]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
4 months agolibkmod: refactor kmod_module_hex_to_str
Tobias Stoeckmann [Mon, 24 Feb 2025 18:55:28 +0000 (19:55 +0100)] 
libkmod: refactor kmod_module_hex_to_str

The hex output uses a heap-based strbuf. It can be turned into a
stack-based strbuf by refactoring kmod_module_hex_to_str. Instead of
returning a C string, a supplied strbuf can be filled with hex values
in ASCII representation. Renamed to kmod_module_strbuf_pushhex.

A size of 512 is sufficient for signatures on Arch Linux and removes
heap allocations. Additional benefit is implicit strbuf_init and
strbuf_release due to DECLARE_STRBUF_WITH_STACK.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/296
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agodepmod: use stack strbuf where possible
Tobias Stoeckmann [Mon, 24 Feb 2025 18:49:40 +0000 (19:49 +0100)] 
depmod: use stack strbuf where possible

The deps bin output uses a strbuf. A size of 2048 covers all cases
on current Arch Linux (max used size is 1548) and removes heap
allocations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/296
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agolibkmod: use stack strbuf for index processing
Tobias Stoeckmann [Mon, 24 Feb 2025 18:48:05 +0000 (19:48 +0100)] 
libkmod: use stack strbuf for index processing

The strbuf content is never returned, so it's easy to switch to a
stack-based solution. It removes heap allocations and the need to
manually call strbuf_init and strbuf_release since these are covered
through DECLARE_STRBUF_WITH_STACK as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/296
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agolibkmod: release memory on builtin error path
Tobias Stoeckmann [Sat, 22 Feb 2025 18:53:43 +0000 (19:53 +0100)] 
libkmod: release memory on builtin error path

If the modules.builtin.modinfo file contains valid and invalid
lines, it is possible that libkmod leaks memory on error path.

Let strbuf API take care to always release strbuf and reset it
if allocated heap memory is taken away from it.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/291
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agomodinfo: reduce amount of continue statements
Tobias Stoeckmann [Sat, 22 Feb 2025 14:24:33 +0000 (15:24 +0100)] 
modinfo: reduce amount of continue statements

Clarify that the code does not perform error checks, for which we
regularly use checks and continue at the start, but merely checks
how to print/filter the data.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/290
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agotestsuite: Improve fake_delete behavior
Gongjun Song [Fri, 7 Mar 2025 02:33:51 +0000 (10:33 +0800)] 
testsuite: Improve fake_delete behavior

- When fake delete_module() succeeds, remove its entry from /sys/module.
- Add tests to ensure module is properly removed.

Co-developed-by: Qingqing Li <qingqing.li@intel.com>
Signed-off-by: Qingqing Li <qingqing.li@intel.com>
Signed-off-by: Dan He <dan.h.he@intel.com>
Signed-off-by: Gongjun Song <gongjun.song@intel.com>
Signed-off-by: Yuchi Chen <yuchi.chen@intel.com>
Signed-off-by: Wenjie Wang <wenjie2.wang@intel.com>
Link: https://github.com/kmod-project/kmod/pull/309
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Test with different moduledir
Lucas De Marchi [Tue, 4 Mar 2025 21:57:21 +0000 (15:57 -0600)] 
ci: Test with different moduledir

Add a test for a common setup (/usr/lib/modules) and a weird one
(/kernel-modules) to cover uses of moduledir.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agomeson: Show compiler and linker in summary
Lucas De Marchi [Fri, 28 Feb 2025 14:44:55 +0000 (08:44 -0600)] 
meson: Show compiler and linker in summary

Make it easy to identify the compiler and linker being used.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Add pipeline to test linking with lld
Lucas De Marchi [Mon, 6 Jan 2025 16:37:56 +0000 (10:37 -0600)] 
ci: Add pipeline to test linking with lld

Test linking with lld to avoid issues like
https://github.com/kmod-project/kmod/issues/269

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Switch most builds to 64b
Lucas De Marchi [Thu, 27 Feb 2025 16:47:08 +0000 (10:47 -0600)] 
ci: Switch most builds to 64b

Due to a mistake on using "multilib" fixed in commit
271d8ab ("ci: Fix 32b build ignoring options") and commit
6897912 ("ci: s/multilib/x32/"), most of our builds were actually
testing 32b, which is not the most common thing.

Leave just 2 32b builds, one with Archlinux and the other with Ubuntu
and remove the FIXME about configuration.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Fix 32b build ignoring options
Lucas De Marchi [Thu, 27 Feb 2025 14:48:56 +0000 (08:48 -0600)] 
ci: Fix 32b build ignoring options

In some configurations we pass meson_setup and x32 options, but the
options were being ignored in 32b builds. Unify the configure/build/test
steps since just the 32b configuration step that needs to be handled
differently, then make sure --native-file and the configure options
are also handled for 32b builds.

Add a 64b configuration for Archlinux and disable test on Archlinux x32
since it's failing due to packages installed and/or distro
configuration.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: s/multilib/x32/
Lucas De Marchi [Thu, 27 Feb 2025 14:38:19 +0000 (08:38 -0600)] 
ci: s/multilib/x32/

