]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
9 months agolibkmod: Simplify module dependency parsing
Tobias Stoeckmann [Thu, 24 Oct 2024 18:54:40 +0000 (20:54 +0200)] 
libkmod: Simplify module dependency parsing

The return value of kmod_module_parse_depline and
module_get_dependencies_noref are never used, and the same is true for
n_dep in struct kmod_module.

Remove them and turn variable n in kmod_module_parse_depline into a
size_t to make sure that it never overflows.

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/211
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Fix typo in libkmod.h
Tobias Stoeckmann [Thu, 24 Oct 2024 18:51:01 +0000 (20:51 +0200)] 
libkmod: Fix typo in libkmod.h

It's "within" instead of "with in".

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/211
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Reduce code duplication
Tobias Stoeckmann [Thu, 24 Oct 2024 18:49:05 +0000 (20:49 +0200)] 
libkmod: Reduce code duplication

If functions exist which cover the exact explicitly written code, use
them instead.

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/211
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Use fread_unlocked
Tobias Stoeckmann [Thu, 17 Oct 2024 08:09:34 +0000 (10:09 +0200)] 
libkmod: Use fread_unlocked

This is in sync with read_char, which uses getc_unlocked. This and
previous FILE based index adjustments improved FILE based index dump
performance by 8 %.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/190
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Add better caching to FILE index
Tobias Stoeckmann [Thu, 17 Oct 2024 07:48:06 +0000 (09:48 +0200)] 
libkmod: Add better caching to FILE index

We can use getdelim and reuse buffers by referencing the index_file
instead of just the FILE handle.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/190
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Read multiple numbers at once
Tobias Stoeckmann [Thu, 17 Oct 2024 07:36:53 +0000 (09:36 +0200)] 
libkmod: Read multiple numbers at once

Reduce the FILE overhead by reading as many bytes as possible at once.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/190
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: factor common strings when handling shell completions
Emil Velikov [Thu, 24 Oct 2024 18:49:18 +0000 (19:49 +0100)] 
meson: factor common strings when handling shell completions

Remove some of the repetition, by moving the common roots as needed.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: bump to 0.61, use install_symlink()
Emil Velikov [Thu, 24 Oct 2024 12:34:45 +0000 (13:34 +0100)] 
meson: bump to 0.61, use install_symlink()

Bump the meson requirement to 0.61 which allows us to remove our clunky
shell script in favour of the native install_symlink().

In terms of OS support - according to repology, all distributions which
have 0.60 (Fedora 36 + winget) also have 0.61 in their repositories.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: disable automatic shell completion on prefix missmatch
Emil Velikov [Thu, 24 Oct 2024 12:46:47 +0000 (13:46 +0100)] 
meson: disable automatic shell completion on prefix missmatch

Currently one can choose a prefix completely different from the one
bash-completion and fish use, as per their pkg-config file.

In such cases, flag a warning and disable it. People can always manually
provide the completion directory/ies to re-enable.

    $ meson setup --prefix=/tmp/example build/
    ...
    WARNING: User provided prefix '/tmp/example' differs from bash-completion one '/usr'. Disabling completion.
    ...
    WARNING: User provided prefix '/tmp/example' differs from fish one '/usr'. Disabling completion.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: remove unused localstatedir=/var
Emil Velikov [Thu, 24 Oct 2024 21:39:31 +0000 (22:39 +0100)] 
meson: remove unused localstatedir=/var

... not sure what I was smoking to add this, since we don't use it
anywhere.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: port moduledir/distconfdir checks from autoconf
Emil Velikov [Thu, 24 Oct 2024 13:27:42 +0000 (14:27 +0100)] 
meson: port moduledir/distconfdir checks from autoconf

Namely, ensure they are absolute paths and any trailing / is stripped.

    $ meson setup -D moduledir=relative/ build/
    ...
    ERROR: Problem encountered: User provided moduledir, 'relative' is not an absolute path.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
