]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
5 weeks agoInstall kmod.pc in ${datadir}/pkgconfig master
Mike Gilbert [Fri, 8 Mar 2024 19:06:19 +0000 (14:06 -0500)] 
Install kmod.pc in ${datadir}/pkgconfig

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>
5 weeks agobuild: Allow to install over dirty dir
Lucas De Marchi [Wed, 6 Mar 2024 14:58:04 +0000 (08:58 -0600)] 
build: Allow to install over dirty dir

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>
6 weeks agokmod 32 v32
Lucas De Marchi [Wed, 6 Mar 2024 03:27:42 +0000 (21:27 -0600)] 
kmod 32

8 weeks agoRemove unmaintained experimental tools
Emil Velikov [Mon, 12 Feb 2024 17:07:57 +0000 (17:07 +0000)] 
Remove unmaintained experimental tools

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>
8 weeks agoman: silence autoconf warnings
Emil Velikov [Sat, 17 Feb 2024 16:01:26 +0000 (16:01 +0000)] 
man: silence autoconf warnings

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>
2 months agomake: install/uninstall tools symlinks to kmod
Emil Velikov [Fri, 26 Jan 2024 14:43:51 +0000 (14:43 +0000)] 
make: install/uninstall tools symlinks to kmod

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>
2 months agoconfigure: tweak the module_directory help string
Emil Velikov [Fri, 26 Jan 2024 14:43:50 +0000 (14:43 +0000)] 
configure: tweak the module_directory help string

Drop the somewhat misleading ${prefix}/lib/modules and explicitly
mention what's the default.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2 months agogitignore: Ignore *.pc files
Lucas De Marchi [Fri, 2 Feb 2024 18:38:11 +0000 (12:38 -0600)] 
gitignore: Ignore *.pc files

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>
2 months agotestsuite: drop mkosi
Lucas De Marchi [Fri, 2 Feb 2024 18:36:28 +0000 (12:36 -0600)] 
testsuite: drop mkosi

It's not being actively used, so drop it.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 months agoci: drop travis config
Lucas De Marchi [Fri, 2 Feb 2024 18:29:13 +0000 (12:29 -0600)] 
ci: drop travis config

We are not using travis anymore for CI. Drop its configuration.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 months agoDrop python bindings
Lucas De Marchi [Fri, 2 Feb 2024 18:23:15 +0000 (12:23 -0600)] 
Drop python bindings

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>
4 months agoconfigure: Check that provided paths are absolute
Michal Suchanek [Fri, 10 Nov 2023 12:13:55 +0000 (13:13 +0100)] 
configure: Check that provided paths are absolute

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>
4 months agolibkmod, depmod, modprobe: Make directory for kernel modules configurable
Michal Suchanek [Fri, 10 Nov 2023 12:13:54 +0000 (13:13 +0100)] 
libkmod, depmod, modprobe: Make directory for kernel modules configurable

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>
5 months agolibkmod: remove pkcs7 obj_to_hash_algo()
Dimitri John Ledkov [Sun, 29 Oct 2023 01:03:19 +0000 (03:03 +0200)] 
libkmod: remove pkcs7 obj_to_hash_algo()

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
5 months agotools: depmod: fix -Walloc-size
Sam James [Sun, 5 Nov 2023 22:02:25 +0000 (22:02 +0000)] 
tools: depmod: fix -Walloc-size

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>
6 months agokmod: Add pkgconfig file with kmod compile time configuration
Michal Suchanek [Tue, 18 Jul 2023 12:01:55 +0000 (14:01 +0200)] 
kmod: Add pkgconfig file with kmod compile time configuration

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>
6 months agolibkmod, depmod: Load modprobe.d, depmod.d from ${prefix}/lib.
Michal Suchanek [Tue, 18 Jul 2023 12:01:54 +0000 (14:01 +0200)] 
libkmod, depmod: Load modprobe.d, depmod.d from ${prefix}/lib.

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>
6 months agoman/depmod.d: Fix incorrect /usr/lib search path
Michal Suchanek [Tue, 18 Jul 2023 12:01:53 +0000 (14:01 +0200)] 
man/depmod.d: Fix incorrect /usr/lib search path

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>
6 months agoconfigure: Detect openssl sm3 support
Michal Suchanek [Tue, 18 Jul 2023 12:01:52 +0000 (14:01 +0200)] 
configure: Detect openssl sm3 support

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>
6 months agokmod 31 v31
Lucas De Marchi [Fri, 29 Sep 2023 14:18:37 +0000 (09:18 -0500)] 
kmod 31