It's confusing using "multilib" because it's not about adding the
"capability of building 32b", it's rather "this is really building and
testing 32b, which takes different steps.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Test with Debian bullseye
Lucas De Marchi [Wed, 26 Feb 2025 03:24:58 +0000 (21:24 -0600)] 
ci: Test with Debian bullseye

This is used to build LibreELEC as per
https://github.com/kmod-project/kmod/issues/298. Test with it.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Drop container object
Lucas De Marchi [Thu, 27 Feb 2025 08:06:31 +0000 (02:06 -0600)] 
ci: Drop container object

Just use all the properties in a single level rather than embeding it in
the container object.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Use include to completly specify the matrix
Lucas De Marchi [Thu, 27 Feb 2025 06:36:33 +0000 (00:36 -0600)] 
ci: Use include to completly specify the matrix

The permutation available in github and extending it "include" or
reducing it with "exclude" are much harder than needed. It doesn't seem
we can have a mix of "properties" with the configurations. Just give up
and completly specify the matrix. Now that there's only 1 build system,
at least doing all the permutations doesn't make it too big.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agobuild: Drop autotools
Lucas De Marchi [Fri, 21 Feb 2025 23:09:37 +0000 (17:09 -0600)] 
build: Drop autotools

Simplify our lives by handling just one build system.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Remove autotools dependencies from containers
Lucas De Marchi [Fri, 21 Feb 2025 23:06:55 +0000 (17:06 -0600)] 
ci: Remove autotools dependencies from containers

Not needed anymore.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agoci: Drop autotools builds
Lucas De Marchi [Fri, 21 Feb 2025 23:05:00 +0000 (17:05 -0600)] 
ci: Drop autotools builds

Not needed anymore.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agomeson: Fix setting an absolute customdir
Hendrik Donner [Mon, 3 Mar 2025 15:10:56 +0000 (16:10 +0100)] 
meson: Fix setting an absolute customdir

The path join operator / does not add a leading path seperator.

Signed-off-by: Hendrik Donner <hd@os-cillation.de>
Link: https://github.com/kmod-project/kmod/pull/303
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
4 months agomeson: Use short options for ln everywhere
Hendrik Donner [Mon, 3 Mar 2025 15:13:01 +0000 (16:13 +0100)] 
meson: Use short options for ln everywhere

Some implementations of ln (toybox, busybox) typically only support the
short option format, so use it consistently.

The short options are already used in other places and it's usually
supported on more implementations: -s and -f are POSIX and the few
ln that support --relative understand -r. Which are GNU coreutils,
the Rust uutils coreutils, toybox (-r only) and there is an old
patch for busybox (-r only). The BSDs and MacOS don't seem to
support --relative at all.

Signed-off-by: Hendrik Donner <hd@os-cillation.de>
Link: https://github.com/kmod-project/kmod/pull/303
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agolibkmod: Fix UB for non-existent keys
Lucas De Marchi [Thu, 27 Feb 2025 15:40:11 +0000 (09:40 -0600)] 
libkmod: Fix UB for non-existent keys

When running the testsuite with UBSAN and a non-existent info key is
used, the following happens:

TESTSUITE: running test_modinfo_sig_hashalgo, in forked context
TESTSUITE: ERR: 'test_modinfo_sig_hashalgo' [4212] terminated by signal 6 (Aborted)
TESTSUITE: ------
TESTSUITE: running test_modinfo_sig_key, in forked context
TESTSUITE: ERR: 'test_modinfo_sig_key' [4292] terminated by signal 6 (Aborted)
TESTSUITE: ------
TESTSUITE: running test_modinfo_signer, in forked context
TESTSUITE: ERR: 'test_modinfo_signer' [4348] terminated by signal 6 (Aborted)

In CI this happens when disabling module signature handling with
-D openssl=disabled. The UBSAN report is as below:

../dist-unpack/kmod-34/libkmod/libkmod-module.c:1773:2: runtime error: null pointer passed as argument 2, which is declared to never be null
    #0 0x55bb657aa13b  (/__w/kmod/kmod/build/meson-private/dist-build/kmod+0x9f13b) (BuildId: 2c8f9c0ffdbcdf249a3cca29a9d2bc47f706a324)
    #1 0x55bb6580a4be  (/__w/kmod/kmod/build/meson-private/dist-build/kmod+0xff4be) (BuildId: 2c8f9c0ffdbcdf249a3cca29a9d2bc47f706a324)
    #2 0x55bb657cc360  (/__w/kmod/kmod/build/meson-private/dist-build/kmod+0xc1360) (BuildId: 2c8f9c0ffdbcdf249a3cca29a9d2bc47f706a324)
    #3 0x55bb657cdf43  (/__w/kmod/kmod/build/meson-private/dist-build/kmod+0xc2f43) (BuildId: 2c8f9c0ffdbcdf249a3cca29a9d2bc47f706a324)
    #4 0x7f0651bb3487  (/usr/lib/libc.so.6+0x27487) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
    #5 0x7f0651bb354b  (/usr/lib/libc.so.6+0x2754b) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
    #6 0x55bb657aeb14  (/__w/kmod/kmod/build/meson-private/dist-build/kmod+0xa3b14) (BuildId: 2c8f9c0ffdbcdf249a3cca29a9d2bc47f706a324)

