aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)AuthorFilesLines
13 dayslibkmod: add weak dependeciesHEADmasterJose Ignacio Tornos Martinez9-4/+326
It has been seen that for some network mac drivers (i.e. lan78xx) the related module for the phy is loaded dynamically depending on the current hardware. In this case, the associated phy is read using mdio bus and then the associated phy module is loaded during runtime (kernel function phy_request_driver_module). However, no software dependency is defined, so the user tools will no be able to get this dependency. For example, if dracut is used and the hardware is present, lan78xx will be included but no phy module will be added, and in the next restart the device will not work from boot because no related phy will be found during initramfs stage. In order to solve this, we could define a normal 'pre' software dependency in lan78xx module with all the possible phy modules (there may be some), but proceeding in that way, all the possible phy modules would be loaded while only one is necessary. The idea is to create a new type of dependency, that we are going to call 'weak' to be used only by the user tools that need to detect this situation. In that way, for example, dracut could check the 'weak' dependency of the modules involved in order to install these dependencies in initramfs too. That is, for the commented lan78xx module, defining the 'weak' dependency with the possible phy modules list, only the necessary phy would be loaded on demand keeping the same behavior, but all the possible phy modules would be available from initramfs. A new function 'kmod_module_get_weakdeps' in libkmod will be added for this to avoid breaking the API and maintain backward compatibility. This general procedure could be useful for other similar cases (not only for dynamic phy loading). Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com> Link: https://lore.kernel.org/r/20240327141116.97587-1-jtornosm@redhat.com
2024-04-30libkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_typesEmil Velikov1-11/+8
It's cleaner to handle all compression types and load functions in the same style. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: move load_reg() further upEmil Velikov1-12/+12
We're about to reference it in comp_types with next commit. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: tidy-up kmod_file_open()Emil Velikov1-36/+27
This commit cleans up the indentation and the error path of the function. It bears no functional changes. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> [ Move assert to avoid warning with -Wdeclaration-after-statement ] Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: swap alloca usage for a few assert_ccEmil Velikov1-14/+8
Since all the compression magic is always available now, we don't need to loop at runtime nor use alloca - latter of which comes with a handful of caveats. Simply throw in a few assert_cc(), which will trigger at build-time. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: always detect the module compressionEmil Velikov1-9/+18
Currently, when built w/o given compression we'll incorrectly report a "compression_none". As we reach do_finit_module(), we'll naively assume that the kernel can handle the compressed module, yet omit the MODULE_INIT_COMPRESSED_FILE flag. As result the kernel will barf at us, do_finit_module will fail with non -ENOSYS and we won't end in the do_init_module codepath (which will also fail). In other words: with this change, you can build kmod without zstd, xz and zlib support and the kernel will load the modules, assuming it supports the format \o/ Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: move kmod_file_load_contents as applicableEmil Velikov1-4/+4
When dealing with an elf, we don't know or care about loading the file. The kmod_elf subsystem/API will deal with the required parts itself. Which in this case, already calls kmod_file_load_contents() as applicable. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: propagate {zstd,xz,zlib}_load errorsEmil Velikov3-6/+15
Propagate any errors during decompression further up the call stack. Without this we could easily pass NULL as mem to init_module(2). Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: nuke struct file_opsEmil Velikov1-44/+18
With the previous commits, we removed the need for a distinct unload callback. So nuke the struct all together and only use/keep the load one around. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: clear file->memory if map failsEmil Velikov1-1/+3
On mmap failure file->memory is set to -1, which we'll happily pass down to munmap later on. More importantly, since we do a NULL check in kmod_file_load_contents() we will exit the function without (re)attempting the load again. Since we ignore the return code for the load function(s), one can end up calling kmod_elf_get_memory() and feed that -1 into init_module. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: remove kmod_file::{zstd,xz}_used flagsEmil Velikov1-12/+0
These are used to protect a free(file->memory), within their respective unload functions. Where the sole caller of the unload function already does a NULL check prior. Even so, free(NULL) is guaranteed to be safe by the standard. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: keep gzFile gzf local to load_zlib()Emil Velikov1-11/+7
There is no need to keep the root gzFile context open for the whole duration. Once we've copied the decompressed module to file->memory we can close the handle. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30libkmod: use a dup()'d fd for zlibEmil Velikov1-7/+12
The gzdopen() API used, takes ownership of the fd. To make that more explicit we clear it (-1) as applicable. Yet again, kmod has explicit API to return the fd to the user - which currently is used solely when uncompressed, so we're safe. Regardless - simply duplicate the fd locally and use that with zlib. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-30build: Ignore directories commonly used for out-of-tree buildLucas De Marchi1-0/+2
build/ and build-*/ are commonly used to have multiple out-out-tree builds. Add them to gitignore. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-04-29testsuite: Fix warnings due to -Wmissing-prototypesLucas De Marchi4-0/+8
/testsuite/module-playground/mod-foo-b.c:13:6: warning: no previous prototype for ‘print_fooB’ [-Wmissing-prototypes] 13 | void print_fooB(void) | ^~~~~~~~~~ /testsuite/module-playground/mod-foo-a.c:13:6: warning: no previous prototype for ‘print_fooA’ [-Wmissing-prototypes] 13 | void print_fooA(void) | ^~~~~~~~~~ /testsuite/module-playground/mod-foo-c.c:13:6: warning: no previous prototype for ‘print_fooC’ [-Wmissing-prototypes] 13 | void print_fooC(void) | ^~~~~~~~~~ /testsuite/module-playground/mod-fake-scsi-mod.c:15:6: warning: no previous prototype for ‘dummy_export’ [-Wmissing-prototypes] 15 | void dummy_export(void) | ^~~~~~~~~~~~ Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-03-12Install kmod.pc in ${datadir}/pkgconfigMike Gilbert2-2/+5
The data in this file isn't related to installed libraries, so put it in an abi-neutral location. pkg.m4 provides macros that also allow the user to override the location with configure switches. Bug: https://bugs.gentoo.org/926431 Signed-off-by: Mike Gilbert <floppym@gentoo.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-03-07build: Allow to install over dirty dirLucas De Marchi1-1/+1
Before commit e98cef6f3f8c ("make: install/uninstall tools symlinks to kmod") it was possible to call `make install DESTDIR=<dir>` multiple times. Use `ln -sf` so the symlink is always re-created. It would be preferred to remove install in an empty dir, but there's not a bad consequence of re-using the same, so let the user decide. Fixes the following errors while installing for the second time: ln: failed to create symbolic link '/tmp/inst/usr/bin/insmod': File exists ln: failed to create symbolic link '/tmp/inst/usr/bin/lsmod': File exists ln: failed to create symbolic link '/tmp/inst/usr/bin/rmmod': File exists ln: failed to create symbolic link '/tmp/inst/usr/bin/depmod': File exists ln: failed to create symbolic link '/tmp/inst/usr/bin/modprobe': File exists ln: failed to create symbolic link '/tmp/inst/usr/bin/modinfo': File exists make[3]: *** [Makefile:2679: install-exec-hook] Error 1 make[2]: *** [Makefile:2553: install-exec-am] Error 2 make[1]: *** [Makefile:2439: install-am] Error 2 make: *** [Makefile:1848: install-recursive] Error 1 Cc: Emil Velikov <emil.l.velikov@gmail.com> Closes: https://github.com/kmod-project/kmod/issues/35 Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://lore.kernel.org/r/20240306145804.135709-1-lucas.de.marchi@gmail.com Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-03-05kmod 32v32Lucas De Marchi3-2/+40
2024-02-20Remove unmaintained experimental toolsEmil Velikov33-400/+0
The kmod insert/remove tools were introduced back in 2015. Since then they have recieved zero attention, unlike the insmod/rmmod variants. Glancing around - neither of the following distributions (Arch, Fedora, Gentoo, Debian) build them, so we're safe to say they have no users. Remove them and alongside it the --enable-experimental toggle, which no longer controls anything. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://lore.kernel.org/r/20240212-rm-experimental-v1-1-b97ab3004ae3@gmail.com Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-02-20man: silence autoconf warningsEmil Velikov11-2/+9
Currently we have a pattern rule, which effective states that two output files are produced - %.5 and %.8. Although that's not the case in practise, since each input xml will be generated to a single manual page. Add the manpage section as part of the xml filename and tweak the pattern (match) rule, accordingly. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://lore.kernel.org/r/20240217-autoconf-manpage-warns-v1-1-e1570cfc286e@gmail.com Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-02-06make: install/uninstall tools symlinks to kmodEmil Velikov1-0/+10
Currently we create symlinks like modprobe (pointing to kmod), during the normal `make` build. Although those were never installed. Add a few lines in the install-exec-hook, to ensure they're present at `make install` time. Thus one can actually use those without additional changes. As an added bonus, distributions can drop the similar hunk from their packaging. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> [ Use a relative symlink ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-02-02configure: tweak the module_directory help stringEmil Velikov1-1/+1
Drop the somewhat misleading ${prefix}/lib/modules and explicitly mention what's the default. Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2024-02-02gitignore: Ignore *.pc filesLucas De Marchi1-0/+1
tools/kmod.pc is generated by build system. Any new *.pc we may have should follow a similar approach. So, just ignore from git, like we do for e.g. *.o. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-02-02testsuite: drop mkosiLucas De Marchi7-126/+0
It's not being actively used, so drop it. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-02-02ci: drop travis configLucas De Marchi1-32/+0
We are not using travis anymore for CI. Drop its configuration. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-02-02Drop python bindingsLucas De Marchi20-743/+4
Python bindings are not well maintained. Currently it's just broken when trying to build with cython 3.0.8: make --no-print-directory all-recursive Making all in . CYTHON libkmod/python/kmod/kmod.c Error compiling Cython file: ------------------------------------------------------------ ... # details. # # You should have received a copy of the GNU Lesser General Public License # along with python-kmod. If not, see <http://www.gnu.org/licenses/>. cimport _libkmod_h ^ Nothing really touched those bindings for 10 years already. I postponed the removal since they were at least building, but that just changed. So let's drop it and allow any interested people to give it a better life outside of libkmod. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-12-06configure: Check that provided paths are absoluteMichal Suchanek1-0/+17
configure checks that its built-in directory options get an absolute path. Copy the check for custom options. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Link: https://lore.kernel.org/r/8aff0c9c491d8afeec7f6b2cd96cbd0439e26fbb.1699618135.git.msuchanek@suse.de Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-12-06libkmod, depmod, modprobe: Make directory for kernel modules configurableMichal Suchanek18-84/+107
Now that modprobe.d is searched under ${prefix}/lib, allow a complete transition to files only under ${prefix} by adding a ${module_directory} configuration. This specifies the directory where to search for kernel modules and should match the location where the kernel/distro installs them. With this distributions that do not want to ship files in /lib can also move kernel modules to /usr while others can keep them in /lib. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Link: https://lore.kernel.org/r/a3765f4e8ae3ce29c0847a0132d4a8d51ad040a9.1699618135.git.msuchanek@suse.de Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-11-07libkmod: remove pkcs7 obj_to_hash_algo()Dimitri John Ledkov2-46/+20
Switch to using OBJ_obj2txt() to calculate and print the pkcs7 signature hash name. This eliminates the need to duplicate libcrypto NID to name mapping, detect SM3 openssl compile-time support, and enables using any hashes that openssl and kernel know about. For example SHA3 are being added for v6.7 and with this patch are automatically supported. Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com> Link: https://lore.kernel.org/r/20231029010319.157390-1-dimitri.ledkov@canonical.com
2023-11-05tools: depmod: fix -Walloc-sizeSam James1-4/+4
GCC 14 introduces a new -Walloc-size included in -Wextra which gives: ``` tools/depmod.c:192:14: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size] tools/depmod.c:255:11: warning: allocation of insufficient size ‘1’ for type ‘struct index_value’ with size ‘16’ [-Walloc-size] tools/depmod.c:286:35: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size] tools/depmod.c:315:44: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size] ``` The calloc prototype is: ``` void *calloc(size_t nmemb, size_t size); ``` So, just swap the number of members and size arguments to match the prototype, as we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not doing anything wrong. Signed-off-by: Sam James <sam@gentoo.org>
2023-10-17kmod: Add pkgconfig file with kmod compile time configurationMichal Suchanek3-1/+21
Show distconfdir (where system configuration files are searched/to be installed), sysconfdir (where user configuration files are searched), module compressions, and module signatures supported. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Link: https://lore.kernel.org/r/468b3f572d3b84f25bb53ec8fcb15ed4871914d4.1689681454.git.msuchanek@suse.de Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-10-17libkmod, depmod: Load modprobe.d, depmod.d from ${prefix}/lib.Michal Suchanek7-5/+20
There is an ongoing effort to limit use of files outside of /usr (or ${prefix} on general). Currently all modprobe.d paths are hardcoded to outside of $prefix. Teach kmod to load modprobe.d from ${prefix}/lib. On some distributions /usr/lib and /lib are the same directory because of a compatibility symlink, and it is possible to craft configuration files with sideeffects that would behave differently when loaded twice. However, the override semantic ensures that one 'overrides' the other, and only one configuration file of the same name is loaded from any of the search directories. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Link: https://lore.kernel.org/r/a290343ce32e2a3c25b134e4f27c13b26e06c9e0.1689681454.git.msuchanek@suse.de Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-10-17man/depmod.d: Fix incorrect /usr/lib search pathMichal Suchanek1-1/+1
depmod searches /lib/depmod.d but the man page says /usr/lib/depmod.d is searched. Align the documentation with the code. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Link: https://lore.kernel.org/r/9c5a6356b1a111eb6e17ddb110494b7f1d1b44c0.1689681454.git.msuchanek@suse.de Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-10-17configure: Detect openssl sm3 supportMichal Suchanek1-0/+7
Older openssl versions do not support sm3. The code has an option to disable the sm3 hash but the lack of openssl support is not detected automatically. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Link: https://lore.kernel.org/r/b97e20faa07e9e31c6eaf96683011aa24e80760c.1689681454.git.msuchanek@suse.de Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-09-29kmod 31v31Lucas De Marchi3-2/+66
2023-09-27libkmod: add fallback MODULE_INIT_COMPRESSED_FILE defineEmil Velikov1-0/+4
The symbol was somewhat recently introduced by the kernel and not all distributions may be have available. The number is part of the ABI, so we can add a local fallback define. Closes: https://github.com/kmod-project/kmod/issues/29 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-06-20libkmod: Use kernel decompression when availableLucas De Marchi4-6/+21
With the recent changes to bypass loading the file it's possible to reduce the work in userspace and delegating it to the kernel. Without any compression to illustrate: Before: read(3, "\177ELF\2\1", 6) = 6 lseek(3, 0, SEEK_SET) = 0 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=238592, ...}, AT_EMPTY_PATH) = 0 mmap(NULL, 238592, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd85cbd1000 finit_module(3, "", 0) = 0 munmap(0x7fd85cbd1000, 238592) = 0 close(3) = 0 After: read(3, "\177ELF\2\1", 6) = 6 lseek(3, 0, SEEK_SET) = 0 finit_module(3, "", 0) = 0 close(3) = 0 When using kernel compression now it's also possible to direct libkmod to take the finit_module() path, avoiding the decompression in userspace and just delegating it to the kernel. Before: read(3, "(\265/\375\244\0", 6) = 6 lseek(3, 0, SEEK_SET) = 0 read(3, "(\265/\375\244", 5) = 5 mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3fa431e000 read(3, "\0\244\3\0\\y\6", 7) = 7 mmap(NULL, 372736, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3fa414f000 brk(0x55944c6a1000) = 0x55944c6a1000 read(3, "\356|\6G\27U\20 \312\260s\211\335\333\263\326\330\336\273O\211\356\306K\360Z\341\374U6\342\221"..., 53038) = 53038 mremap(0x7f3fa431e000, 135168, 266240, MREMAP_MAYMOVE) = 0x7f3fa410e000 read(3, ",;\3\nqf\311\362\325\211\7\341\375A\355\221\371L\\\5\7\375 \32\246<(\258=K\304"..., 20851) = 20851 mremap(0x7f3fa410e000, 266240, 397312, MREMAP_MAYMOVE) = 0x7f3fa40ad000 read(3, ")\36\250\213", 4) = 4 read(3, "", 4) = 0 munmap(0x7f3fa414f000, 372736) = 0 init_module(0x7f3fa40ad010, 238592, "") = 0 munmap(0x7f3fa40ad000, 397312) = 0 close(3) = 0 After: read(3, "(\265/\375\244P", 6) = 6 lseek(3, 0, SEEK_SET) = 0 finit_module(3, "", 0x4 /* MODULE_INIT_??? */) = 0 close(3) = 0 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-06-09libkmod: Keep track of in-kernel compression supportLucas De Marchi1-0/+37
When creating the context, read /sys/kernel/compression to check what's the compression type supported by the kernel. This will later be used when loading modules to check if the decompression step has to happen in userspace or if it can be delegated to the kernel. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-06-09libkmod: Keep track of compression typeLucas De Marchi2-12/+22
Do not only set the type as direct, but also keep track of the compression being used. This will allow using the in-kernel compression in future. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-06-09libkmod: Extract finit_module vs init_module pathsLucas De Marchi1-47/+73
Extract 2 functions to handle finit_module vs init_modules differences, with a fallback from the former to the latter. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-06-09libkmod: Do not inititialize file->memory on openLucas De Marchi4-4/+27
Add a separate function to load the file contents when it's needed. When it's not needed on the path of loading modules via finit_module(), there is no need to mmap the file. This will help support loading modules with the in-kernel compression support. This is done differently than the lazy initialization for kmod_file_get_elf() because on the contents case there is also the file->size to be updated. It would be a weird API to return the pointer and have the size changed as a side-effect. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-05-30shared: avoid passing {NULL, 0} array to bsearch()Dmitry Antipov1-5/+8
Fix the following warning reported by UBSan (as of gcc-13.1.1): shared/hash.c:244:35: runtime error: null pointer passed as argument 2, which is declared to never be null Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> [ reshuffle the code to use return-early style ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-05-30libkmod: fix possible out-of-bounds memory accessDmitry Antipov1-0/+4
An attempt to pass too long module name to, say, rmmod, may cause an out-of-bounds memory access (as repoted by UBSan): $ rmmod $(for i in $(seq 0 4200); do echo -ne x; done) libkmod/libkmod-module.c:1828:8: runtime error: index 4107 out of bounds for type 'char [4096]' This is because 'snprintf(path, sizeof(path), ...)' may return the value which exceeds 'sizeof(path)' (which happens when an output gets truncated). To play it safe, such a suspicious output is better to be rejected explicitly. Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Link: https://lore.kernel.org/r/20230519074638.402045-1-dmantipov@yandex.ru
2023-05-30libkmod, depmod: prefer -ENODATA over -ENOENT if no section foundDmitry Antipov2-4/+4
When the module is definitely present but CONFIG_MODVERSIONS is disabled, the following error message may be somewhat confusing: modprobe --dump-modversions /path/to/module.ko.xz modprobe: FATAL: could not get modversions of /path/to/module.ko.xz: No such file or directory Choosing among the convenient errno values, I would suggest to use ENODATA when the module lacks a particular ELF section (and vermagic as well). So now it is expected to be: modprobe: FATAL: could not get modversions of /path/to/module.ko.xz: No data available Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Link: https://lore.kernel.org/r/20230519093630.474185-1-dmantipov@yandex.ru
2023-04-18modprobe: rmmod_do_module: Free kmod list of holdersNicolas Schier1-0/+1
Add a missing kmod_module_unref_list() to fix a memory leak. Fixes: 42b32d30c38e ("modprobe: Fix holders removal") Signed-off-by: Nicolas Schier <n.schier@avm.de> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-03-06configure.ac: fix link with -llzmaFabrice Fontaine1-4/+4
Add liblzma_LIBS to LIBS to avoid the following build failure when building with a static-only liblzma.a: /home/autobuild/autobuild/instance-5/output-1/host/lib/gcc/xtensa-buildroot-linux-uclibc/11.3.0/../../../../xtensa-buildroot-linux-uclibc/bin/ld: libkmod/.libs/libkmod-internal.a(libkmod-file.o):(.text.xz_uncompress+0x10): undefined reference to `lzma_code' For consistency, also update libzstd, zlib and libcrypto Fixes: - http://autobuild.buildroot.org/results/83a4a7ecc77f39639d3e5bc8554bd01a62a3ede0 References: https://github.com/kmod-project/kmod/pull/25 Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-21configure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILESEmil Velikov2-25/+2
Replace the manual sed command, build rules and dist/clean for using AC_CONFIG_FILES. It does the exact same thing, with an added bonus... Currently we're missing version.py.in in the EXTRA_DIST. Thus a simple "touch Makefile" should retrigger the regeneration of version.py. Which would presumably fail, since the input file isn't in the distribution tarball. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-21shared: annotate local API as staticEmil Velikov2-6/+3
None of the API is used outside of the compilation unit. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-21libkmod: annotate kmod_builtin_iter API as staticEmil Velikov2-9/+4
It's no longer used outside the compilation unit, as of last commit. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-21libkmod: remove unused kmod_module_get_builtinEmil Velikov2-44/+0
The last and only user was removed with commit 0246e06 ("depmod: Stop opening modules.modinfo once per module") Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-10testsuite: Handle different sysconfdirLucas De Marchi6-32/+9
Instead of skipping tests if sysconfdir isn't /etc, just handle it during the rootfs setup logic. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2023-02-10testsuite: Move setup-rootfs logic from Makefile to scriptLucas De Marchi2-10/+19
It's easier to implement the logic outside of the Makefile, so rename the populate-modules.sh script to setup-rootfs.sh and move the additional logic from the makefile to the script. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2023-02-09libkmod: error out on unknown hash algorithmEmil Velikov1-1/+5
Currently if we see unknown algorithm, we'll do an OOB read in pkey_hash_algo. This can happen for example if OPENSSL_NO_SM3 is set and the kernel module uses a SM3 hash. Cc: Mikhail Novosyolov <m.novosyolov@rosalinux.ru> Cc: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-09testsuite/depmod: use defines for the rootfs/lib_modulesEmil Velikov1-23/+27
The uname used across the tests is same, so drop "_ORDER" from the macro name and use it throughout. Similarly - add respective LIB_MODULES defines and use them in the tests. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-09testsuite: add function declarations for __xstat familyEmil Velikov1-1/+8
As the inline comment says - the declarations have been dropped with glibc 2.32.9000, as a result the build throws a set of lovely warnings. Inspired by umockdev, which bears the same license as this project. https://github.com/martinpitt/umockdev/commit/f1b416400479d861deffb4c5a40422dcdf190e85 Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-09treewide: add some static const notationsEmil Velikov6-12/+12
Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-09depmod: Introduce outdir optionEmil Velikov8-3/+128
This option is equivalent to basedir, with the small difference being that's where the meta-data files are generated. In other words, this allows us to have read-only input modules and modules.dep, while still being able to generate the meta-data files. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> [ Move files to a different dir so input files (produced by kernel build system is separate from the files generated by depmod (output) ] Signed-off-by: Lucas De Marchi <lucas.demarchi@gmail.com>
2023-02-08man/rmmod: explain why modprobe -r is more usefulYauheni Kaliuta1-1/+2
Improve user experience by explaining the option so the user may not search explanations in other manpages (modprobe). Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-01-13modprobe: Allow passing path to moduleGustavo Sousa24-10/+91
This is useful to kernel module developers for testing a just compiled module: instead of using insmod, they can load the module from the path while getting all the benefits of modprobe (e.g. module dependency resolution). v2: - Add test for relative path as well. (Lucas) - Add note warning about modules with dependencies not matching the installed depmod database. (Lucas) Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com> Cc: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-01-13modprobe: Move insertion block into separate functionGustavo Sousa1-35/+42
That same logic will be used for enabling modprobe for paths in the next patch. As such, prepare for that by extracting that block into its own function. Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-01-13testsuite: Wrap chdir()Gustavo Sousa1-0/+1
One of the tests in an upcoming patch will need to change into a specific directory to test loading a module from a relative path. Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-12-26kmod: configure.ac: In _Noreturn check, include <stdlib.h> for exitFlorian Weimer1-1/+2
Otherwise, an implicit functiona declaration is used, causing a C99 compatibility issue. Signed-off-by: Florian Weimer <fweimer@redhat.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-11-30autogen.sh: remove --with-rootprefix, it is gone since kmod-11Adam Gołębiowski1-1/+0
Signed-off-by: Adam Gołębiowski <adamg@pld-linux.org>
2022-10-03libkmod: do not crash on unknown signature algorithmMikhail Novosyolov1-0/+3
Example kernel module: https://file-store.rosalinux.ru/download/7281f97e0c04c0f818ad3f936706f4a407e8dc7e (/lib/modules/5.15.67-generic-1rosa2021.1-x86_64/kernel/drivers/usb/host/xhci-pci.ko.zst) It is signed with Streebog 512. libkmod v30 crashed in libkmod-module.c:2413 in this code: n = kmod_module_info_append(list, "sig_hashalgo", strlen("sig_hashalgo"), sig_info.hash_algo, strlen(sig_info.hash_algo)); because strlen() got null.
2022-09-05testsuite: fix override of `stat` on 32-bit architecturesJulien Cristau1-4/+5
When _FILE_OFFSET_BITS is 64, glibc headers turn `stat` calls into `stat64`, and our `stat` override into a `stat64` function. However, because we use dlsym to get the address of libc's `stat`, we end up calling into the "real" `stat` function, which deals with 32-bit off_t, and we treat its result as if it were returned from stat64. On most architectures this seems to have been harmless, but on 32-bit mips, st_mode's offset in struct stat and struct stat64 are different, so we read garbage. To fix this, explicitly unset _FILE_OFFSET_BITS in path.c, to turn off the redirect magic in glibc headers, and override both the 32-bit and 64-bit functions so each call ends up wrapping the right libc function. Fixes #16 (https://github.com/kmod-project/kmod/issues/16)
2022-06-30modprobe: Write error messages to syslog if stderr is unavailableQuentin Armitage1-0/+7
The man page modprobe(8) states for the --syslog option: "This is also automatically enabled when stderr is unavailable." but it wasn't happening. This commit now makes modprobe write to syslog if stderr is closed.
2022-06-30build: enable building & running tests from a subdirDimitri John Ledkov1-0/+1
During dpkg build, in a subdir, it is currently not possible to run tests. Building testsuite/modules due to non-existance of the testsuite directory under the build dir. Thus create it, when it is not there. Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
2022-06-30testsuite: repair read of uninitialized memoryJan Engelhardt1-1/+1
Function ``test_backoff_time`` does not initialize ``delta``, and ``get_backoff_delta_msec`` then performs a read from uninitialized memory with the ``!*delta`` expression. Signed-off-by: Jan Engelhardt <jengelh@inai.de> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-30kmod 30v30Lucas De Marchi3-5/+85
2022-06-30libkmod: Support SM3 hash algorithmHuaxinLu1-0/+6
SM3 has been supported in kernel and cryptographic libraries like openssl. This patch adds support for the SM3 algorithm of kmod. Signed-off-by: HuaxinLu <luhuaxin1@huawei.com>
2022-06-29README: Update optional dependenciesLucas De Marchi1-0/+2
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-28Keep only one readmeLucas De Marchi1-126/+0
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26modprobe: Add --waitLucas De Marchi2-9/+78
Retry module removal if it fails due to EAGAIN. This allows user to pass --wait <timeout>, during which `modprobe -r` will keep trying to remove the module. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26testsuite: Add tests for sleep calculationLucas De Marchi1-0/+41
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26util: Add exponential backoff sleepLucas De Marchi2-0/+51
Add simple functions to put the current thread to sleep using exponential backoff to split the interval in smaller pieces. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26util: Add msec variants for time-related functionsLucas De Marchi2-0/+20
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26util: Add time-related functions from testsuiteLucas De Marchi3-13/+19
This will be useful in future not only to testsuite, but also to tools and library. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26module-playground: Add debugfs entry in mod-simpleLucas De Marchi1-1/+17
Add a debugfs file in mod-simple for manual tests: insert the module and open the file to have its refcount increased. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26libkmod: Allow to ignore log message on module removalLucas De Marchi2-4/+11
Caller may want to handle retries, in which case the log message is not appropriate. Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26modprobe: Move -R to "Query options"Lucas De Marchi1-4/+4
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26modprobe: re-use modname variableLucas De Marchi1-1/+1
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26depmod: Fix writing over array lengthLucas De Marchi1-0/+1
Make sure return value in flush_stream_to() is the length written if the value didn't the size. Fix warning on gcc 12.1: tools/depmod.c: In function ‘output_builtin_alias_bin’: tools/depmod.c:2465:24: warning: array subscript 4096 is above array bounds of ‘char[4096]’ [-Warray-bounds] 2465 | modname[len] = '\0'; | ~~~~~~~^~~~~ tools/depmod.c:2460:22: note: while referencing ‘modname’ 2460 | char modname[PATH_MAX]; | ^~~~~~~ tools/depmod.c:2477:22: warning: array subscript 4096 is above array bounds of ‘char[4096]’ [-Warray-bounds] 2477 | value[len] = '\0'; | ~~~~~^~~~~ tools/depmod.c:2461:22: note: while referencing ‘value’ 2461 | char value[PATH_MAX]; | ^~~~~ Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-04-06modprobe: Make rmmod_do_module() contain all the removal sequenceLucas De Marchi1-15/+22
Move the remaining part of the removal sequence dangling in rmmod_do_remove_module() to rmmod_do_module() so we can consider this function is the one controlling all the module removals. While at it, add some comments about the removal order and normalize coding style in this function. Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-04-06modprobe: move check for remove_holders to callerLucas De Marchi1-2/+4
Do not mix the flags with and additional boolean from arguments. Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-04-06modprobe: Fix holders removalLucas De Marchi1-8/+10
The idea behind --remove-dependencies was to remove other modules that depend on the current module being removed. It's the reverse dependency list, not the dependency list of the current module: that never works since the current module would still hold a ref on it. Fix it by replacing the call to kmod_module_get_dependencies() with kmod_module_get_holders() when using that option. Also try to cleanup the confusion by renaming the option to --remove-holders: "holder" is the name used in sysfs and by libkmod to refer to a "live" reverse dependency like what we are interested in. Before: ./tools/modprobe -D -r --remove-dependencies video rmmod video After: ./tools/modprobe -D -r --remove-holders video rmmod i915 rmmod thinkpad_acpi rmmod video Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-04-04modprobe: remove unneeded variable str_startMasahiro Yamada1-3/+3
The variable 'str_start' is not useful here. Replace it with 'str'. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2022-04-04modprobe: fix the NULL-termination of new_argvMasahiro Yamada1-1/+1
The number of new arguments is (i + argc - 1) as it is set to *p_argc one line below. The correct location of NULL termination is new_argv[i + argc - 1]. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2022-04-01depmod: Add support for excluding a directorySaul Wold2-4/+76
This adds support to depmod to enable a new exclude directive in the depmod.d/*.conf configuration file. Currently depmod already excludes directories named source or build. This change will allow additional directories like .debug to be excluded also via a new exclude directive. depmod.d/exclude.conf example: exclude .debug Signed-off-by: Saul Wold <saul.wold@windriver.com> [ Fix warnings and make should_exclude_dir() return bool ] Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2022-04-01modprobe: Rename rmmod_do_deps_listLucas De Marchi1-4/+5
It's used not only for dependencies, but also for pre and post softdep. Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-03-03docs: Add missing functions to documentationLucas De Marchi1-0/+2
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2022-02-23libkmod: Fix use of sizeof instead of ARRAY_SIZELucas De Marchi1-2/+2
Link: https://github.com/kmod-project/kmod/issues/12 Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2022-02-20modinfo: Allow to force arg as module nameLucas De Marchi1-2/+28
If the Linux kernel or userspace sets an alias with the same name as a module, they force the tools to use that. However in some situations it may be desired to query the module itself. Getting the module information through modinfo is one such situation. So, add a option to modinfo to explicitly instruct it to handle the argument as a module name. Example, when trying to output information about the crc32 module that is builtin: $ modinfo crc32 filename: /lib/modules/5.15.19-1-MANJARO/kernel/arch/x86/crypto/crc32-pclmul.ko.zst alias: crypto-crc32-pclmul alias: crc32-pclmul alias: crypto-crc32 alias: crc32 license: GPL author: Alexander Boyko <alexander_boyko@xyratex.com> srcversion: B6B2FF9236731E69418A2E5 alias: cpu:type:x86,ven*fam*mod*:feature:*0081* depends: retpoline: Y intree: Y name: crc32_pclmul vermagic: 5.15.19-1-MANJARO SMP preempt mod_unload sig_id: PKCS#7 signer: Build time autogenerated kernel key sig_key: 77:FB:AA:BD:48:78:A4:C6:56:18:9A:7E:A6:F3:29:3E:C5:6B:E9:37 sig_hashalgo: sha512 signature: 30:65:02:31:00:B0:D4:49:9D:1D:F1:71:4C:3C:BB:70:B2:3E:46:5D: 38:5A:F1:00:95:FD:7A:96:C4:2C:24:35:A2:1B:0B:A8:1C:29:6F:02: 7A:68:EE:BA:A4:1C:01:4B:86:39:15:3E:66:02:30:7F:7A:66:5E:F2: 2F:98:73:3D:AD:96:66:81:8B:94:6E:F3:3F:44:0F:85:E1:73:3A:9E: F9:C4:BE:9B:88:02:BD:83:04:B9:2E:72:0B:93:BC:82:B6:A1:1B:6A: C2:ED:8C filename: /lib/modules/5.15.19-1-MANJARO/kernel/crypto/crc32_generic.ko.zst alias: crypto-crc32-generic alias: crc32-generic alias: crypto-crc32 alias: crc32 license: GPL description: CRC32 calculations wrapper for lib/crc32 author: Alexander Boyko <alexander_boyko@xyratex.com> srcversion: F08036C38DDB06BCD1E6091 depends: retpoline: Y intree: Y name: crc32_generic vermagic: 5.15.19-1-MANJARO SMP preempt mod_unload sig_id: PKCS#7 signer: Build time autogenerated kernel key sig_key: 77:FB:AA:BD:48:78:A4:C6:56:18:9A:7E:A6:F3:29:3E:C5:6B:E9:37 sig_hashalgo: sha512 signature: 30:65:02:31:00:E3:9E:C8:80:15:0E:D7:74:96:B5:25:EA:32:F7:DF: E9:FC:3C:82:D9:B9:B9:37:C5:20:8D:06:31:02:62:B3:54:E8:DF:F2: 7E:E2:7C:A4:CF:49:17:CB:75:DF:2C:7A:2F:02:30:25:DE:7C:2A:2C: 97:3F:65:16:76:B3:71:FB:62:DB:8F:F3:33:65:77:98:F3:57:ED:D7: 87:78:FF:C2:04:55:70:00:10:63:1E:B2:FE:22:D8:E5:6D:5F:95:4E: 7D:2C:6B That is because the Linux kernel exports "crc32" as an alias to those modules, besides being a module itself: $ grep crc32 /lib/modules/$(uname -r)/modules.builtin kernel/lib/crc32.ko $ $ grep "alias crc32 " /lib/modules/$(uname -r)/modules.alias alias crc32 crc32_pclmul alias crc32 crc32_generic With the new -m|--modname option it's possible to query the information about this (builtin) module explicitly: $ modinfo --modname crc32 name: crc32 filename: (builtin) license: GPL file: lib/crc32 description: Various CRC32 calculations author: Matt Domsch <Matt_Domsch@dell.com> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20modinfo: Update help message with "modulename"Lucas De Marchi1-1/+1
man page correctly states the a module name can be used in place of a file name: modinfo [-0] [-F field] [-k kernel] [modulename|filename...] Update the help message accordingly. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20libkmod: Add lookup from module nameLucas De Marchi3-0/+61
Slightly different than kmod_module_new_from_lookup(): it doesn't consider aliases, only module names. This is useful for cases we want to force a tool to handle something as the module name, without trying to interpret it as an alias. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20libkmod: Update docs about indexes orderLucas De Marchi1-1/+1
New indexes were created without updating the documentation about the order in kmod_module_new_from_lookup(). Add them to the documentation. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20libkmod: Add helper function to iterate lookup optionsLucas De Marchi1-45/+37
The CHECK_ERR_AND_FINISH macro with conditional code flow changes has been a source of bugs. Get rid of it replacing with a helper function to iterate an array of lookup functions. This helper may also be useful in future to create different lookup APIs in libkmod. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20gitignore: ignore gtk-doc.makeLucas De Marchi1-0/+1
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20libkmod-module: Fix return code for kmod_module_new_from_lookup()Lucas De Marchi1-2/+2
When kmod_module_new_from_lookup() resolves to an alias, `err` will be set to a positive value from the lookup function. Do not return a positive value to follow the behavior when it matches a module name and the documentation. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20test-initstate: Check for negative value on errorLucas De Marchi1-1/+1
Documentation says kmod_module_new_from_lookup() returns < 0 on error and 0 otherwise. There are bugs in libkmod however making it return a positive value in some situations, that need to be fixed. However it's best to check for the error explicitly like is done in the rest of the library to avoid this kind of issues. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-11depmod: Stop opening modules.modinfo once per moduleLucas De Marchi1-62/+96
Since the addition of modules.aliases.bin, depmod has to open that index multiple times and parse it over and over again: $ sudo strace -e openat ./tools/depmod 2>&1 | grep modules.builtin.modinfo | wc -l 299 $ time sudo ./tools/depmod real 0m7.814s user 0m7.571s sys 0m0.237s Rework the logic in depmod so it does everything: open, read and parse. The format is very straightforward and we don't need to keep it in a data structure since we only want to add the result to a index. New output: $ sudo strace -e openat ./tools/depmod 2>&1 | grep modules.builtin.modinfo | wc -l 1 $ time sudo ./tools/depmod real 0m7.663s user 0m7.516s sys 0m0.139s Indexes still match: $ cmp /tmp/modules.builtin.alias.bin.new /tmp/modules.builtin.alias.bin.old; echo $? 0 Fix: https://github.com/kmod-project/kmod/issues/11
2022-02-11depmod: Do not duplicate builtin indexLucas De Marchi1-4/+1
Now that libkmod uses modules.builtin.bin again, we don't need to add the module names in modules.builtin.alias.bin and just add the aliases. After this change, here are the new sizes for the indexes: Before After index 21k 6.4K modules.builtin.alias.bin 11k 11K modules.builtin.bin
2022-02-11libkmod: Prefer builtin index over builtin.aliasLucas De Marchi1-5/+7
The modules.builtin.alias.bin is way larger than the modules.builtin.bin. On a normal "distro kernel": 21k modules.builtin.alias.bin 11k modules.builtin.bin From the kernel we get both modules.builtin and modules.builtin.modinfo. depmod generates modules.builtin.bin and modules.builtin.alias.bin from them respectively. modules.bultin is not going away: it's not deprecated by the new index added. So, let's just stop duplicating the information inside modules.builtin.alias.bin and just use the other index.
2022-01-20libkmod: Set builtin to no when module is created from path.Michal Suchanek1-8/+9
A recent bug report showed that modinfo doesn't give the signature information for certain modules, and it turned out to happen only on the modules that are built-in on the running kernel; then modinfo skips the signature check, as if the target module file never exists. The behavior is, however, inconsistent when modinfo is performed for external modules (no matter which kernel version is) and the module file path is explicitly given by a command-line argument, which guarantees the presence of the module file itself. Fixes: e7e2cb61fa9f ("modinfo: Show information about built-in modules") Link: https://lore.kernel.org/linux-modules/CAKi4VAJVvY3=JdSZm-GD1hJqyCPYaYz-jBJ_REeY5BakVb6_ww@mail.gmail.com/ BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1189537 Suggested-by: Lucas De Marchi <lucas.de.marchi@gmail.com> Signed-off-by: Michal Suchanek <msuchanek@suse.de> Reviewed-by: Petr Vorel <pvorel@suse.cz>
2021-09-23libkmod: add a library notice log level printLuis Chamberlain1-0/+2
When you use pass the -v argument to modprobe we bump the log level from the default modprobe log level of LOG_WARNING (4) to LOG_NOTICE (5), however the library only has avaiable to print: #define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg) #define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg) #define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg) LOG_INFO (6) however is too high of a level for it to be effective at printing anything when modprobe -v is passed. And so the only way in which modprobe -v can trigger the library to print a verbose message is to use ERR() but that always prints something and we don't want that in some situations. We need to add a new log level macro which uses LOG_NOTICE (5) for a "normal but significant condition" which users and developers can use to look underneath the hood to confirm if a situation is happening. Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2021-06-09libkmod-module: check "new_from_name" return value in get_builtinYauheni Kaliuta1-1/+4
kmod_module_new_from_name() may fail and return error value. It is handled properly across the code, but in this particular place the check is missing. Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2021-05-20kmod 29v29Lucas De Marchi3-2/+48
2021-05-11testsuite: update gitignoreLucas De Marchi1-1/+1
2021-05-11depmod: fix modules.builtin.alias.bin outputLucas De Marchi1-1/+1
Due to wrong documentation on kmod_module_get_info() we ended up checking for 0 as return. Check for > 0 to decided if we want to write the index to the file, otherwise we would output a 0-sized index on success.
2021-05-11Fix return value doc for kmod_module_get_info()Lucas De Marchi1-1/+1
We don't return 0 on success, we return the number of elements we added to the list.
2021-04-17libkmod: fix possible double free with wrong modules.builtin.modinfoSeung-Woo Kim1-1/+1
Fix double free for *modinfo with non '\0' terminated wrong modules.builtin.modinfo, which is because EOF is minus value. Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
2021-04-17libkmod: fix an overflow with wrong modules.builtin.modinfoSeung-Woo Kim1-1/+1
Fix a possbile overflow with exact PATH_MAX length modname in wrong modules.builtin.modinfo. Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
2021-04-17gitignore: ignore .mbx and .cover for b4 integrationLucas De Marchi1-0/+2
Lately I'm using b4 to work with the patches in the mailing list. Better to start ignoring .cover and .mbx files since they get created by b4.
2021-04-09libkmod-config: fix a memory leak when kmod_list_append() failsSeung-Woo Kim1-1/+3
From kmod_config_new(), when kmod_list_append() fails, fix not list-appended kmod_config_path leak. Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
2021-03-10libkmod-config: more chars allowed as spaceLucas De Marchi1-2/+5
Recently in a discussion I noticed that kernel allows more chars to be considered as space in the kernel command line. Switch to the equivalent of isspace() instead of considering only ' '.
2021-02-15test-modprobe: share single function for kcmdline testsLucas De Marchi1-85/+10
2021-02-15testsuite: allow to re-use single function for testsLucas De Marchi1-2/+4
Add a new DEFINE_TEST_WITH_FUNC() that accepts the function alongside the test name. This will allow us to share a single function for different tests.
2021-02-15libkmod-config: re-quote option from kernel cmdlineLucas De Marchi10-1/+109
It was reported that grub mangles the kernel cmdline. It turns acpi_cpufreq.dyndbg="file drivers/cpufreq/acpi-cpufreq.c +mpf" into "acpi_cpufreq.dyndbg=file drivers/cpufreq/acpi-cpufreq.c +mpf" However, even though we could blame grub for doing that, the kernel happily accepts and re-quotes it when the module is built-in. So, it's better if kmod also understands it this way and does the same. Here we basically add additional code to un-mangle it, moving the quote in way that is acceptable to pass through init_module(). Note that the interface [f]init_module() gives us mandates the quote to be part of the value: the module name is not passed and the options are separated by space. Reported-by: Jiri Slaby <jirislaby@kernel.org> Tested-by: Jessica Yu <jeyu@kernel.org> Link: https://bugzilla.suse.com/show_bug.cgi?id=1181111#c10
2021-02-15libkmod-config: revamp kcmdline parsing into a state machineLucas De Marchi1-34/+52
The handling of spaces and quotes is becoming hard to maintain. Convert the parser into a state machine so we can check all the states. This should make it easier to fix a corner case we have right now: The kernel also accepts a quote before the module name instead of the value. But this additional is left for later. This is purely an algorithm change with no behavior change. Tested-by: Jessica Yu <jeyu@kernel.org>
2021-02-05testsuite: also test xz compressionLucas De Marchi1-0/+9
Reviewed-by: Petr Vorel <pvorel@suse.cz>
2021-02-05testsuite: compress modules if feature is enabledLucas De Marchi3-12/+19
Since the output needs to be the same, regardless if the module is compressed, change populate-modules.sh to conditionally compress the module if that feature is enabled. This way we can execute the tests with any build-time configuration and it should still pass. Suggested-by: Michal Suchánek <msuchanek@suse.de> Reviewed-by: Michal Suchánek <msuchanek@suse.de> Tested-by: Michal Suchánek <msuchanek@suse.de> Reviewed-by: Petr Vorel <pvorel@suse.cz>
2021-01-23populate-modules: Use more bash, more quotesDave Reisner1-9/+9
We're already using associatives arrays, so there's no reason we should be using 'test'.
2021-01-20README: make github mirror officialLucas De Marchi2-4/+126
For some time I've been maintaining a read-only mirror on github. I think it's time to allow patches flowing from there besides the mailing list: I created a new org to host the project: https://github.com/kmod-project/kmod
2021-01-18Support /usr/local for configuration filesLucas De Marchi4-4/+9
Add /usr/local to the search path for configuration files. These are intended for local installs, provided /usr/local is given as prefix.
2021-01-18depmod: fix precedence orderLucas De Marchi1-1/+1
Configuration in /etc should have higher prio than /run. Given how rarely configuration in /run is used with depmod, this is likely not to cause any problems, even if it's a change in behavior.
2021-01-18libkmod: Fix documentation on config precedence orderLucas De Marchi3-3/+3
/etc is has higher priority than /run.
2021-01-07Fix "modinfo -F always shows name for built-ins"Marco d'Itri1-1/+5
Bug reported by Ben Hutchings <ben@decadent.org.uk>: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=970871 Now that the kernel provides module information for potentially modular code that's actually built-in, it's possible to query these built-ins with "modinfo -F". However, this doesn't work quite right: $ modinfo -Flicense e1000e GPL v2 $ modinfo -Flicense bitrev name: bitrev GPL
2021-01-07README: remove leftover from semaphoreciLucas De Marchi1-3/+0
We are not currently using semaphoreci, so remove leftover status from README.
2021-01-07testsuite: Automatically skip tests that fail when sysconfdir != /etc.Marius Bakke5-7/+28
2021-01-07testsuite: Add facility to skip tests.Marius Bakke2-0/+11
The Makefile helpfully warns that some tests will fail when --sysconfdir != /etc, but there are no provisions to easily disable those. This commit provides an escape hatch. [ Lucas: add comment detailing the purpose of the field ]
2021-01-07kmod 28v28Lucas De Marchi3-2/+15
2021-01-07build: add comment with rules for libtool version updateLucas De Marchi1-0/+13
2020-12-27build: fix distcheck due to missing zstdLucas De Marchi1-1/+1
Enable zstd since it's used in the testsuite.
2020-12-27testsuite: add test for empty modules.builtin.aliases.binLucas De Marchi12-1/+13
2020-12-27shared: fix UNIQ definitionLucas De Marchi2-3/+6
We need a macro indirection for UNIQ to work. Otherwise it won't be unique at all since it will just append "UNIQ" to the name: In file included from testsuite/test-init.c:30: testsuite/testsuite.h:142:27: error: redefinition of ‘stest_load_resourcesUNIQ’
2020-12-27depmod: unconditionally write builtin.alias.binLucas De Marchi1-4/+6
The file is always created and unless we return an error, the temporary file is renamed to its final destination. All other places write the index without checking if the index is empty, so just do the same. Reported-by: Joe Buehler <aspam@cox.net>
2020-12-03ci: remove semaphoreciLucas De Marchi1-46/+0
It's currently failing and we are already covered by travis-ci.
2020-12-03ci: update travis distroLucas De Marchi1-11/+5
Don't bother with gcc 4.8 vs 4.9, just use the latest one for the distro. Update travis to ubuntu 20.04 so we can get current dependencies.
2020-12-03NEWS: fix typoShuo Wang1-1/+1
2020-12-01libkmod: kmod_log_null: qualify ctx argument as constYauheni Kaliuta1-1/+1
kmod_log_null() does not change ctx (does nothing). Fix warnings In file included from libkmod/libkmod-index.c:33: libkmod/libkmod-index.c: In function ‘index_mm_open’: libkmod/libkmod-index.c:757:6: warning: passing argument 1 of ‘kmod_log_null’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 757 | DBG(ctx, "file=%s\n", filename); Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2020-12-01depmod: output_builtin_alias_bin: free idx on error pathYauheni Kaliuta1-7/+4
idx is allocated in the beginning but it's not freed if there is a failure after the allocation. Change the error path: return immediately if idx allocation fails and then free it in both success and error path at the end. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2020-12-01libkmod: kmod_builtin_get_modinfo: free modinfo on errorYauheni Kaliuta1-0/+1
The function allocates array but on building it if get_string() fails it returns the error leaving the array allocated. The caller does not care about it in error case either. Free it to fix memory leak. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2020-10-19man: fix typoSamanta Navarro1-1/+1
2020-09-10testsuite: add test for zstd-compressed moduleTorge Matthies1-1/+9
I took away one module from the gzip-compressed modules for this purpose. Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
2020-09-10add Zstandard compression supportTorge Matthies10-6/+178
I changed the style of the hackargs variable in autogen.sh to multiline because said line was becoming a bit long with the new --with-zstd arg added. A previous version of this patch has been running on my two Arch Linux installations (with an accompanying mkinitcpio patch) for several months over many kernel updates without any issues. Any additional testing and/or patch review would of course be appreciated. Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
2020-03-23testsuite: add check for kmod_load_resourcesLucas De Marchi11-0/+36
Make sure we can call kmod_load_resources when we do have all the mandatory indexes in place.
2020-03-23libkmod: allow modules.alias.builtin to be optionalLucas De Marchi1-3/+12
2020-03-23libkmod: fix return error when opening indexLucas De Marchi3-22/+29
When calling kmod_load_resources() we could end up getting a bogus return value -ENOMEM due to several other reasons, like the index not existing. Change index_mm_open() to propagate the failure reason so we can take actions on it or return to the caller.
2020-03-23libkmod: simplify lookup when builtin.modinfo.bin file is missingLucas De Marchi2-18/+15
When we try to lookup a module and builtin.modinfo.bin is missing, we would do the right thing because the caller was replacing the return code with 0 (and the list was not modified). Make it simpler by allowing the caller to check and differentiate the errors between module not found and index not found.
2020-03-13depmod: do not output .bin to stdoutLucas De Marchi1-1/+5
index_write() relies on fseek/ftell to manage the position to which we are write and thus needs the file stream to support it. Right now when trying to write the index to stdout we fail with: depmod: tools/depmod.c:416: index_write: Assertion `initial_offset >= 0' failed. Aborted (core dumped) We have no interest in outputting our index to stdout, so just skip it like is done with other indexes. While at it, add/remove some newlines to improve readability. Reported-by: Yanko Kaneti <yaneti@declera.com> Fix: b866b2165ae6 ("Lookup aliases in the modules.builtin.modinfo")
2020-03-13testsuite: check for ill-formed kcmdlineLucas De Marchi3-0/+32
Commit ca3bf5d47cec ("iommu/amd: Introduces ivrs_acpihid kernel parameter") in the kernel introduced an ill-formed kernel parameter, ivrs_acpihid. The problem is that it may have a dot on the key side: "ivrs_acpihid[00:14.5]=AMD0020:0". This could potentially trip our parser of module options, but right now it's working as intended: the only thing that happens is that after deciding "ivrs_acpihid[00:14" is a module name, it will fail the underscores() routine and the option will be ignored from the kmod pov (not kernel's pov since that driver parsers the kernel command line by itself).
2020-03-13libkmod: ignore kcmdline option if we fail to parse modnameLucas De Marchi1-1/+2
The error message is saying we are ignoring the option on the kernel command line, so just do it.
2020-03-09gitignore: ignore .cache.mk when building modulesLucas De Marchi1-0/+1
2020-02-28gitignore: ignore release filesLucas De Marchi1-1/+2
2020-02-18kmod 27v27Lucas De Marchi3-2/+51
2020-01-20libkmod: reset was_space on second passLucas De Marchi1-0/+1
The softdep config parser uses a 2-pass approach to use a single allocation for all the softdep struct. However "was_space" variable isn't reset between them. This can lead to a buffer overflow. Reported-by: Jorge Lucangeli Obes <jorgelo@google.com> Link: https://lore.kernel.org/linux-modules/CAKYuF5QhGCPCazHQjN-=kFc5kHs7Ok8WqmmGLo31CiOEN8TYdA@mail.gmail.com
2019-12-29libkmod-module: convert return value from system() to errnoTopi Miettinen1-6/+11
Don't use exit status of a command directly as errno code, callers will be confused. Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
2019-12-18modinfo: Show information about built-in modulesAlexey Gladkov3-26/+38
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2019-12-18Lookup aliases in the modules.builtin.modinfoAlexey Gladkov5-2/+98
New modules.builtin.modinfo duplicates modules.builtin in the built-in module name search. If it exists, then we can use this file, but if not, then we need to fallback to the old file. Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2019-12-18libkmod: Add function to get list of built-in modulesAlexey Gladkov2-0/+41
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2019-12-18libkmod: Add parser for modules.builtin.modinfoAlexey Gladkov3-0/+338
The kernel since version v5.2-rc1 exports information about built-in modules in the modules.builtin.modinfo. Information is stored in the same format as in the separate modules (null-terminated string array). The module name is a prefix for each line. $ tr '\0' '\n' < modules.builtin.modinfo ext4.softdep=pre: crc32c ext4.license=GPL ext4.description=Fourth Extended Filesystem ext4.author=Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others ext4.alias=fs-ext4 ext4.alias=ext3 ext4.alias=fs-ext3 ext4.alias=ext2 ext4.alias=fs-ext2 md_mod.alias=block-major-9-* md_mod.alias=md md_mod.description=MD RAID framework md_mod.license=GPL md_mod.parmtype=create_on_open:bool md_mod.parmtype=start_dirty_degraded:int ... Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2019-11-18Makefile.am: filter -Wl,--no-undefinedFabrice Fontaine1-1/+4
Commit 1d14ef82f4a3be741bcdf6b1c6d51ce9dce43567 does not completely fix the build with python 3.8 as we still get link failure due to '-z undefs' being ignored by some versions of ld. Indeed, -z undefs was added by commit 97a232d7335f3bd0231fd9cd39455bde1d563922 in upstream binutils, and this commit was first present in binutils 2.30. So any toolchain using binutils version older than that won't have -z undefs and will build fail on: /home/buildroot/autobuild/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/mips-linux-gnu/5.3.0/../../../../mips-linux-gnu/bin/ld: warning: -z undefs ignored. /home/naourr/work/instance-1/output-1/host/opt/ext-toolchain/bin/../lib/gcc/aarch64_be-linux-gnu/7.3.1/../../../../aarch64_be-linux-gnu/bin/ld: warning: -z undefs ignored. So filter -Wl,--no-undefined to fix the issue Fixes: - http://autobuild.buildroot.org/results/e9645d9969481b09f507f6e0d0b35faaa283eb60 - http://autobuild.buildroot.org/results/06a6d865b6b7d8ebd793bde214f4a4c40e0962e1 Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2019-11-07modprobe: use flags rather than bool argsLucas De Marchi1-8/+8
It's easier to know what the caller is doing when we pass a named flag rather than a list of bools.
2019-11-07travis: remove old compiler failing to build kernel moduleLucas De Marchi1-11/+18
This is when building the kernel modules for testsuite: Makefile:718: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler gcc: error: unrecognized command line option ‘-fstack-protector-strong’ Just drop gcc 4.8 from running tests. Failure not really related to kmod.
2019-11-06testsuite: update gitignoreLucas De Marchi1-1/+4
2019-11-06modprobe: ignore builtin module on recursive removingYauheni Kaliuta1-6/+12
If there are built-in dependencies and any of them is built-in in the kernel, modprobe -r fails with modprobe: FATAL: Module module_name is builtin. It makes sense to ignore such dependencies for the case when removing is called for non-top level module. Example: cifs module, it declares bunch of softdeps and the first one fails on some kernel configs: modprobe: FATAL: Module gcm is builtin. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-10-25Do not check for undefined symbols when building the Python modulesThomas Petazzoni1-1/+1
kmod's configure.ac uses the -Wl,--no-undefined linker flag to verify at link time that all symbols of shared libraries are available, and that there are no undefined symbols. This make perfect sense for regular shared libraries. However, for Python extensions, which will be dlopen()ed inside the Python interpreter, it makes less sense. Since Python 3.8, there is a change in python-config script and Python's pkg-config file: it no longer links Python extensions with the libpython library. See https://docs.python.org/dev/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build which states: On the other hand, pkg-config python3.8 --libs no longer contains -lpython3.8. C extensions must not be linked to libpython (except on Android and Cygwin, whose cases are handled by the script); this change is backward incompatible on purpose. (Contributed by Victor Stinner in bpo-36721.) So, when linking the kmod Python extensions, it currently fails with numerous unresolved symbols, that were previously provided by libpython: /home/test/autobuild/run/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/powerpc64-buildroot-linux-gnu/7.4.0/../../../../powerpc64-buildroot-linux-gnu/bin/ld: libkmod/python/kmod/.libs/list_la-list.o: in function `__Pyx_PyObject_GetAttrStr': list.c:(.text.__Pyx_PyObject_GetAttrStr+0x48): undefined reference to `PyObject_GetAttr' /home/test/autobuild/run/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/powerpc64-buildroot-linux-gnu/7.4.0/../../../../powerpc64-buildroot-linux-gnu/bin/ld: libkmod/python/kmod/.libs/list_la-list.o: in function `__pyx_tp_dealloc_4kmod_4list_ModListItem': list.c:(.text.__pyx_tp_dealloc_4kmod_4list_ModListItem+0x78): undefined reference to `PyObject_CallFinalizerFromDealloc' /home/test/autobuild/run/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/powerpc64-buildroot-linux-gnu/7.4.0/../../../../powerpc64-buildroot-linux-gnu/bin/ld: libkmod/python/kmod/.libs/list_la-list.o: in function `__pyx_tp_dealloc_4kmod_4list_ModList': list.c:(.text.__pyx_tp_dealloc_4kmod_4list_ModList+0x30): undefined reference to `PyErr_Fetch' [Complete log at http://autobuild.buildroot.net/results/79a/79a5a0398723e8cfea0d0aa3dec5f7649aee4c63/build-end.log] Linking with libpython is no longer recommended: those symbols should remain unresolved in the Python extensions, as they wil be properly resolved when the Python extension gets loaded into the Python interpreter. Since we want to keep -Wl,--no-undefined globally in kmod, we leave the configure.ac file unchanged, and instead, specifically in the LDFLAGS used to build the Python extensions, we override -Wl,--no-undefined with -Wl,-z,undefs. Ideally, -Wl,--no-undefined is the same as -Wl,-z,defs, and the effect of these options can be canceled on the linker command line by a following -Wl,-z,undefs (see the ld man page for details). Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Cc: Victor Stinner <victor.stinner@gmail.com>
2019-05-28libkmod-signature: use PKCS#7 instead of CMSStefan Strogin1-18/+19
Linux uses either PKCS #7 or CMS for signing modules (see scripts/sign-file.c). CMS is not supported by LibreSSL or older OpenSSL, so PKCS #7 is used on systems with these libcrypto providers. CMS and PKCS #7 formats are very similar. CMS is newer but is as much as possible backward compatible with PKCS #7 [1]. PKCS #7 is supported in the latest OpenSSL as well as CMS. The fields used for signing kernel modules are supported both in PKCS #7 and CMS. For now modinfo uses CMS with no alternative requiring OpenSSL 1.1.0 or newer. Use PKCS #7 for parsing module signature information, so that modinfo could be used both with OpenSSL and LibreSSL. [1] https://tools.ietf.org/html/rfc5652#section-1.1 Changes v1->v2: - Don't use ifdefs for keeping redundant CMS code, just use PKCS #7 both with OpenSSL and LibreSSL. Signed-off-by: Stefan Strogin <steils@gentoo.org>
2019-03-08tools: Print a message if refcnt attribute is missingEzequiel Garcia2-6/+12
Currently, check_module_inuse returns a wrong user message if the kernel is built without module unloading support. Fix it by returning a more specific error, in case 'refcnt' attribute is missing.
2019-02-20build: Stop using doltAdrian Bunk4-186/+0
This does regress "make -12" from 0.7s to 0.9s on my Coffee Lake machine, but even on slower hardware this will not amount to a noticable slowdown. On the other hand using dolt can create problems for people doing cross-compilation, e.g. Yocto has two hacks just for dolt in kmod: https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-kernel/kmod/kmod.inc?id=a17abae00785c76cfffe5381a22fb2c86b982e82 (Lucas: remove leftover entry in Makefile and reformat commit message)
2019-02-13Link against libcrypto, not all of opensslDave Reisner2-5/+5
In the previous build setup, libkmod.so would link to not just libcrypto.so, but also libssl.so: $ readelf -d /lib/libkmod.so | grep NEEDED 0x0000000000000001 (NEEDED) Shared library: [liblzma.so.5] 0x0000000000000001 (NEEDED) Shared library: [libz.so.1] 0x0000000000000001 (NEEDED) Shared library: [libssl.so.1.1] 0x0000000000000001 (NEEDED) Shared library: [libcrypto.so.1.1] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] We don't need any symbols from libssl, though. This patch ensures that we pass 'libcrypto' to pkgconfig rather than 'openssl', getting only the library that we need: $ readelf -d ./libkmod/.libs/libkmod.so.2.3.4 | grep NEEDED 0x0000000000000001 (NEEDED) Shared library: [liblzma.so.5] 0x0000000000000001 (NEEDED) Shared library: [libz.so.1] 0x0000000000000001 (NEEDED) Shared library: [libcrypto.so.1.1] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
2019-02-07kmod 26v26Lucas De Marchi3-2/+49
2019-02-07build: fix make distcheckLucas De Marchi1-1/+2
Make sure to add the dummy.pkcs7 file to the dist files. While at it, also change the distcheck flags to include --with-openssl.
2019-02-04testsuite: mkosi: update filesLucas De Marchi3-2/+4
- Add openssl - Disable python (quick hack to avoid more dependencies) - Update Fedora to 29
2019-02-04build: check openssl versionLucas De Marchi1-1/+1
2019-02-04build: add openssl to CI depsLucas De Marchi2-3/+5
Travis-ci is at most on Ubuntu 16.04, that doesn't have openssl >= 1.1, so disable openssl there. Semaphore 2.0 was also missing a call to update the package database.
2019-02-04build: enable openssl by defaultLucas De Marchi1-1/+1
Like with other features, let's enable it for developers.
2019-02-04testsuite: fix modinfo test without opensslLucas De Marchi7-7/+25
2019-02-04libkmod-signature: implement pkcs7 parsing with opensslYauheni Kaliuta5-5/+213
The patch adds data fetching from the PKCS#7 certificate using openssl library (which is used by scripts/sign-file.c in the linux kernel to sign modules). In general the certificate can contain many signatures, but since kmod (modinfo) supports only one signature at the moment, only first one is taken. With the current sign-file.c certificate doesn't contain signer key's fingerprint, so "serial number" is used for the key id. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-02-04testsuite: add modinfo pkcs7 signature testYauheni Kaliuta6-4/+14
Use the same approach to generate the signed module, like in the old signature test: just append the pregenerated binary signature to the module (the signature check will fail). In case of need of generating correct signature, from the linux kernel makefiles (certs/Makefile) it could be like: $ openssl req -new -nodes -utf8 -sha256 -days 36500 -batch -x509 -config ./x509.genkey -outform PEM -out signing_key.pem -keyout signing_key.pem $ /lib/modules/$(uname -r)/build/scripts/extract-cert signing_key.pem signing_key.x509 $ /lib/modules/$(uname -r)/build/scripts/sign-file sha256 signing_key.pem signing_key.x509 module.ko where x509.genkey is: ``` [ req ] default_bits = 4096 distinguished_name = req_distinguished_name prompt = no string_mask = utf8only x509_extensions = myexts [ req_distinguished_name ] CN = Build time autogenerated kernel key [ myexts ] basicConstraints=critical,CA:FALSE keyUsage=digitalSignature subjectKeyIdentifier=hash authorityKeyIdentifier=keyid ``` Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-01-14man: Fix typoDaniel Kahn Gillmor1-1/+1
2019-01-04testsuite: factor out fd related parameters to a structureYauheni Kaliuta1-143/+214
This is a more abstract implementation of "file descriptor comparation". With the current implementation the code is full of conditions based on the descriptor type. It makes sense to initialize the parameters once based on the descriptor type. stdout and stderr are handled in almost the same way, but for monitor descriptor branch, based on the type check is necessary in some cases. Since epoll's context now contains pointers to the structures, so no direct manipulations there. Most of the patch is just replacing direct buffer manipulations with the structures' ones. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-01-04testsuite: track number of descriptors instead of their stateYauheni Kaliuta1-1/+6
use the number of tracked descriptors to determine the end of the loop. This is a preparation for more abstract descriptor comparation implementation where checking of the descriptor state may be more expensive than just checking of the local variables. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-01-04Add semaphoreci 2.0 configurationLucas De Marchi3-3/+46
Add another CI as alternative to travis-ci. Test on gcc 6, 7 and 8 on Ubuntu 18.04. Not sure if this is the best way to define the yml file, but it works. The old badge doesn't work. It will be added back later.
2019-01-03testsuite: move --show-exports test to use regexLucas De Marchi2-1/+2
This allows it to pass if the kernel is configured with CONFIG_MODVERSIONS.
2019-01-03testsuite: add support for testing output against regexLucas De Marchi2-2/+119
Allow to test outputs when they don't match exactly, but should follow some regex patterns. This can be used when the info we are printing is randomized or depends on kernel configuration.
2019-01-03testsuite: split out function to compare outputs exactlyLucas De Marchi1-54/+70
Move functionality to compare the exact output to a separate function and allocate one buffer per output/match pair. This will allow us to extend this to allow other types of comparisons. Since now we are using heap-allocated buffer, keep the buffer allocation to the caller, so we don't have to allocate and free it on every invocation. It also avoids the different comparison functions to have to deal with it.
2018-12-17depmod: shut up gcc insufficinet buffer warningMichal Suchanek1-16/+38
In a couple of places depmod concatenates the module directory and filename with snprintf. This can technically overflow creating an unterminated string if module directory name is long. Use openat instead as is done elsewhere in depmod. This avoids the snprintf, the extra buffer on stack, and the gcc warning. It may even fix a corner case when the module direcotry name is just under PATH_MAX. [ Lucas: fix up coding style and closing fd on error path ] Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2018-12-17depmod: prevent module dependency files corruption due to parallel invocation.Michal Suchanek1-2/+7
Depmod does not use unique filename for temporary files. There is no guarantee the user does not attempt to run mutiple depmod processes in parallel. If that happens a temporary file might be created by depmod(1st), truncated by depmod(2nd), and renamed to final name by depmod(1st) resulting in corrupted file seen by user. Due to missing mkstempat() this is more complex than it should be. Adding PID and timestamp to the filename should be reasonably reliable. Adding O_EXCL as mkstemp does fails creating the file rather than corrupting existing file. Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2018-12-17depmod: prevent module dependency files missing during depmod invocationMichal Suchanek1-1/+0
depmod deletes the module dependency files before moving the temporary files in their place. This results in user seeing no dependency files while they are updated. Remove the unlink call. The rename call should suffice to move the new file in place and unlink the old one. It should also do both atomically so there is no window when no dependency file exists. Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2018-12-17Remove bootstrap* scriptsLucas De Marchi7-74/+74
Let's just use autogen.sh, no need for wrapper scripts. Now `autogen.sh c` uses the same recommended options for developing kmod and also accepts extra arguments.
2018-11-30README: Add link to mailing list archiveLucas De Marchi1-0/+1
We now have a proper archive for the mailing list.
2018-11-16signature: do not report wrong data for pkc#7 signatureYauheni Kaliuta2-19/+39
when PKC#7 signing method is used the old structure doesn't contain any useful data, but the data are encoded in the certificate. The info getting/showing code is not aware of that at the moment and since 0 is a valid constant, shows, for example, wrong "md4" for the hash algo. The patch splits the 2 mothods of gethering the info and reports "unknown" for the algo. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2018-11-13testsuite: add simple test for --show-exportsLucas De Marchi3-0/+24
2018-11-13modprobe: add --show-exportsYauheni Kaliuta1-0/+36
modprobe has --show-modversions switch, which dumps symbols with their modversion crcs from the __versions sections. At the moment the section contains information for the dependency symbols only, while exported symbols add to symtab entries with __crc_ prefix (the format may differ, see 1e48901166ef libkmod-elf: resolve CRC if module is built with MODULE_REL_CRCS). The patch makes it to show exported symbols as well. The function is basically cut'n'paste of show_modversions(), but 'version' family replaced with 'symbol' one. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2018-10-10mkosi: allow Clear to use test modulesLucas De Marchi2-7/+3
Now Clear has a bundle for the kernel headers, let's use it.
2018-07-20man: depmod: remove deprecated -m optionLucas De Marchi1-1/+0
Thanks to Howard Johnson <hwj@bridgeportcontractor.com> for noticing.
2018-06-18kmod: build: cure compiler warnings showing up externallyJan Engelhardt1-2/+2
When building a C source file with gcc-7 -Wshift-overflow=2, this warning springs up: libkmod.h: warning: result of "1 << 31" requires 33 bits to represent, but "int" only has 32 bits [-Wshift-overflow=] Change the two _KMOD_* identifiers to fit into 32 bits.
2018-05-16build: fix wrong quotes on bootstrapJakov Simunic1-1/+1
2018-05-14Phrasing correction in modprobe man pageChris Stackpole1-1/+1
2018-04-05libkmod-module: check for NULL before accessing pointersLuca Bruno2-13/+15
This introduces a few missing NULL-checks in public functions, and align their docstrings with real behavior by getting rid of copy-paste mistakes. Signed-off-by: Luca Bruno <luca.bruno@coreos.com>