6 months agolibkmod: add fallback MODULE_INIT_COMPRESSED_FILE define
Emil Velikov [Wed, 27 Sep 2023 15:38:05 +0000 (16:38 +0100)] 
libkmod: add fallback MODULE_INIT_COMPRESSED_FILE define

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>
9 months agolibkmod: Use kernel decompression when available
Lucas De Marchi [Thu, 1 Jun 2023 22:40:01 +0000 (15:40 -0700)] 
libkmod: Use kernel decompression when available

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>
10 months agolibkmod: Keep track of in-kernel compression support
Lucas De Marchi [Thu, 1 Jun 2023 22:40:00 +0000 (15:40 -0700)] 
libkmod: Keep track of in-kernel compression support

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>
10 months agolibkmod: Keep track of compression type
Lucas De Marchi [Thu, 1 Jun 2023 22:39:59 +0000 (15:39 -0700)] 
libkmod: Keep track of compression type

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>
10 months agolibkmod: Extract finit_module vs init_module paths
Lucas De Marchi [Thu, 1 Jun 2023 22:39:58 +0000 (15:39 -0700)] 
libkmod: Extract finit_module vs init_module paths

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>
10 months agolibkmod: Do not inititialize file->memory on open
Lucas De Marchi [Thu, 1 Jun 2023 22:39:57 +0000 (15:39 -0700)] 
libkmod: Do not inititialize file->memory on open

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>
10 months agoshared: avoid passing {NULL, 0} array to bsearch()
Dmitry Antipov [Fri, 19 May 2023 07:41:08 +0000 (10:41 +0300)] 
shared: avoid passing {NULL, 0} array to bsearch()

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>
10 months agolibkmod: fix possible out-of-bounds memory access
Dmitry Antipov [Fri, 19 May 2023 07:46:38 +0000 (10:46 +0300)] 
libkmod: fix possible out-of-bounds memory access

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
10 months agolibkmod, depmod: prefer -ENODATA over -ENOENT if no section found
Dmitry Antipov [Fri, 19 May 2023 09:36:30 +0000 (12:36 +0300)] 
libkmod, depmod: prefer -ENODATA over -ENOENT if no section found

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
12 months agomodprobe: rmmod_do_module: Free kmod list of holders
Nicolas Schier [Tue, 18 Apr 2023 08:52:38 +0000 (10:52 +0200)] 
modprobe: rmmod_do_module: Free kmod list of holders

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>
13 months agoconfigure.ac: fix link with -llzma
Fabrice Fontaine [Thu, 2 Mar 2023 17:54:26 +0000 (18:54 +0100)] 
configure.ac: fix link with -llzma

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>
13 months agoconfigure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES
Emil Velikov [Tue, 21 Feb 2023 13:19:29 +0000 (13:19 +0000)] 
configure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES

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>
13 months agoshared: annotate local API as static
Emil Velikov [Tue, 21 Feb 2023 13:19:28 +0000 (13:19 +0000)] 
shared: annotate local API as static

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>
13 months agolibkmod: annotate kmod_builtin_iter API as static
Emil Velikov [Tue, 21 Feb 2023 13:19:27 +0000 (13:19 +0000)] 
libkmod: annotate kmod_builtin_iter API as static

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>
13 months agolibkmod: remove unused kmod_module_get_builtin
Emil Velikov [Tue, 21 Feb 2023 13:19:26 +0000 (13:19 +0000)] 
libkmod: remove unused kmod_module_get_builtin

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>
14 months agotestsuite: Handle different sysconfdir
Lucas De Marchi [Thu, 9 Feb 2023 19:19:46 +0000 (11:19 -0800)] 
testsuite: Handle different sysconfdir

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>
14 months agotestsuite: Move setup-rootfs logic from Makefile to script
Lucas De Marchi [Thu, 9 Feb 2023 19:19:45 +0000 (11:19 -0800)] 
testsuite: Move setup-rootfs logic from Makefile to script

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>
14 months agolibkmod: error out on unknown hash algorithm
Emil Velikov [Mon, 6 Feb 2023 14:32:59 +0000 (14:32 +0000)] 
libkmod: error out on unknown hash algorithm

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>
14 months agotestsuite/depmod: use defines for the rootfs/lib_modules
Emil Velikov [Mon, 6 Feb 2023 14:04:49 +0000 (14:04 +0000)] 
testsuite/depmod: use defines for the rootfs/lib_modules

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>
14 months agotestsuite: add function declarations for __xstat family
Emil Velikov [Mon, 6 Feb 2023 14:04:47 +0000 (14:04 +0000)] 
testsuite: add function declarations for __xstat family

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>
14 months agotreewide: add some static const notations
Emil Velikov [Mon, 6 Feb 2023 14:04:46 +0000 (14:04 +0000)] 
treewide: add some static const notations

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agodepmod: Introduce outdir option
Emil Velikov [Mon, 6 Feb 2023 13:18:34 +0000 (13:18 +0000)] 
depmod: Introduce outdir option

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>
14 months agoman/rmmod: explain why modprobe -r is more useful
Yauheni Kaliuta [Thu, 2 Feb 2023 13:47:36 +0000 (15:47 +0200)] 
man/rmmod: explain why modprobe -r is more useful

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>
15 months agomodprobe: Allow passing path to module
Gustavo Sousa [Fri, 13 Jan 2023 21:37:45 +0000 (18:37 -0300)] 
modprobe: Allow passing path to module

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>
15 months agomodprobe: Move insertion block into separate function
Gustavo Sousa [Fri, 13 Jan 2023 21:37:44 +0000 (18:37 -0300)] 
modprobe: Move insertion block into separate function

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>
15 months agotestsuite: Wrap chdir()
Gustavo Sousa [Fri, 13 Jan 2023 21:37:43 +0000 (18:37 -0300)] 
testsuite: Wrap chdir()

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>
15 months agokmod: configure.ac: In _Noreturn check, include <stdlib.h> for exit
Florian Weimer [Sat, 17 Dec 2022 16:52:34 +0000 (17:52 +0100)] 
kmod: configure.ac: In _Noreturn check, include <stdlib.h> for exit

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>
16 months agoautogen.sh: remove --with-rootprefix, it is gone since kmod-11
Adam Gołębiowski [Mon, 28 Nov 2022 09:05:31 +0000 (10:05 +0100)] 
autogen.sh: remove --with-rootprefix, it is gone since kmod-11