Keep the current behavior of appending a 0-length value, just skipping
the pointless memcpy.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/300
5 months agomeson: Fix build with glibc 2.31
Lucas De Marchi [Tue, 25 Feb 2025 14:49:50 +0000 (08:49 -0600)] 
meson: Fix build with glibc 2.31

In order to use dlopen it may be required to link with libdl depending
on the libc. Add the proper dependency to fix the build in Debian
Bullseye.

Closes: https://github.com/kmod-project/kmod/issues/298
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/299
5 months agobuild: support missing gtkdocize in releases
Tobias Stoeckmann [Mon, 24 Feb 2025 18:34:10 +0000 (19:34 +0100)] 
build: support missing gtkdocize in releases

The release tarballs may already contain symbolic links into the
file system for gtk-doc specific files.

If gtk-doc is not installed, and thus not desired for building,
remove the symbolic links and create empty files instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/295
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agoci: add pahole for Debian unstable
Tobias Stoeckmann [Mon, 24 Feb 2025 16:12:24 +0000 (17:12 +0100)] 
ci: add pahole for Debian unstable

The pahole package is required in our test suite for module creation:

  BTF [M] /__w/kmod/kmod/build/testsuite/module-playground/mod-simple.ko
/bin/sh: 1: pahole: not found
make[3]: *** [/usr/src/linux-headers-6.12.16-common/scripts/Makefile.modfinal:64: /__w/kmod/kmod/build/testsuite/module-playground/mod-simple.ko] Error 127

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/294
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agoNEWS: ditch mention of libxz.so
Jan Engelhardt [Fri, 21 Feb 2025 22:43:42 +0000 (23:43 +0100)] 
NEWS: ditch mention of libxz.so

There is no libxz.so; xz produces liblzma.so.N.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Link: https://github.com/kmod-project/kmod/pull/288
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agokmod 34 v34
Lucas De Marchi [Fri, 21 Feb 2025 20:28:48 +0000 (14:28 -0600)] 
kmod 34

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agobuild: Run autogen.sh for autotools compatibility
Lucas De Marchi [Tue, 18 Feb 2025 14:58:41 +0000 (08:58 -0600)] 
build: Run autogen.sh for autotools compatibility

When generating the dist archive, run autogen.sh so the tarball can also
be used by distros using autotools.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agobuild: Drop NEWS-checking from autotools
Lucas De Marchi [Mon, 17 Feb 2025 17:08:21 +0000 (11:08 -0600)] 
build: Drop NEWS-checking from autotools

Help with the build transition and release.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agokmod: use program_invocation_short_name more often
Tobias Stoeckmann [Wed, 19 Feb 2025 18:18:23 +0000 (19:18 +0100)] 
kmod: use program_invocation_short_name more often

Remove the explicit basename(argv[0]) calls because we already
rely on program_invocation_short_name even before reaching
these lines. Unifies code and slightly reduces binary size.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/284
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agostatic-nodes: unify return statements
Tobias Stoeckmann [Wed, 19 Feb 2025 18:35:51 +0000 (19:35 +0100)] 
static-nodes: unify return statements

The write_* functions have different return statement handling. Unify
them by removing "else" if the if-block itself returns and also unify
the error handling by checking for the error case, leaving the success
return statement at the end of the function.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/285
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agomodprobe: unify help output
Tobias Stoeckmann [Wed, 19 Feb 2025 21:21:48 +0000 (22:21 +0100)] 
modprobe: unify help output

Add = to modprobe help output for --wait to comply with all other long
option descriptions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/287
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agoman: add -h explanation to modinfo.8
Tobias Stoeckmann [Wed, 19 Feb 2025 21:19:00 +0000 (22:19 +0100)] 
man: add -h explanation to modinfo.8

Unifiy modinfo.8 with other manual pages by also explaining what
-h option does.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/287
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agoman: use = for long options
Tobias Stoeckmann [Wed, 19 Feb 2025 21:13:31 +0000 (22:13 +0100)] 
man: use = for long options

Stay in sync with other manual pages like the ones from coreutils
and the -h output of kmod tools.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/287
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agostatic-nodes: do not open /dev/stdout explicitly
Tobias Stoeckmann [Tue, 18 Feb 2025 21:40:40 +0000 (22:40 +0100)] 
static-nodes: do not open /dev/stdout explicitly

If no -o option is given, use stdout directly without opening
/dev/stdout manually. In a chroot environment, this could lead
to /dev/stdout creation as a regular file.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/283
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agolibkmod: Check correct ELF header size
Tobias Stoeckmann [Sat, 15 Feb 2025 21:03:34 +0000 (22:03 +0100)] 
libkmod: Check correct ELF header size