[ Fix relative customdir ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: fold distconfdir/moduledir handling
Emil Velikov [Thu, 24 Oct 2024 13:07:52 +0000 (14:07 +0100)] 
meson: fold distconfdir/moduledir handling

We're about to add a few more checks, so instead of duplicating them
fold the handling of custom variables in single place.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: group and print all directories in the summary
Emil Velikov [Thu, 24 Oct 2024 21:35:01 +0000 (22:35 +0100)] 
meson: group and print all directories in the summary

The original listing (both contents and ordering) was copied from
autotools. Update it to be more comprehensive and logical.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: consolidate all get_option('somedir') handling
Emil Velikov [Thu, 24 Oct 2024 12:49:22 +0000 (13:49 +0100)] 
meson: consolidate all get_option('somedir') handling

Consolidate fetching of the directory options in a single place. This
allows us to see what's missing, wrong and prevents error-prone
duplication.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: switch to / operator instead of join_paths()
Emil Velikov [Thu, 24 Oct 2024 22:00:03 +0000 (23:00 +0100)] 
meson: switch to / operator instead of join_paths()

The former was introduced with meson v0.49.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/209
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoRevert "libkmod: call fnmatch() only as needed"
Lucas De Marchi [Thu, 24 Oct 2024 04:59:02 +0000 (23:59 -0500)] 
Revert "libkmod: call fnmatch() only as needed"

This reverts commit e79bba6b4af86216072b56382198da645a0906f4.

This broke alias resolution to more than one module. Example:

kmod v33:
$ modprobe -R char-major-116-1
snd
snd_seq

e79bba6b4af86216072b56382198da645a0906f4:
$ ./modprobe -R char-major-116-1
snd

Closes: https://github.com/kmod-project/kmod/issues/207
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/208
9 months agolibkmod: Read mm index node content on demand
Tobias Stoeckmann [Mon, 21 Oct 2024 16:38:51 +0000 (18:38 +0200)] 
libkmod: Read mm index node content on demand

Many values are never needed, so only parse them on demand. Also keep
pointers into memory-mapped area without copying data into dynamically
sized structs, which allows nodes to be kept on stack.

Improves performance of `modprobe -c` by around 3 %.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/201
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Simplify index search functions
Tobias Stoeckmann [Mon, 21 Oct 2024 15:47:43 +0000 (17:47 +0200)] 
libkmod: Simplify index search functions

Remove arguments with fixed values. Also increment char pointers instead
of working with addresses of indices for easier readability.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/201
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Fix typos
Tobias Stoeckmann [Mon, 21 Oct 2024 15:29:58 +0000 (17:29 +0200)] 
libkmod: Fix typos

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/201
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Const annotate read_*_mm API
Tobias Stoeckmann [Mon, 21 Oct 2024 15:22:45 +0000 (17:22 +0200)] 
libkmod: Const annotate read_*_mm API

Clarify that we never intend to modify the memory-mapped content.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/201
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoCONTRIBUTING.md: mention about gtk-doc Since:
Emil Velikov [Mon, 21 Oct 2024 13:23:55 +0000 (14:23 +0100)] 
CONTRIBUTING.md: mention about gtk-doc Since:

We don't have an easy way to test if API is missing a Since annotation,
so mention that in the contributing guide.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/200
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agodocs: annotate the deprecated API
Emil Velikov [Mon, 21 Oct 2024 13:08:59 +0000 (14:08 +0100)] 
docs: annotate the deprecated API

The kmod_module_get_filtered_blacklist() was deprecated since kmod v6 in
favour of kmod_module_apply_filter().

Add the decoration so gtk-doc includes it in the generated html and also
add a designated index.

It seem that gtk-doc insists on having deprecation guards, so not it
prints an extra warning like:

  warning: XXX is deprecated in the inline comments, but no deprecation
  guards were found around the declaration. (See the --deprecated-guards
  option for gtkdoc-scan.)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/200
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agodocs: add per-version index sections
Emil Velikov [Mon, 21 Oct 2024 13:05:40 +0000 (14:05 +0100)] 
docs: add per-version index sections

With the introduction of the "Since: XX" tags, gtk-doc has been
helpfully reminding us that the per-version index isn't referenced
anywhere.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/200
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: Fix installing without DESTDIR
Lucas De Marchi [Wed, 23 Oct 2024 21:20:14 +0000 (16:20 -0500)] 
meson: Fix installing without DESTDIR

Script fails because of `set -u`. Make sure DESTDIR is set to something

Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # meson v1.6.0
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/206
9 months agotools: Use options_from_array in insmod
Tobias Stoeckmann [Wed, 23 Oct 2024 21:52:05 +0000 (23:52 +0200)] 
tools: Use options_from_array in insmod

Adjust arguments of options_from_array to avoid skipping the first
array entry because that's not intuitive based on its function name.

Fixes insmod's handling of module options given as quoted command line
arguments.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/204
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotools: Extract options_from_array into opt.c
Tobias Stoeckmann [Wed, 23 Oct 2024 21:49:05 +0000 (23:49 +0200)] 
tools: Extract options_from_array into opt.c

The function should be used in insmod as well to allow identical
handling of module options between insmod and modprobe.

Prepare using the function in insmod by extracting it into opt.c.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/204
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: Collect all prefix get_option at one place
Sedat Dilek [Wed, 23 Oct 2024 20:52:49 +0000 (22:52 +0200)] 
meson: Collect all prefix get_option at one place

Signed-off-by: Sedat Dilek <sedat.dilek@gmail.com>
Link: https://lore.kernel.org/r/20241023205352.45271-1-sedat.dilek@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: always pass complete path to kmod-symlink.sh
Emil Velikov [Tue, 22 Oct 2024 20:28:27 +0000 (21:28 +0100)] 
meson: always pass complete path to kmod-symlink.sh

The end-user can provide either relative (to prefix) or an absolute
directory for bindir. Just fold the prefix and bindir with join_path()
which handles this correctly and pass that to kmod-symlink.sh instead of
relying on the MESON_INSTALL_DESTDIR_PREFIX environment variable.

This was previously failing due to trying to create the symlink in the
wrong location:

$ meson setup --prefix /usr --bindir /bin build-gentoo
$ DESTDIR=/tmp/install-gentoo meson install -C build-gentoo/
...
ln: failed to create symbolic link '/tmp/install-gentoo/usr//bin/depmod': No such file or directory
FAILED: install script '/home/ldmartin/p/kmod/scripts/kmod-symlink.sh /bin/depmod' failed with exit code 1.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/205
[ fix typo, add repro ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Prevent OOB with huge amount of symbols
Tobias Stoeckmann [Sun, 20 Oct 2024 14:32:17 +0000 (16:32 +0200)] 
libkmod: Prevent OOB with huge amount of symbols

On 32 bit systems it's possible to overflow the final calculation of
required memory for symbols retrieved from __ksymtab_strings.

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/198
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotools/depmod: use separate arrays for alias,xxxdep values
Emil Velikov [Sun, 20 Oct 2024 12:39:02 +0000 (13:39 +0100)] 
tools/depmod: use separate arrays for alias,xxxdep values

Currently, we walk the info list multiples times each time filtering all
but one key. Just create a few arrays to avoid that, saving 2-3% cycles
at the cost of extra ~500bytes per module.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/197
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Adjust style
Tobias Stoeckmann [Sun, 20 Oct 2024 14:42:39 +0000 (16:42 +0200)] 
libkmod: Adjust style

Add a blank between variable declaration and function calls.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Use correct format specifiers
Tobias Stoeckmann [Sun, 20 Oct 2024 12:57:15 +0000 (14:57 +0200)] 
libkmod: Use correct format specifiers

Use correct format specifiers for size_t variables.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Access correct array
Tobias Stoeckmann [Sun, 20 Oct 2024 12:12:59 +0000 (14:12 +0200)] 
libkmod: Access correct array

The contents of s and strings are identical at this point, but iterate
over the correct variable nonetheless.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Simplify size checks
Tobias Stoeckmann [Sun, 20 Oct 2024 12:08:29 +0000 (14:08 +0200)] 
libkmod: Simplify size checks

An empty section is very unlikely, so reorder code to account for it.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Remove elf_find_section
Tobias Stoeckmann [Sun, 20 Oct 2024 11:58:21 +0000 (13:58 +0200)] 
libkmod: Remove elf_find_section

The function's purpose can be merged into elf_get_section. Reduces
amount of duplicated code.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Inline elf_get_strings_section
Tobias Stoeckmann [Sun, 20 Oct 2024 10:23:42 +0000 (12:23 +0200)] 
libkmod: Inline elf_get_strings_section

Its only caller can do the processing directly (kmod_elf_new).

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Simplify section name handling
Tobias Stoeckmann [Sun, 20 Oct 2024 10:20:43 +0000 (12:20 +0200)] 
libkmod: Simplify section name handling

The name of string section is not needed, so it does not have to stored.
If section name is needed, return a char pointer instead of forcing the
caller to handle offset and memory calculations.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Use ELF offsets more often
Tobias Stoeckmann [Sun, 20 Oct 2024 10:10:09 +0000 (12:10 +0200)] 
libkmod: Use ELF offsets more often

Returned pointers are converted back to offsets in some functions. It is
more readable to turn offsets into pointers though.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Remove struct name
Tobias Stoeckmann [Sun, 20 Oct 2024 09:40:51 +0000 (11:40 +0200)] 
libkmod: Remove struct name

This struct name is never used. Define it just like the other ones in
kmod_elf.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Use correct data types
Tobias Stoeckmann [Sun, 20 Oct 2024 09:38:56 +0000 (11:38 +0200)] 
libkmod: Use correct data types

A huge module file could contain more symbols than could be represented
with an int. Use size_t instead.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Introduce elf_range_valid
Tobias Stoeckmann [Sun, 20 Oct 2024 08:57:51 +0000 (10:57 +0200)] 
libkmod: Introduce elf_range_valid

The range check should be performed in its own function for better
readability and reusability. Also, perform range checks before loops
or otherwise repeated calls by checking whole ranges instead of
single byte areas within said ranges iteratively.

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/196
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Check node offset in index_mm_read_node
Tobias Stoeckmann [Tue, 22 Oct 2024 15:48:32 +0000 (17:48 +0200)] 
libkmod: Check node offset in index_mm_read_node

Add a cheap but important check to make sure that offsets do not point
outside of memory-mapped area.

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/203
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agodepmod: Prevent undefined behavior
Tobias Stoeckmann [Fri, 18 Oct 2024 15:37:40 +0000 (17:37 +0200)] 
depmod: Prevent undefined behavior

Calling qsort with NULL argument is invalid, although size 0 would
prevent anything bad from happening. Make sure that UBSAN is not
triggered.

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/193
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agodepmod: Use strbuf for dependency output
Tobias Stoeckmann [Fri, 18 Oct 2024 15:28:36 +0000 (17:28 +0200)] 
depmod: Use strbuf for dependency output

Use shared/strbuf instead of manually re-implementing its features.
Reduces the amount of custom code in depmod, simplifies auditing,
reduces binary size, and has the nice benefit of slightly faster
runtime due to memory reusage.

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/193
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agodepmod: use array for dependency output
Tobias Stoeckmann [Fri, 18 Oct 2024 15:23:17 +0000 (17:23 +0200)] 
depmod: use array for dependency output

The shared/array implementation is already used within depmod, but not
for dependency output. Adding it here reduces the amount of custom code
in depmod, simplifies auditing, reduces binary size, and has the nice
benefit of slightly faster runtime due to memory reusage.

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/193
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotools/rmmod: minor getopt tweaks
Emil Velikov [Sat, 19 Oct 2024 17:11:17 +0000 (18:11 +0100)] 
tools/rmmod: minor getopt tweaks

Adjust the loop to follow the in-documentation example.

Namely, we don't need the unused idx and removing the seemingly
infinite loop helps static analysers better reason about the code flow.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/195
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotools/lsmod: minor getopt tweaks
Emil Velikov [Sat, 19 Oct 2024 17:11:17 +0000 (18:11 +0100)] 
tools/lsmod: minor getopt tweaks

Adjust the loop to follow the in-documentation example.

Namely, we don't need the unused idx and removing the seemingly
infinite loop helps static analysers better reason about the code flow.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/195
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotools/insmod: minor getopt tweaks
Emil Velikov [Sat, 19 Oct 2024 17:11:17 +0000 (18:11 +0100)] 
tools/insmod: minor getopt tweaks

Pull the unistd.h for optind and adjust the loop to follow the
in-documentation example.

Namely, we don't need the unused idx and removing the seemingly
infinite loop helps static analysers better reason about the code flow.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/195
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Allow better optimization
Tobias Stoeckmann [Wed, 16 Oct 2024 14:55:43 +0000 (16:55 +0200)] 
libkmod: Allow better optimization

If we have native endianess, i.e. parsing modules for the running
system, assist the compiler to note that it is really much faster to
move a word/qword etc. instead of actually running through a loop.

Reduces library instructions on x86_64 by 1.4 % and binary instructions
by 3 % with default configuration.

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/187
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Split elf->class into two booleans
Tobias Stoeckmann [Wed, 16 Oct 2024 14:52:26 +0000 (16:52 +0200)] 
libkmod: Split elf->class into two booleans

Compilers on x86_64 use two instructions to test value of class
variable, i.e. loading a mask and then comparing with value.

A boolean is faster, shows directly what it is about, and the struct
does not even grow.

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/187
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Unify READV usages
Tobias Stoeckmann [Wed, 16 Oct 2024 14:46:00 +0000 (16:46 +0200)] 
libkmod: Unify READV usages

Do not assign variables which are not even used, but merely exist for
the READV macro to work.

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/187
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Use pread where appropriate
Tobias Stoeckmann [Thu, 17 Oct 2024 21:55:06 +0000 (23:55 +0200)] 
libkmod: Use pread where appropriate

Since we do not want to modify the current position in file, use pread
instead of read + lseek. Removes one lseek call per module, which for
depmod on Arch Linux means 6143 calls.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/189
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Fail if ELF cannot be stripped
Tobias Stoeckmann [Fri, 11 Oct 2024 13:37:14 +0000 (15:37 +0200)] 
libkmod: Fail if ELF cannot be stripped

Do not fall back to regular module operations, but keep going if data
which must be stripped is not available.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/176
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotestsuite: update "make rootfs" error message
Emil Velikov [Thu, 17 Oct 2024 17:02:38 +0000 (18:02 +0100)] 
testsuite: update "make rootfs" error message

We have added meson recently, with the goal to remove the make/autotools
one in a release or two. Update the reference to the meson equivalent.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotestsuite/README: update for meson, mention sanitizers
Emil Velikov [Thu, 17 Oct 2024 16:41:58 +0000 (17:41 +0100)] 
testsuite/README: update for meson, mention sanitizers

Mention that running outside of `meson test", one needs to set the env.
aka "source scripts/sanitizer-env.sh".

Also gently discourage using sanitizers alongside gdb and strace. While
thing might work it's not the setup we want to support, I think.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoci: sort the distribution listing
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
ci: sort the distribution listing

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoci: add clang permutation
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
ci: add clang permutation

With the clang issues resolved, let's add it to the CI matrix so fewer
issues get it.

Note: Fedora 40 doesn't ship the shared sanitizer library, while older
Fedora versions did. Fedora 41 will be coming with LLVM 19, which will
have the binary (seemingly with different name :facepalm:).

Let's leave the Fedora/clang infra in and just mask it out sanitizers
for the next month or so, until the new version comes out. Then we can
re-evaluate.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoAdd support for clang sanitizers
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
Add support for clang sanitizers

By default clang uses static sanitizer libraries, which causes build and
test-time failures. Swap for the shared libasan which resolves both.

Note: meson tries to be helpful here, throwing a warning that we should
use -D b_lundef=false which is incorrect in our case.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoEnable sanitizers in build-dev.ini
Emil Velikov [Thu, 17 Oct 2024 16:46:48 +0000 (17:46 +0100)] 
Enable sanitizers in build-dev.ini

With the sanitizers supported in both gcc + clang and all the issues
resolved, let's enable them via build-dev.ini.

This means, developers will see any issues OOTB without having to run
through the CI.

As a nice bonus, let's re-enable them for ubuntu:22.04 - it should be
working fine now.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoscripts/test-wrapper.sh: convert to sanitizer-env.sh
Emil Velikov [Thu, 17 Oct 2024 15:48:13 +0000 (16:48 +0100)] 
scripts/test-wrapper.sh: convert to sanitizer-env.sh

Convert the existing wrapper script, into one that we source to set the
environment aka LD_PRELOAD.

Thus a developer can, use/test/debug the tests without using meson.
Namely:
 - source scripts/sanitizer-env.sh
 - build/testsuite/test-depmod

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: _printf_format_ annotate and adjust ELFDBG modifiers
Emil Velikov [Thu, 17 Oct 2024 18:17:25 +0000 (19:17 +0100)] 
libkmod: _printf_format_ annotate and adjust ELFDBG modifiers

The recently added "always build ELFDBG" patch is already paying
dividends... Clang is flagging a "fmt" is not literal warning.

That's clearly wrong, although without _printf_format_ clang was
struggling to figure things out. With the attribute, it helpfully
flagged that handful of the modifiers are wrong.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoSwap rsync for cp --archive for module sources copying
Emil Velikov [Thu, 17 Oct 2024 20:30:08 +0000 (21:30 +0100)] 
Swap rsync for cp --archive for module sources copying

As Tobias reported, rsync is a bit of heavyweight dependency. We
introduced it, as a replacement for the rm/cp -r previously used.

The rsync was inspired since, unlike make, meson will build all the test
binaries/artefacts even without calling "meson test".

We can go back to cp with --archive (--preserve=timestamps at least),
which will ensure we don't get stale files. To ensure the second run
doesn't copy the source folder as _subfolder_ of the dest we need to
wildcard the copy... Plus we need a proper destination folder in the
first place.

With this, we get a no-op second+ builds - be that with meson or make.
Since the explicit always-dirty state is by design, drop the meson TODO
and document the output variable.

Confirmed by comparing both the `make --debug` output and the execution
times.

Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/192
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomodinfo: Prevent undefined behavior with long keys
Tobias Stoeckmann [Wed, 16 Oct 2024 09:43:47 +0000 (11:43 +0200)] 
modinfo: Prevent undefined behavior with long keys

If a key is longer than INT_MAX, it is possible to trigger a signed
integer overflow. Since this overflow only occurs for formatting,
prevent it by checking if key is longer than 15 characters. If it is,
there is no need to add any more spacing anyway.

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/184
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomodinfo: Prevent out of boundary access
Tobias Stoeckmann [Wed, 16 Oct 2024 09:42:04 +0000 (11:42 +0200)] 
modinfo: Prevent out of boundary access

If a module file contains parameter strings longer than INT_MAX, it is
possible to trigger an out of boundary read with memcmp. Since such a
file is very likely broken or of malicious intent, just consider it
invalid and error out.

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/184
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Add another section size check
Tobias Stoeckmann [Tue, 15 Oct 2024 16:19:32 +0000 (18:19 +0200)] 
libkmod: Add another section size check

Make sure that section is actually large enough to hold a 32 bit value.

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/181
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoAlways define and use ENABLE_ELFDBG
Emil Velikov [Tue, 15 Oct 2024 19:36:50 +0000 (20:36 +0100)] 
Always define and use ENABLE_ELFDBG

Convert the "if defined FOO" pre-processor checks for compiler ones "if
(FOO == 1)".

This makes things easier to reason with and ensures both code-paths are
build-tested. In case, the option is disabled DCE will kick in (assuming
you're not force disabling all optimisations) and remove the respective
code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/173
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoAlways define and use ENABLE_DEBUG
Emil Velikov [Tue, 15 Oct 2024 19:36:50 +0000 (20:36 +0100)] 
Always define and use ENABLE_DEBUG

Convert the "if defined FOO" pre-processor checks for compiler ones "if
(FOO == 1)".

This makes things easier to reason with and ensures both code-paths are
build-tested. In case, the option is disabled DCE will kick in (assuming
you're not force disabling all optimisations) and remove the respective
code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/173
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoAlways define and use ENABLE_LOGGING
Emil Velikov [Tue, 15 Oct 2024 19:36:50 +0000 (20:36 +0100)] 
Always define and use ENABLE_LOGGING

Convert the "if defined FOO" pre-processor checks for compiler ones "if
(FOO == 1)".

This makes things easier to reason with and ensures both code-paths are
build-tested. In case, the option is disabled DCE will kick in (assuming
you're not force disabling all optimisations) and remove the respective
code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/173
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: always include priority in log messages
Emil Velikov [Thu, 3 Oct 2024 16:22:43 +0000 (17:22 +0100)] 
libkmod: always include priority in log messages

One shouldn't need debug messages only to have the priority (emergency,
error, warning ...) properly logged.

With this the libkmod logger aligns with the custom one we use for kmod
tools. The latter was printing the priority since day one.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/173
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomodprobe: Fix error message
Tobias Stoeckmann [Wed, 16 Oct 2024 10:07:24 +0000 (12:07 +0200)] 
modprobe: Fix error message

We try to add from environment, not from command line.

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/185
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Simplify elf_strip_section
Tobias Stoeckmann [Tue, 15 Oct 2024 14:18:55 +0000 (16:18 +0200)] 
libkmod: Simplify elf_strip_section

It is always called with "__versions" as argument, so remove the
argument and rename function accordingly.

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/175
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Remove elf->changed
Tobias Stoeckmann [Fri, 11 Oct 2024 11:40:50 +0000 (13:40 +0200)] 
libkmod: Remove elf->changed

Keep changed ELF data only around as long as necessary. Otherwise it
can happen that subsequent module operations lead to unintuitive
results.

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/175
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotestsuite: fix gcc/libasan.so load order
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
testsuite: fix gcc/libasan.so load order

Currently we silence the ordering warning from libasan, via the
environment: ASAN_OPTIONS=verify_asan_link_order=0...

Instead we should be LD_PRELOAD-ing the library, since otherwise we
might end with miss-matched symbols - one coming from libasan, with the
counter part from the system library.

Plus LD_PRELOAD is the only way to make the clang sanitizers work...
That I have found. Although that's coming with a later patch.

v2:
 - handle when the file is a script

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/179
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotestsuite: preserve the existing LD_PRELOAD
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
testsuite: preserve the existing LD_PRELOAD

In order for the sanitisers to work correctly, we need to LD_PRELOAD the
sanitizer shared library.

So drop the explicit unset(LD_PRELOAD) and instead prepend the existing
value to the LD_PRELOAD path that we construct.

Const annotate the other LD_PRELOAD instance, while we're here.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/179
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoMove sanitizer details into a test wrapper
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
Move sanitizer details into a test wrapper

We want the meson test target to be self contained and having an
essential variables defined in the GitHub CI is heading the opposite
direction.

Create a wrapper that does this for us.

v2:
 - add the script to the autotools tarball/EXTRA_DIST

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/179
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoci: disable sanitizers for ubuntu 22.04
Emil Velikov [Tue, 15 Oct 2024 12:52:07 +0000 (13:52 +0100)] 
ci: disable sanitizers for ubuntu 22.04

It seems that the meson shipped with Ubuntu 22.04 is too old (buggy?) to
set the ASAN_OPTIONS and similar variables. Which means that we don't
have an easy way to detect if the sanitizers are enabled in the upcoming
test wrapper script.

The alternative is to grab newer meson, either via pip or otherwise.
Although considering we have decent coverage via the other distributions
it doesn't seem worth the hassle.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/179
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoci: re-run the test verbosely when on failure
Emil Velikov [Wed, 9 Oct 2024 16:28:32 +0000 (17:28 +0100)] 
ci: re-run the test verbosely when on failure

This will provide us the test log, without having to fiddle with upload
actions. Which is particularly funky since:
 - v4 requires distinct names
 - symbols like : (as in our container name) are not supported

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/179
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: remove no longer used HAVE_DECL___GLIBC__
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
meson: remove no longer used HAVE_DECL___GLIBC__

Earlier commit removed the final user, drop the autotools define yet
forgot the meson one.

Fixes: 0766f541 ("build: check for __xstat declarations")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/179
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoAvoid adding zero to a NULL pointer
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
Avoid adding zero to a NULL pointer

Adding zero to a NULL pointer is undefined behaviour, which is getting
clarified with C23 (or just after) to match our current usage.

With clang 18, this triggers the undefined behaviour sanitizer so add a
check to stay compliant.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoman/insmod: Fix style
Tobias Stoeckmann [Wed, 16 Oct 2024 08:52:28 +0000 (10:52 +0200)] 
man/insmod: Fix style

Add missing newline for better formatting and to stay in sync with other
options.

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/182
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agobuild: add builtin overflow checks to configure.ac
Tobias Stoeckmann [Wed, 16 Oct 2024 09:14:40 +0000 (11:14 +0200)] 
build: add builtin overflow checks to configure.ac

Without these, the build becomes quite noisy and doesn't add builtin
functions even though they exist.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/183
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoman/insmod: minor cosmetic changes
Emil Velikov [Fri, 11 Oct 2024 15:21:42 +0000 (16:21 +0100)] 
man/insmod: minor cosmetic changes

Namely: drop the ellipsis from the man page, to align with --help.

Properly bold modprobe, without the leading space... A reminder from the
xml days.

Reference: https://lore.kernel.org/linux-modules/ZvknyLKvQeBo16n9@meinfjell.helgefjelltest.de
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/177
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoman: remove erroneous " in BUGS section
Emil Velikov [Fri, 11 Oct 2024 15:19:24 +0000 (16:19 +0100)] 
man: remove erroneous " in BUGS section

A silly copy/paste mistake by yours truly (-:

Fixes: ecedc689 ("man: add BUGS section with basic information")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/177
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoman/rmmod: document (how) we handle list of modules
Emil Velikov [Wed, 9 Oct 2024 10:39:52 +0000 (11:39 +0100)] 
man/rmmod: document (how) we handle list of modules

Mention in the help and docs that rmmod operates on list of modules,
alongside its current mode of operation.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/177
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotools/depmod: avoid casting symbol_free() function type
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
tools/depmod: avoid casting symbol_free() function type

With clang 17, -fsanitize=function is enabled alongside any other
sanitizers. Which flags undefined behaviour, since the function type
(argument type really) is not compatible.

Reference: https://reviews.llvm.org/D148827#4422631
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: used unsigned type for INDEX_CHILDMAX and co
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
libkmod: used unsigned type for INDEX_CHILDMAX and co

Currently the define is an signed int of 128, which we store in a char
triggering a clang warning. This is expected since the sign of char is
platform specific.

Convert the macro to unsigned and the respective variables to unsigned
char, alongside the documentation comment.

With that done, adjust the first/last checks so we don't get
tautological-compare warnings from clang.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotools/rmmod: rework control flow
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
tools/rmmod: rework control flow

Currently the control flow we use is a bit tricky:

 - we use a goto within a loop, to avoid one function call
 - we increment r, assuming it cannot wrap around

In practise these are not bugs, although make the code more convoluted
than needed. While in here, scope the local err to where it's used.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotools/insmod: use single control variable
Emil Velikov [Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)] 
tools/insmod: use single control variable

Currently we're returning success, if any of the pre libkmod checks
fail. That's because err is our local variable, while r is the (exit)
resutlt. In practise we don't need the distinction, so just drop the
former.

Reported by clang.

Fixes: ca8f04e8 ("tools/insmod: add syslog and verbose options")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
[ add blank lines, remove extra braces ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agomeson: set ENABLE_{LOGGING,DEBUG} only as needed
Emil Velikov [Thu, 3 Oct 2024 16:22:43 +0000 (17:22 +0100)] 
meson: set ENABLE_{LOGGING,DEBUG} only as needed

With the introduction of the meson build, both ENABLE_LOGGING and
ENABLE_DEBUG have always been set - 1 or 0. Whereas the code relies on
them being set or unset.

Adjust the build accordingly.

Fixes: 370141c1 ("meson: introduce meson, covering libkmod.so")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/173
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoIntroduce and use u{add,mul}sz_overflow() helpers
Emil Velikov [Mon, 30 Sep 2024 21:11:40 +0000 (22:11 +0100)] 
Introduce and use u{add,mul}sz_overflow() helpers

Instead of doing things manually add a few helpers and use them. As a
bonus point, fix the potential overflow in kmod_elf_get_strings().

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/169
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoshared: introduce umul{32,64}_overflow() helpers
Emil Velikov [Mon, 30 Sep 2024 20:35:18 +0000 (21:35 +0100)] 
shared: introduce umul{32,64}_overflow() helpers

We'll use them to implement the size_t variant.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/169
[ Fixup commit message for renamed functions ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoshared: introduce uadd32_overflow() helper
Emil Velikov [Mon, 30 Sep 2024 20:06:14 +0000 (21:06 +0100)] 
shared: introduce uadd32_overflow() helper

We'll use it in the upcoming size_t variant.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/169
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoshared: s/addu64_overflow/uadd64_overflow/g
Emil Velikov [Mon, 30 Sep 2024 21:36:29 +0000 (22:36 +0100)] 
shared: s/addu64_overflow/uadd64_overflow/g

Rename the helper closer to the actual built-in.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/169
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoshared: tweak addu64_overflow() #if/else chain
Emil Velikov [Mon, 30 Sep 2024 19:52:18 +0000 (20:52 +0100)] 
shared: tweak addu64_overflow() #if/else chain

Group the checks as applicable - require the long variant when
sizeof(long) == 8, or the long long one as sizeof(long long) == 8.

Ultimately, fold fallback in the #else path, since it's dead code atm
and seemingly confuses tools such as Coverity.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/169
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: call fnmatch() only as needed
Emil Velikov [Tue, 8 Oct 2024 17:04:34 +0000 (18:04 +0100)] 
libkmod: call fnmatch() only as needed

Currently we'll call the function even when the patterns is an empty
string.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/174
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: use strbuf_pushchars() where possible
Emil Velikov [Tue, 8 Oct 2024 17:04:34 +0000 (18:04 +0100)] 
libkmod: use strbuf_pushchars() where possible

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/174
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agotestsuite/test-strbuf: use const char * for strbuf_str()
Emil Velikov [Tue, 8 Oct 2024 17:04:34 +0000 (18:04 +0100)] 
testsuite/test-strbuf: use const char * for strbuf_str()

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/174
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoci/actions: LC_ALL=C sort the packages
Emil Velikov [Thu, 3 Oct 2024 16:02:45 +0000 (17:02 +0100)] 
ci/actions: LC_ALL=C sort the packages

I'm about to add some more and the current (almost sorted) state breaks
my brain :-x

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agoci: directly use archlinux:multilib-devel container
Emil Velikov [Thu, 3 Oct 2024 16:02:45 +0000 (17:02 +0100)] 
ci: directly use archlinux:multilib-devel container

There was some recent snafu which meant the container wasn't available.
With that resolved, we can drop our hack and use the correct container
directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: silence autological compare warning
Emil Velikov [Thu, 3 Oct 2024 16:02:45 +0000 (17:02 +0100)] 
libkmod: silence autological compare warning

Clang will detect that the enum cannot be zero, thus triggering a
warning. Since this is an external (public API) function, the end-user
can provide any input so we want to keep the check.

Note: include the pragmas in a if defined(__clang__) guard, otherwise
we'll trigger -Wunknown_pragma which will become an error in CI and
developer builds.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>