Signed-off-by: Adam Gołębiowski <adamg@pld-linux.org>
18 months agolibkmod: do not crash on unknown signature algorithm
Mikhail Novosyolov [Sun, 25 Sep 2022 14:46:08 +0000 (17:46 +0300)] 
libkmod: do not crash on unknown signature algorithm

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.

19 months agotestsuite: fix override of `stat` on 32-bit architectures
Julien Cristau [Mon, 5 Sep 2022 08:32:12 +0000 (10:32 +0200)] 
testsuite: fix override of `stat` on 32-bit architectures

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)

21 months agomodprobe: Write error messages to syslog if stderr is unavailable
Quentin Armitage [Fri, 19 Nov 2021 18:33:49 +0000 (18:33 +0000)] 
modprobe: Write error messages to syslog if stderr is unavailable

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.

21 months agobuild: enable building & running tests from a subdir
Dimitri John Ledkov [Thu, 24 Jun 2021 13:53:56 +0000 (14:53 +0100)] 
build: enable building & running tests from a subdir

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>
21 months agotestsuite: repair read of uninitialized memory
Jan Engelhardt [Thu, 30 Jun 2022 16:47:25 +0000 (18:47 +0200)] 
testsuite: repair read of uninitialized memory

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>
21 months agokmod 30 v30
Lucas De Marchi [Thu, 30 Jun 2022 15:19:17 +0000 (08:19 -0700)] 
kmod 30