Check if enough bytes are available for Elf32_Ehdr, not Elf32_Shdr.
The size of Elf32_Shdr is needed later on.

Since both are 64 bytes, no functional change.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/279
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agolog: fix style
Tobias Stoeckmann [Tue, 18 Feb 2025 21:25:51 +0000 (22:25 +0100)] 
log: fix style

Add a missing newline between two functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/282
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agomodprobe: reduce visibility of use_syslog
Tobias Stoeckmann [Tue, 18 Feb 2025 21:25:05 +0000 (22:25 +0100)] 
modprobe: reduce visibility of use_syslog

The use_syslog variable is only used within main function, so reduce
its visibility.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/282
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agotools: use bool instead of int for log_open
Tobias Stoeckmann [Tue, 18 Feb 2025 21:20:46 +0000 (22:20 +0100)] 
tools: use bool instead of int for log_open

Since log_open takes a booln as argument, turn use_syslog into a
bool instead of using an int. Shrinks binary size with GCC and from
C point of view, this makes the code cleaner.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/282
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
5 months agostrbuf: Remove alloca.h include
Lucas De Marchi [Sat, 15 Feb 2025 01:18:43 +0000 (19:18 -0600)] 
strbuf: Remove alloca.h include

This is not used anymore.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 months agoci: Stop using ubuntu-latest
Lucas De Marchi [Mon, 6 Jan 2025 19:14:05 +0000 (13:14 -0600)] 
ci: Stop using ubuntu-latest

This generates a bunch of warnings in CI

ubuntu-latest pipelines will use ubuntu-24.04 soon. For more details,
see https://github.com/actions/runner-images/issues/10636

Update to ubuntu 24.04 to catch any possible issues and stop using
ubuntu-latest.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 months agotestsuite: Assert a test binary is non-empty
Lucas De Marchi [Mon, 6 Jan 2025 16:07:07 +0000 (10:07 -0600)] 
testsuite: Assert a test binary is non-empty

Avoid issues like https://github.com/kmod-project/kmod/issues/269
by asserting the test binary is non-empty:

Suggested-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 months agoclang-format: Add new attribute macros
Lucas De Marchi [Mon, 6 Jan 2025 15:16:13 +0000 (09:16 -0600)] 
clang-format: Add new attribute macros

Commits 44855d7 ("shared/macro: Add _alignedptr_") and d7e7c4c
("shared/macro: Add macros for more attributes") added the macros, but
forgot to add them to the clang-format configuration.

Suggested-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 months agotestsuite: Remove trailing ;
Lucas De Marchi [Fri, 3 Jan 2025 19:21:49 +0000 (13:21 -0600)] 
testsuite: Remove trailing ;

Remove trailing ; from DEFINE_TEST_WITH_FUNC() and ensure the callers
add it on their own, like it's done with other defines.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/274
6 months agoshared/macro: Add _alignedptr_
Lucas De Marchi [Fri, 3 Jan 2025 20:35:10 +0000 (14:35 -0600)] 
shared/macro: Add _alignedptr_

Peek what systemd does and do something similar. Instead of hardcoding
8, add a ptr abstraction for the aligned attribute.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/274
6 months agoshared/macro: Add macros for more attributes
Lucas De Marchi [Fri, 3 Jan 2025 20:32:00 +0000 (14:32 -0600)] 
shared/macro: Add macros for more attributes

Move attributes from test definition to a wrapper macro.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/274
6 months agotestsuite: Fix build when linking with lld
Lucas De Marchi [Fri, 3 Jan 2025 19:01:14 +0000 (13:01 -0600)] 
testsuite: Fix build when linking with lld

When building with clang and linking with lld there is an issue with
keeping the kmod_tests sections: On ELF targets, __attribute__((used))
prevents compiler discarding, but does not affect linker --gc-sections,
according to https://lld.llvm.org/ELF/start-stop-gc.

Make sure the _start/_stop symbols are not weak and add the "retain"
attribute.

Closes: https://github.com/kmod-project/kmod/issues/269
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/274
6 months agotools: specify buffer to be size PATH_MAX
Grayson Nocera [Mon, 25 Nov 2024 20:33:02 +0000 (15:33 -0500)] 
tools: specify buffer to be size PATH_MAX

Using a CodeQL query, I discovered that the destination of a `sscanf` call could overflow.
Thus, we bound the buffer size to be PATH_MAX, to ensure that it is
not larger than `modname` or `devname`.

Signed-off-by: Grayson Nocera <gnocera@purdue.edu>
Suggested-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/260
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 months agostrbuf: Extend strbuf_reserve_extra size check
Tobias Stoeckmann [Wed, 18 Dec 2024 09:37:14 +0000 (10:37 +0100)] 
strbuf: Extend strbuf_reserve_extra size check

Make sure that alignment to BUF_STEP won't overflow if excessively
huge amount of memory is requested to be reserved.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/268
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
6 months agolibkmod: Use correct data types for ELF arithmetic
Tobias Stoeckmann [Sun, 22 Dec 2024 18:02:44 +0000 (19:02 +0100)] 
libkmod: Use correct data types for ELF arithmetic

Make sure that no input files could overflow internal variables
used for calculations.

This prevents wrong output and out of boundary writes.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/272
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
7 months agolsmod: Simplify code
Tobias Stoeckmann [Sun, 22 Dec 2024 16:24:57 +0000 (17:24 +0100)] 
lsmod: Simplify code

Reduces cyclomatic complexity and binary size.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/271
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
7 months agoci: Add 2 more pipelines to the matrix
Lucas De Marchi [Thu, 5 Dec 2024 17:59:43 +0000 (11:59 -0600)] 
ci: Add 2 more pipelines to the matrix

Test disabling one of the compression libs while dlopen'ing the rest and
handling 1 linked and 2 dlopen'ed.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agoci: Add configure tests for dlopen
Lucas De Marchi [Sat, 30 Nov 2024 20:48:56 +0000 (14:48 -0600)] 
ci: Add configure tests for dlopen

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agoci: Fix fail due to existent build dir
Lucas De Marchi [Sat, 30 Nov 2024 18:46:21 +0000 (12:46 -0600)] 
ci: Fix fail due to existent build dir

The second check is a "should fail" check, but it will fail because the
build dir already exists rather than for the true reason. Use a
different dir for the configure tests and move the `rm` inside the
function.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agolibkmod: Add ELF notes to compression libraries
Lucas De Marchi [Wed, 4 Dec 2024 15:24:49 +0000 (09:24 -0600)] 
libkmod: Add ELF notes to compression libraries

Follow the new spec for ELF notes as detailed in
https://systemd.io/ELF_PACKAGE_METADATA/.

We can copy mostly verbatim the macros from systemd codebase.

Example output:

$ meson setup --native-file build-dev.ini -Dxz=disabled -Ddlopen=zlib build
...
    dlopen           : zlib

    features         : +ZSTD -XZ +ZLIB +OPENSSL

$ dlopen-notes.py build/libkmod.so.2
# build/libkmod.so.2
[
  {
    "feature": "xz",
    "description": "Support for uncompressing xz-compressed modules",
    "priority": "recommended",
    "soname": [
      "liblzma.so.5"
    ]
  }
]

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agomeson: Allow to set dlopen option for compression libraries
Lucas De Marchi [Wed, 4 Dec 2024 07:19:32 +0000 (01:19 -0600)] 
meson: Allow to set dlopen option for compression libraries

Add a dlopen option that allows toggling what libraries libkmod should
attempt to dlopen. If -Ddlopen=foo is passed, it means that library is
required to build, regardless of -Dfoo=*. However that library will
only be linked in if it's not set as dlopen.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
[ with disagreement on the need to toggle each one individually,
  it'd be better to be all-or-nothing dlopen'ed ]
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agomeson: Let openssl option follow same logic as compression
Lucas De Marchi [Wed, 4 Dec 2024 08:03:07 +0000 (02:03 -0600)] 
meson: Let openssl option follow same logic as compression

Keep the logic similar for all libraries. While at it, add a comment
divider for the config output.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agomeson: Simplify compression handling
Lucas De Marchi [Wed, 4 Dec 2024 07:16:09 +0000 (01:16 -0600)] 
meson: Simplify compression handling

Move libs to a table, similarly to how other things are handled,
so this logic can be more easily expanded in future for all compression
types.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agobuild: Always define ENABLE_* macros
Lucas De Marchi [Wed, 4 Dec 2024 07:04:09 +0000 (01:04 -0600)] 
build: Always define ENABLE_* macros

Define either to 0 or 1 so codebase is forced to used `#if ENABLE_*` or
similar. It's confusing to have some leaving undefined and others
defining as 0 or 1.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agolibkmod/zstd: Allow to load libzstd.so on demand
Lucas De Marchi [Sat, 30 Nov 2024 17:00:22 +0000 (11:00 -0600)] 
libkmod/zstd: Allow to load libzstd.so on demand

Use dlfcn helpers to load libzstd once it's needed.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agolibkmod/zstd: Do not re-use size_t for ret
Lucas De Marchi [Sat, 30 Nov 2024 16:53:49 +0000 (10:53 -0600)] 
libkmod/zstd: Do not re-use size_t for ret

size_t is unsigned, while the function returns a negative number.
Instead of using `ret` for the return from ZSTD_decompress(), re-use
dst_size that should be the same as we passed in for that call since
it already checks for ZSTD_CONTENTSIZE_UNKNOWN and ZSTD_CONTENTSIZE_ERROR.

Even if it's not the same, it's more correct to use that value to
assign to file->size to avoid accessing uninitialized memory.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agolibkmod/zlib: Allow to load libz.so on demand
Lucas De Marchi [Sat, 30 Nov 2024 06:38:11 +0000 (00:38 -0600)] 
libkmod/zlib: Allow to load libz.so on demand

Use dlfcn helpers to load libz once it's needed.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agolibkmod/zlib: s/err/ret/ for consistency
Lucas De Marchi [Sat, 30 Nov 2024 16:22:26 +0000 (10:22 -0600)] 
libkmod/zlib: s/err/ret/ for consistency