21 months agolibkmod: Support SM3 hash algorithm
HuaxinLu [Thu, 30 Jun 2022 06:36:05 +0000 (14:36 +0800)] 
libkmod: Support SM3 hash algorithm

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>
21 months agoREADME: Update optional dependencies
Lucas De Marchi [Wed, 29 Jun 2022 05:24:41 +0000 (22:24 -0700)] 
README: Update optional dependencies

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agoKeep only one readme
Lucas De Marchi [Wed, 29 Jun 2022 05:23:34 +0000 (22:23 -0700)] 
Keep only one readme

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agomodprobe: Add --wait
Lucas De Marchi [Fri, 3 Jun 2022 21:50:47 +0000 (14:50 -0700)] 
modprobe: Add --wait

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>
21 months agotestsuite: Add tests for sleep calculation
Lucas De Marchi [Fri, 3 Jun 2022 21:50:46 +0000 (14:50 -0700)] 
testsuite: Add tests for sleep calculation

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agoutil: Add exponential backoff sleep
Lucas De Marchi [Fri, 3 Jun 2022 21:50:45 +0000 (14:50 -0700)] 
util: Add exponential backoff sleep

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>
21 months agoutil: Add msec variants for time-related functions
Lucas De Marchi [Fri, 3 Jun 2022 21:50:44 +0000 (14:50 -0700)] 
util: Add msec variants for time-related functions

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agoutil: Add time-related functions from testsuite
Lucas De Marchi [Fri, 3 Jun 2022 21:50:43 +0000 (14:50 -0700)] 
util: Add time-related functions from testsuite

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>
21 months agomodule-playground: Add debugfs entry in mod-simple
Lucas De Marchi [Fri, 3 Jun 2022 21:50:42 +0000 (14:50 -0700)] 
module-playground: Add debugfs entry in mod-simple

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>
21 months agolibkmod: Allow to ignore log message on module removal
Lucas De Marchi [Fri, 3 Jun 2022 21:50:41 +0000 (14:50 -0700)] 
libkmod: Allow to ignore log message on module removal

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>
21 months agomodprobe: Move -R to "Query options"
Lucas De Marchi [Fri, 3 Jun 2022 21:50:40 +0000 (14:50 -0700)] 
modprobe: Move -R to "Query options"

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agomodprobe: re-use modname variable
Lucas De Marchi [Fri, 3 Jun 2022 20:49:02 +0000 (13:49 -0700)] 
modprobe: re-use modname variable

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agodepmod: Fix writing over array length
Lucas De Marchi [Fri, 3 Jun 2022 20:49:01 +0000 (13:49 -0700)] 
depmod: Fix writing over array length

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>
2 years agomodprobe: Make rmmod_do_module() contain all the removal sequence
Lucas De Marchi [Tue, 29 Mar 2022 09:05:40 +0000 (02:05 -0700)] 
modprobe: Make rmmod_do_module() contain all the removal sequence

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>
2 years agomodprobe: move check for remove_holders to caller
Lucas De Marchi [Tue, 29 Mar 2022 09:05:39 +0000 (02:05 -0700)] 
modprobe: move check for remove_holders to caller

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>
2 years agomodprobe: Fix holders removal
Lucas De Marchi [Tue, 29 Mar 2022 09:05:37 +0000 (02:05 -0700)] 
modprobe: Fix holders removal

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>
2 years agomodprobe: remove unneeded variable str_start
Masahiro Yamada [Thu, 10 Feb 2022 02:14:23 +0000 (11:14 +0900)] 
modprobe: remove unneeded variable str_start

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>
2 years agomodprobe: fix the NULL-termination of new_argv
Masahiro Yamada [Thu, 10 Feb 2022 02:14:22 +0000 (11:14 +0900)] 
modprobe: fix the NULL-termination of new_argv

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>
2 years agodepmod: Add support for excluding a directory
Saul Wold [Thu, 31 Mar 2022 21:56:28 +0000 (14:56 -0700)] 
depmod: Add support for excluding a directory

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>
2 years agomodprobe: Rename rmmod_do_deps_list
Lucas De Marchi [Tue, 29 Mar 2022 06:55:03 +0000 (23:55 -0700)] 
modprobe: Rename rmmod_do_deps_list

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>
2 years agodocs: Add missing functions to documentation
Lucas De Marchi [Thu, 3 Mar 2022 08:57:10 +0000 (00:57 -0800)] 
docs: Add missing functions to documentation

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2 years agolibkmod: Fix use of sizeof instead of ARRAY_SIZE
Lucas De Marchi [Wed, 23 Feb 2022 18:19:13 +0000 (10:19 -0800)] 
libkmod: Fix use of sizeof instead of ARRAY_SIZE

Link: https://github.com/kmod-project/kmod/issues/12
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2 years agomodinfo: Allow to force arg as module name
Lucas De Marchi [Wed, 16 Feb 2022 07:36:49 +0000 (23:36 -0800)] 
modinfo: Allow to force arg as module name

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>
2 years agomodinfo: Update help message with "modulename"
Lucas De Marchi [Wed, 16 Feb 2022 07:16:33 +0000 (23:16 -0800)] 
modinfo: Update help message with "modulename"

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>
2 years agolibkmod: Add lookup from module name
Lucas De Marchi [Wed, 16 Feb 2022 07:10:58 +0000 (23:10 -0800)] 
libkmod: Add lookup from module name

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>
2 years agolibkmod: Update docs about indexes order
Lucas De Marchi [Wed, 16 Feb 2022 06:47:06 +0000 (22:47 -0800)] 
libkmod: Update docs about indexes order

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>
2 years agolibkmod: Add helper function to iterate lookup options
Lucas De Marchi [Wed, 16 Feb 2022 03:12:05 +0000 (19:12 -0800)] 
libkmod: Add helper function to iterate lookup options

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>
2 years agogitignore: ignore gtk-doc.make
Lucas De Marchi [Wed, 16 Feb 2022 01:28:53 +0000 (17:28 -0800)] 
gitignore: ignore gtk-doc.make

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agolibkmod-module: Fix return code for kmod_module_new_from_lookup()
Lucas De Marchi [Tue, 15 Feb 2022 22:09:14 +0000 (14:09 -0800)] 
libkmod-module: Fix return code for kmod_module_new_from_lookup()

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>
2 years agotest-initstate: Check for negative value on error
Lucas De Marchi [Tue, 15 Feb 2022 22:05:13 +0000 (14:05 -0800)] 
test-initstate: Check for negative value on error

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>
2 years agodepmod: Stop opening modules.modinfo once per module
Lucas De Marchi [Thu, 10 Feb 2022 02:07:03 +0000 (18:07 -0800)] 
depmod: Stop opening modules.modinfo once per module

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