Use the libkmod-file-xz.c as reference, keeping similar variable names
so it's easy to share code.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agolibkmod/xz: Allow to load liblzma.so on demand
Lucas De Marchi [Sat, 30 Nov 2024 06:38:11 +0000 (00:38 -0600)] 
libkmod/xz: Allow to load liblzma.so on demand

Use dlfcn helpers to load liblzma once it's needed.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agoutil: Add dlfcn helpers
Lucas De Marchi [Sat, 30 Nov 2024 06:30:53 +0000 (00:30 -0600)] 
util: Add dlfcn helpers

Heavily based on systemd: add similar (but simplified) functions to
dlopen() a library and load specific symbols from it. This will be
useful to allow to load the compression libraries as needed. A few
differences from the systemd implementation:

1) It's allowed to link directly to the library and hence bypass the
   dlopen() + dlsym()
2) The only entrypoint is dlsym_many() which is already declared with
   the sentinel: it's expected callers will use an x-macro that doesn't
   allow forgetting the sentinel
3) No support yet for ELF info annotation yet

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
7 months agoAdd TAKE_PTR()
Lucas De Marchi [Sun, 1 Dec 2024 00:49:00 +0000 (18:49 -0600)] 
Add TAKE_PTR()

Similar to macro in systemd codebase: add a macro that documents we are
"leaking" a pointer that would otherwise be cleaned up by the cleanup
attribute.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/264
7 months agotools: Unify help messages
Tobias Stoeckmann [Mon, 2 Dec 2024 18:35:04 +0000 (19:35 +0100)] 
tools: Unify help messages

Unify help messages shown when kmod is called without any arguments
to use the same grammar and capitalisation.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/265
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite/test-weakdep: remove custom handling
Emil Velikov [Thu, 21 Nov 2024 17:53:47 +0000 (17:53 +0000)] 
testsuite/test-weakdep: remove custom handling

Currently test-weakdep is the only test which explicitly sets the kernel
module lookup directory and the modprobe.d location. It does so by
explicitly hard-coding the full path for both, thus effectively
bypassing the path handling done in our `LD_PRELOAD` module `path.so`.

Just use `kmod_new(NULL, NULL);` which will ensure that everything is
handled relatively to `TC_ROOTFS` defined further down in the test.

Note: this technically reduces our test coverage, although kmod_new() is
not the goal of this test and should be handled separately.

Noticed while removing the TESTSUITE_ROOTFS instances from DEFINE_TEST()

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/258
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: hash_new(): always use a step size of at least 4
Martin Wilck [Thu, 21 Nov 2024 23:02:26 +0000 (00:02 +0100)] 
libkmod: hash_new(): always use a step size of at least 4

The current algorithm would choose a step size of 4 for
n_buckets == 31, but 1 for n_buckets == 32, which seems wrong.
Fix it.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: strbuf_pushchars: handle pushing empty string gracefully
Martin Wilck [Fri, 15 Nov 2024 22:26:26 +0000 (23:26 +0100)] 
libkmod: strbuf_pushchars: handle pushing empty string gracefully

If buf->bytes, buf->used, and len are all 0, buf_grow() will do nothing,
and memcpy() willbe called with a NULL first argument. This will cause
an error because the function is annotated with __nonnull(1, 2).

Fixes: e62d8c7 ("strbuf: make strbuf_pushchars() a little less dumb")
Signed-off-by: Martin Wilck <martin_wilck@gmx.de>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite: test_strbuf_pushmem: test pushing 0 bytes to an empty strbuf
Martin Wilck [Thu, 21 Nov 2024 22:56:10 +0000 (23:56 +0100)] 
testsuite: test_strbuf_pushmem: test pushing 0 bytes to an empty strbuf

This test fails, and will be fixed by the next commit.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: hash_del: handle deleting a non-existing element gracefully
Martin Wilck [Fri, 15 Nov 2024 22:25:15 +0000 (23:25 +0100)] 
libkmod: hash_del: handle deleting a non-existing element gracefully

It can happen that bucket->entries is NULL, but bsearch is annotated
such that it's second argument must be non-NULL.

Fixes: 7db0865 ("Add simple hash implementation")
Signed-off-by: Martin Wilck <martin_wilck@gmx.de>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite: test-hash: add a test for deleting a non-existing element
Martin Wilck [Thu, 21 Nov 2024 22:45:02 +0000 (23:45 +0100)] 
testsuite: test-hash: add a test for deleting a non-existing element

This test fails and will be fixed by the next commit.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: hash_del: fix out-of-bounds memory access
Martin Wilck [Fri, 15 Nov 2024 22:24:30 +0000 (23:24 +0100)] 
libkmod: hash_del: fix out-of-bounds memory access

Assume bucket->used is 1, and element 0 is deleted. We shouldn't access any
memory above (entry + 1) in this case. Likewise, if bucked->used is 2, only
one element should be shifted, etc.

Fixes: 7db0865 ("Add simple hash implementation")
Signed-off-by: Martin Wilck <martin_wilck@gmx.de>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite: test-hash: add a test for deleting a single element
Martin Wilck [Thu, 21 Nov 2024 21:52:34 +0000 (22:52 +0100)] 
testsuite: test-hash: add a test for deleting a single element

...using n_buckets = 32, which will cause a step size of 1.
This test fails, and will be fixed by the next commit.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoman: remove duplicate option in depmod.8.scd
Martin Wilck [Wed, 13 Nov 2024 23:53:14 +0000 (00:53 +0100)] 
man: remove duplicate option in depmod.8.scd

Fixes: c36ddb6 ("depmod: Add option to override MODULE_DIRECTORY")
Signed-off-by: Martin Wilck <martin_wilck@gmx.de>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: expand the deprecated/0xB007FA57 comment
Emil Velikov [Thu, 21 Nov 2024 09:15:36 +0000 (09:15 +0000)] 
libkmod: expand the deprecated/0xB007FA57 comment

Provide a summary how the magic and version fields have evolved. It
serves as better reference than the current "deprecated versions" note.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/256
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite: Test that modprobe --show-depends doesn't load module
Lucas De Marchi [Thu, 21 Nov 2024 14:19:08 +0000 (08:19 -0600)] 
testsuite: Test that modprobe --show-depends doesn't load module