2 years agodepmod: Do not duplicate builtin index
Lucas De Marchi [Thu, 10 Feb 2022 02:46:34 +0000 (18:46 -0800)] 
depmod: Do not duplicate builtin index

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

2 years agolibkmod: Prefer builtin index over builtin.alias
Lucas De Marchi [Thu, 10 Feb 2022 02:21:03 +0000 (18:21 -0800)] 
libkmod: Prefer builtin index over builtin.alias

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.

2 years agolibkmod: Set builtin to no when module is created from path.
Michal Suchanek [Wed, 18 Aug 2021 20:52:00 +0000 (22:52 +0200)] 
libkmod: Set builtin to no when module is created from path.

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>
2 years agolibkmod: add a library notice log level print
Luis Chamberlain [Tue, 10 Aug 2021 05:16:00 +0000 (22:16 -0700)] 
libkmod: add a library notice log level print

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>
2 years agolibkmod-module: check "new_from_name" return value in get_builtin
Yauheni Kaliuta [Tue, 8 Jun 2021 06:29:22 +0000 (09:29 +0300)] 
libkmod-module: check "new_from_name" return value in get_builtin

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>
2 years agokmod 29 v29
Lucas De Marchi [Thu, 20 May 2021 23:02:57 +0000 (16:02 -0700)] 
kmod 29

2 years agotestsuite: update gitignore
Lucas De Marchi [Tue, 11 May 2021 16:57:10 +0000 (09:57 -0700)] 
testsuite: update gitignore

2 years agodepmod: fix modules.builtin.alias.bin output
Lucas De Marchi [Tue, 11 May 2021 16:48:04 +0000 (09:48 -0700)] 
depmod: fix modules.builtin.alias.bin output

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.

2 years agoFix return value doc for kmod_module_get_info()
Lucas De Marchi [Tue, 11 May 2021 16:47:09 +0000 (09:47 -0700)] 
Fix return value doc for kmod_module_get_info()

We don't return 0 on success, we return the number of elements we added
to the list.

3 years agolibkmod: fix possible double free with wrong modules.builtin.modinfo
Seung-Woo Kim [Tue, 13 Apr 2021 11:23:15 +0000 (20:23 +0900)] 
libkmod: fix possible double free with wrong modules.builtin.modinfo

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>
3 years agolibkmod: fix an overflow with wrong modules.builtin.modinfo
Seung-Woo Kim [Tue, 13 Apr 2021 11:23:14 +0000 (20:23 +0900)] 
libkmod: fix an overflow with wrong modules.builtin.modinfo

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>
3 years agogitignore: ignore .mbx and .cover for b4 integration
Lucas De Marchi [Sat, 17 Apr 2021 20:39:12 +0000 (13:39 -0700)] 
gitignore: ignore .mbx and .cover for b4 integration

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.

3 years agolibkmod-config: fix a memory leak when kmod_list_append() fails
Seung-Woo Kim [Fri, 9 Apr 2021 09:44:23 +0000 (18:44 +0900)] 
libkmod-config: fix a memory leak when kmod_list_append() fails

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>
3 years agolibkmod-config: more chars allowed as space
Lucas De Marchi [Wed, 10 Mar 2021 16:33:01 +0000 (08:33 -0800)] 
libkmod-config: more chars allowed as space

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 ' '.

3 years agotest-modprobe: share single function for kcmdline tests
Lucas De Marchi [Fri, 12 Feb 2021 09:45:24 +0000 (01:45 -0800)] 
test-modprobe: share single function for kcmdline tests