Remove /proc/modules and /sys/module/* from the show-depends rootfs
since they shouldn't be there and add a test to make sure no module is
loaded.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/254
8 months agotestsuite: No need to check for not loaded
Lucas De Marchi [Tue, 19 Nov 2024 14:55:58 +0000 (08:55 -0600)] 
testsuite: No need to check for not loaded

Simplify tests that just dump the configuration: no need to check that
no module was loaded.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/254
8 months agotestsuite: Check cmdline for multiple blacklist
Lucas De Marchi [Tue, 19 Nov 2024 14:53:57 +0000 (08:53 -0600)] 
testsuite: Check cmdline for multiple blacklist

Make sure this (undocumented) behavior doesn't change in future.
Multiple blacklist append to the config.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/254
8 months agotestsuite: Remove duplicated directory
Lucas De Marchi [Tue, 19 Nov 2024 14:48:48 +0000 (08:48 -0600)] 
testsuite: Remove duplicated directory

module-param-kcmdline7 was incorrectly copied inside
module-param-kcmdline{7,8}. Drop the extra dir that is not used
anywhere.

Fixes: d3a1fe67b64c ("libkmod-config: re-quote option from kernel cmdline")
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/254
8 months agolibkmod: Improve index dump performance
Tobias Stoeckmann [Sun, 17 Nov 2024 10:39:59 +0000 (11:39 +0100)] 
libkmod: Improve index dump performance

Buffer data before calling write for output. This reduces the amount
of total write system calls and leads to faster execution times.

This is a simple approach to imitate FILE's I/O buffering, which we
cannot use because we want to properly handle interrupts.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/252
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: use uint8_t for the child prefix/index
Emil Velikov [Sat, 16 Nov 2024 15:20:42 +0000 (15:20 +0000)] 
libkmod: use uint8_t for the child prefix/index

Stop implicitly casting the child prefix/index to int. It can have high
bits set thus get promoted to wildly incorrect value and cause chaos
further on.

In addition, convert the existing `unsigned char` instances to uint8_t,
which better illustrates what we're after - a fixed sized 8 bit unsigned
integer.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/251
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agodepmod: use uint8_t for the child prefix/index
Emil Velikov [Sat, 16 Nov 2024 15:20:42 +0000 (15:20 +0000)] 
depmod: use uint8_t for the child prefix/index

Stop implicitly casting the child prefix/index to int. It can have high
bits set thus get promoted to wildly incorrect value and cause chaos
further on.

In addition, convert the existing `unsigned char` instances to uint8_t,
which better illustrates what we're after - a fixed sized 8 bit unsigned
integer.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/251
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod, tools: Fix format specifiers
Tobias Stoeckmann [Fri, 15 Nov 2024 17:46:58 +0000 (18:46 +0100)] 
libkmod, tools: Fix format specifiers

Use %zu for size_t, not %zd which would be for ssize_t.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/248
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Prevent ouf of boundary access
Tobias Stoeckmann [Fri, 15 Nov 2024 17:45:28 +0000 (18:45 +0100)] 
libkmod: Prevent ouf of boundary access

Follow up of aad7c697, which fixes the same issue in another function.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/248
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Propagate hash_add errors
Tobias Stoeckmann [Fri, 15 Nov 2024 17:43:12 +0000 (18:43 +0100)] 
libkmod: Propagate hash_add errors

If newly created module in kmod_module_new could not be added to hash,
return an error. Otherwise it is possible to create multiple independent
structs with the same name, which the hash set is supposed to prevent.

An error only occurs in out of memory conditions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/248
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite: remove need_spawn = false support
Emil Velikov [Fri, 15 Nov 2024 15:54:43 +0000 (15:54 +0000)] 
testsuite: remove need_spawn = false support

Our test suite is a little unique in my experience in that the test can
be either a normal (fork) child or a (re)spawned one. All the other test
frameworks I have used opt for only one of the two.

I'm not entirely sure why we have both since the latter is sufficient for
all use-cases that we have. Perhaps the former was kept as
micro-optimisation?

Currently I am exploring a way to provide the results summary and the
need_spawn = false ones, are printed multiple times. At a glance I
couldn't quite find a way to fix it.

In addition I am also looking at removing/reducing the use of exit()
across the test suite. Where the two code-flows makes that process more
convoluted.

So let's remove one of the code-paths, simplify things and fix the
logging output. If needed we can re-introduce it later on.

NOTE: there's a lot going on here, because clang-format insist on
reformatting bunch of the DEFINE_TEST() instances :-\

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite/test-init: use distinct test names
Emil Velikov [Fri, 15 Nov 2024 15:44:26 +0000 (15:44 +0000)] 
testsuite/test-init: use distinct test names

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite: run all tests, don't exit on first failure
Emil Velikov [Wed, 13 Nov 2024 12:58:00 +0000 (12:58 +0000)] 
testsuite: run all tests, don't exit on first failure

Instead of exiting on the first failing test execute all tests and
report overall failure as needed.

This gives us a better overview - which do we have single failure or
multiple instances need work - and more consistent results numbers.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite: use exitcode 77 for skipped tests
Emil Velikov [Fri, 15 Nov 2024 15:38:23 +0000 (15:38 +0000)] 
testsuite: use exitcode 77 for skipped tests

Using 77 is a de-facto standard for skipped tests that both autotools
and meson support OOTB. Use that instead of EXIT_SUCCESS aka 0.

Semi-recently we removed the only skip = true tests, although with more
tests incoming we're need bound to have a few users.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite/modprobe: Simplify modprobe exec
Emil Velikov [Fri, 15 Nov 2024 16:54:47 +0000 (16:54 +0000)] 
testsuite/modprobe: Simplify modprobe exec

Too much copy and paste for simple exec tests. Just provide an
EXEC_MODPROBE macro to help.

Hats off to Lucas for the initial idea and porting the depmod test.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotestsuite: Test depmod with relative -m
Lucas De Marchi [Thu, 14 Nov 2024 21:36:09 +0000 (15:36 -0600)] 
testsuite: Test depmod with relative -m

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
8 months agotestsuite: Simplify defines for depmod -m test
Lucas De Marchi [Tue, 19 Nov 2024 07:05:47 +0000 (01:05 -0600)] 
testsuite: Simplify defines for depmod -m test

Simplify the defines so it's easier to extend the test for another
directory.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
8 months agotestsuite/depmod: Simplify depmod exec
Lucas De Marchi [Thu, 14 Nov 2024 20:33:02 +0000 (14:33 -0600)] 
testsuite/depmod: Simplify depmod exec

Too much copy and paste for simple exec tests. Just provide an
EXEC_DEPMOD macro to help.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
8 months agotestsuite/depmod: Remove bogus rootfs from test
Lucas De Marchi [Thu, 14 Nov 2024 16:53:39 +0000 (10:53 -0600)] 
testsuite/depmod: Remove bogus rootfs from test

The testsuite rootfs shouldn't be part of the argument.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
8 months agodepmod: Fix handling relative moduledir
Lucas De Marchi [Thu, 14 Nov 2024 16:33:14 +0000 (10:33 -0600)] 
depmod: Fix handling relative moduledir

Make sure moduledir is always relative to the basedir and document it as
such.

Note: scdoc 1.11.3 produces a strange result when trying to render the
man page for the 2 examples. Workaround that by ending with an explicit
newline, which produces another stranger behavior (but visually correct)
of indenting the next line.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
8 months agoman: Fix reference to MODULEDIR
Lucas De Marchi [Thu, 14 Nov 2024 16:28:37 +0000 (10:28 -0600)] 
man: Fix reference to MODULEDIR

The expression used is <MODULEDIR>, so keep it consistent with the
option name.

Fixes: e9f2580eaf27 ("man: Reword depmod's paths")
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
8 months agodepmod: Remove multiple ternary operations
Lucas De Marchi [Thu, 14 Nov 2024 15:41:05 +0000 (09:41 -0600)] 
depmod: Remove multiple ternary operations

Just keep a separate default value around and use it in case no option
from command line was parsed.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
8 months agoutil: Promote path_is_absolute() to header
Lucas De Marchi [Thu, 14 Nov 2024 15:48:30 +0000 (09:48 -0600)] 
util: Promote path_is_absolute() to header

This is a trivial function that can be used elsewhere. There's no point
in keeping the assert if we are going to crash in the very next
instruction. Rather add the relevant attribute and drop the assert.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
8 months agodepmod: Fix error messages related to module_directory
Lucas De Marchi [Thu, 14 Nov 2024 05:55:10 +0000 (23:55 -0600)] 
depmod: Fix error messages related to module_directory

It's no longer a constant: print the right message.

Fixes: 4f8a6a85 ("tools: Check snprintf return value")
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243