]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
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
8 months agoci/codeql: use filter-sarif to filter meson-private
Enrico Joerns [Wed, 28 Feb 2024 23:33:30 +0000 (00:33 +0100)] 
ci/codeql: use filter-sarif to filter meson-private

There is a severe number of false-positive in code scanning caused by
inspecting meson-internal test files like
'build/meson-private/tmpzb46osmq/testfile.c'.

As a workaround, use the 'filter-sarif' action to filter out these
results before uploading the SARIF (Static Analysis Results Interchange
Format).

This PR was inspired by https://github.com/rauc/rauc/pull/1346 and the
example from https://github.com/advanced-security/filter-sarif.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
[Emil: port from rauc, use checksums for actions]
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/249
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agodepmod: Properly check index keys
Tobias Stoeckmann [Fri, 15 Nov 2024 17:22:45 +0000 (18:22 +0100)] 
depmod: Properly check index keys

Synchronize character checks with libkmod-index.c. 8-bit ASCII chars
would turn negative (due to signed char), which index__checkstring does
not properly check for.

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/247
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoci: add meson setup -D {distconf,module}dir=relative/ checks
Emil Velikov [Fri, 15 Nov 2024 15:27:26 +0000 (15:27 +0000)] 
ci: add meson setup -D {distconf,module}dir=relative/ checks

Based on the autotools build, meson does not support relative
directories for distconfig and moduledir. We fixed that recently, but
never added a check so we don't regress.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/245
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Fix file error handling regression
Tobias Stoeckmann [Wed, 13 Nov 2024 22:32:55 +0000 (23:32 +0100)] 
libkmod: Fix file error handling regression

The propagation of errors from loading function through errno must make
sure that errno is positive, otherwise errors are not correctly spotted.

Fixes: 81e5c797 ("libkmod: propagate {zstd,xz,zlib}_load errors")
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/242
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Fix typo in comment
Tobias Stoeckmann [Wed, 13 Nov 2024 18:43:48 +0000 (19:43 +0100)] 
libkmod: Fix typo in comment

The word practise only exists in British English and is a verb.
Switch to practice and adjust style.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/241
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Improve index comment
Tobias Stoeckmann [Wed, 13 Nov 2024 18:41:04 +0000 (19:41 +0100)] 
libkmod: Improve index comment

In version 1 of kmod, definitions of INDEX_MAGIC_OLD and INDEX_MAGIC
were in two adjacent lines, which made the sentence starting with
"Second one" much easier to read.

Since the "second one" is actually INDEX_MAGIC and even kmod version 1
did use it, let's not talk about "newer versioned binary files" anymore
but clearly state that 0xB007FA57 is deprecated.

Also add a missing full stop.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
Link: https://github.com/kmod-project/kmod/pull/241
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Do not set errno in libkmod-index
Max Kunzelmann [Tue, 12 Nov 2024 21:49:41 +0000 (22:49 +0100)] 
libkmod: Do not set errno in libkmod-index

Don't set errno in read functions ad it's a libc interface which we
should not be overriding. None of the functions up the call stack (some
examples) check on it.

Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
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/240
[ Reword commit message according to suggestion by Emil and remove
  inline ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoRemove scratchbuf implementation
Lucas De Marchi [Tue, 12 Nov 2024 20:31:36 +0000 (14:31 -0600)] 
Remove scratchbuf implementation

All its unique features have been ported to strbuf and users converted.
Nuke it.

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/239
8 months agodepmod: Convert output_symbols_bin() to strbuf
Lucas De Marchi [Tue, 12 Nov 2024 20:26:56 +0000 (14:26 -0600)] 
depmod: Convert output_symbols_bin() to strbuf

Remove last use of scratchbuf.

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/239
8 months agodepmod: Convert depmod_modules_search_path() to strbuf
Lucas De Marchi [Tue, 12 Nov 2024 20:07:32 +0000 (14:07 -0600)] 
depmod: Convert depmod_modules_search_path() to strbuf

Replace the scratchbuf usage with corresponding API from strbuf.

depmod_modules_search_path() itself may further be simplified in the
future to share opening the dir with depmod_modules_search_dir(),
but that is left for later.

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/239
8 months agostrbuf: Add strbuf_shrink_to()
Lucas De Marchi [Thu, 14 Nov 2024 05:02:07 +0000 (23:02 -0600)] 
strbuf: Add strbuf_shrink_to()

Useful when working with paths on a loop and resetting to a base path
component on every loop iteration.

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/239
8 months agostrbuf: Add strbuf_used()
Lucas De Marchi [Thu, 14 Nov 2024 04:49:52 +0000 (22:49 -0600)] 
strbuf: Add strbuf_used()

So users don't feel tempted to look at inside the strbuf. Just add a
function for it and proper tests.

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/239
8 months agostrbuf: Add strbuf_pushmem()
Lucas De Marchi [Tue, 12 Nov 2024 19:45:33 +0000 (13:45 -0600)] 
strbuf: Add strbuf_pushmem()

Wrapper for memcpy(). It's similar to strbuf_pushchars(), but push any
char, including the NUL byte, relying on the size passed as 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/239
8 months agostrbuf: Do not append '\0' if not needed
Lucas De Marchi [Tue, 12 Nov 2024 19:43:20 +0000 (13:43 -0600)] 
strbuf: Do not append '\0' if not needed

Unconditionally appending '\0' is not a big problem, but that does
trigger the buffer to potentially be re-allocated. Avoid that by
checking the last char is not already NUL.

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/239
8 months agostrbuf: Add strbuf_reserve_extra()
Lucas De Marchi [Tue, 12 Nov 2024 18:07:39 +0000 (12:07 -0600)] 
strbuf: Add strbuf_reserve_extra()

To accomplish the same task as scratchbuf_alloc() does: make sure the
buffer has enough space for next operations. One difference is that
ensures **extra** space, not the total space. If needed in future,
a strbuf_reserve(), that resembles C++'s std::vector::reserve(), can be
added on top.

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/239
8 months agostrbuf: Allow to start with stack space
Lucas De Marchi [Tue, 12 Nov 2024 16:09:38 +0000 (10:09 -0600)] 
strbuf: Allow to start with stack space

This is the main functionality of the scratchbuf implementation: it
starts with a buffer on stack that covers most of the calls, but also
has a fallback to allocate the buffer if it grows beyond the initial
size.

Port that functionality from scratchbuf to strbuf, so the former can be
eventually removed.

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/239
8 months agostrbuf: Invalidate (only) when stolen
Lucas De Marchi [Tue, 12 Nov 2024 15:34:58 +0000 (09:34 -0600)] 
strbuf: Invalidate (only) when stolen

The main for strbuf_steal() to free() on error was to allow the caller
to pass the NULL up the stack with just a return call to
strbuf_steal().

However this is error-prone and surprising that the buffer is still
invalidated on error. Provide an strbuf cleanup attribute that can be
used for the same purpose and make sure that when the string is stolen,
it's set to NULL, so there's no dangling pointer around.

Since we run the  testsuite with AddressSanitizer, a simple test can be
added to make sure the stolen string becomes valid when the attribute is
used.

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/239
8 months agostrbuf: Document strbuf_popchar(s)
Lucas De Marchi [Tue, 12 Nov 2024 15:25:52 +0000 (09:25 -0600)] 
strbuf: Document strbuf_popchar(s)

Document the behavior for these functions and also clarify why the
testsuite can check the buffer for equality after calling strbuf_str().

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/239
8 months agostrbuf: Re-use buf_realloc()
Lucas De Marchi [Tue, 12 Nov 2024 15:07:05 +0000 (09:07 -0600)] 
strbuf: Re-use buf_realloc()

Let the realloc happen in only one place, so we can change its behavior
in future.

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/239
8 months agostrbuf: Extract realloc
Lucas De Marchi [Tue, 12 Nov 2024 14:36:54 +0000 (08:36 -0600)] 
strbuf: Extract realloc

Extract the realloc from the size calculation so it can be shared with
other upcoming callers.

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/239
8 months agolibkmod: Release memory on error paths
Tobias Stoeckmann [Tue, 5 Nov 2024 17:17:50 +0000 (18:17 +0100)] 
libkmod: Release memory on error paths

Do not override pointers to first list nodes if appending failed,
otherwise it's impossible to release already existing nodes of these
lists afterwards.

Remove the now unused function kmod_list_remove_n_latest as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agodepmod: Release memory on error path
Tobias Stoeckmann [Wed, 6 Nov 2024 16:50:27 +0000 (17:50 +0100)] 
depmod: Release memory on error path

Check malloc return value and clean up resources if allocation fails.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agodepmod: Release memory on error paths
Tobias Stoeckmann [Tue, 5 Nov 2024 16:58:15 +0000 (17:58 +0100)] 
depmod: Release memory on error paths

If a list node could not be added, release already allocated data which
was supposed to end up in list.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Introduce kmod_list_release
Tobias Stoeckmann [Tue, 5 Nov 2024 16:47:02 +0000 (17:47 +0100)] 
libkmod: Introduce kmod_list_release

Add a macro to reduce amount of explicit while-loops for removal of
nodes and release of their associated data in code base.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: store common section off/size and use them
Emil Velikov [Wed, 23 Oct 2024 23:27:08 +0000 (00:27 +0100)] 
libkmod: store common section off/size and use them

Currently, we repeatedly loop over the elf headers looking for five well
known sections. Just do it once in kmod_elf_new() and reuse the data as
needed.

Note that not all sections are guaranteed to be available, so check and
ELFDBG print the ones which are missing.

v2: quit looping when found, ELFDBG print missing sections
v3: match the first section name, use a loop

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: rename kmod_elf_get_strings()
Emil Velikov [Wed, 23 Oct 2024 23:37:31 +0000 (00:37 +0100)] 
libkmod: rename kmod_elf_get_strings()

Rename kmod_elf_get_strings() to kmod_elf_get_modinfo_strings() and fold
the section name within, instead of passing it as an argument.

This aligns better with the other kmod_elf function names and will allow
us to tweak the kmod_elf_get_section() handling with later commit.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: stop copying symbol names in kmod_elf_get_dependency_symbols()
Emil Velikov [Wed, 23 Oct 2024 16:19:53 +0000 (17:19 +0100)] 
libkmod: stop copying symbol names in kmod_elf_get_dependency_symbols()

Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: stop copying symbol names in kmod_elf_get_symbols()
Emil Velikov [Wed, 23 Oct 2024 16:19:53 +0000 (17:19 +0100)] 
libkmod: stop copying symbol names in kmod_elf_get_symbols()

Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: stop copying symbol names in kmod_elf_get_symbols_symtab()
Emil Velikov [Wed, 23 Oct 2024 16:19:53 +0000 (17:19 +0100)] 
libkmod: stop copying symbol names in kmod_elf_get_symbols_symtab()

Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: check for trailing \0 in __ksymtab_strings
Emil Velikov [Thu, 24 Oct 2024 22:18:28 +0000 (23:18 +0100)] 
libkmod: check for trailing \0 in __ksymtab_strings

As per the documentation (man 5 elf) the section must be null
terminated. Move the check further up and remove the no longer needed
code trying to workaround non-compliant instances.

Note: drop the erroneous +1 in the overflow (malloc size) calculation

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: stop copying symbol names in kmod_elf_get_modversions()
Emil Velikov [Wed, 23 Oct 2024 16:19:53 +0000 (17:19 +0100)] 
libkmod: stop copying symbol names in kmod_elf_get_modversions()

Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: const annotate kmod_modversion::symbol
Emil Velikov [Wed, 23 Oct 2024 22:11:27 +0000 (23:11 +0100)] 
libkmod: const annotate kmod_modversion::symbol

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agodepmod: Remove a malloc call
Emil Velikov [Thu, 17 Oct 2024 13:53:03 +0000 (15:53 +0200)] 
depmod: Remove a malloc call

The offsets of node children can be stored on stack.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/188
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agodepmod: Write index in pre-order
Tobias Stoeckmann [Wed, 16 Oct 2024 19:38:04 +0000 (21:38 +0200)] 
depmod: Write index in pre-order

Index files in pre-order have a significant performance improvement
for libkmod users.

On Arch Linux system, dumping configuration takes 296 read calls
in pre-order, compared to 4080 in post-order. Tests on a Raspberry
Pi 2 test system have shown an improvement by 9 %.

Even writing is faster now. This happens because we must know in
advance how many bytes index nodes will consume in the resulting file.
Although this code calculates it on the fly and caches the results,
saving lseek system calls has a significant positive effect which
compensates this extra overhead.

On Arch Linux system, writing index takes 6143 lseek calls now, compared
to previous 83701, leading to a performance gain of 13 %.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/188
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agomeson: undefine NDEBUG in the tests
Emil Velikov [Mon, 11 Nov 2024 13:08:20 +0000 (13:08 +0000)] 
meson: undefine NDEBUG in the tests

When using -D b_ndebug=true or inheriting CFLAGS="-DNDEBUG" from the
environment, the asserts will be no-op thus the checks in the
LD_PRELOADED libraries will be omitted.

Explicitly undefine the macro, so we don't accidentally shoot ourselves
in the foot.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/238
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoci: bump the all-actions group across 1 directory with 3 updates
dependabot[bot] [Fri, 8 Nov 2024 17:55:23 +0000 (17:55 +0000)] 
ci: bump the all-actions group across 1 directory with 3 updates

Bumps the all-actions group with 3 updates in the / directory: [actions/checkout](https://github.com/actions/checkout), [yshui/git-clang-format-lint](https://github.com/yshui/git-clang-format-lint) and [github/codeql-action](https://github.com/github/codeql-action).

Updates `actions/checkout` from 4.1.7 to 4.2.2
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/692973e3d937129bcbf40652eb9f2f61becf3332...11bd71901bbe5b1630ceea73d27597364c9af683)

Updates `yshui/git-clang-format-lint` from 1.16 to 1.17
- [Release notes](https://github.com/yshui/git-clang-format-lint/releases)
- [Commits](https://github.com/yshui/git-clang-format-lint/compare/a65b466f5903524aef27552f63c3906c0f73f184...27f3890c6655216edadcc2759110b9c127c74786)

Updates `github/codeql-action` from 3.26.7 to 3.27.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/8214744c546c1e5c8f03dde8fab3a7353211988d...4f3212b61783c3c68e8309a0f18a699764811cda)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
- dependency-name: yshui/git-clang-format-lint
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Link: https://github.com/kmod-project/kmod/pull/237
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Fix overflow in kmod_module_hex_to_str
Tobias Stoeckmann [Fri, 8 Nov 2024 16:08:41 +0000 (17:08 +0100)] 
libkmod: Fix overflow in kmod_module_hex_to_str

If an overly long signature is found in a module file, it is possible to
trigger an out of boundary write in kmod_module_hex_to_str due to
integer and subsequent heap buffer overflow.

This approach replaces malloc + sprintf with a simple hex-lookup and a
strbuf approach, being slightly faster in real life scenarios while
adding around 100 bytes to library size. A much faster approach could be
done without strbuf and using our overflow check functions, but
readability should win here.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/236
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Avoid overflows while parsing files
Tobias Stoeckmann [Thu, 7 Nov 2024 20:24:35 +0000 (21:24 +0100)] 
libkmod: Avoid overflows while parsing files

Specially crafted files could overflow internal counters, allowing out of
boundary writes. Make sure that neither counters nor resulting calculations
overflow.

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/234
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agotree-wide: Sprinkle _clang_suppress_alloc_
Lucas De Marchi [Mon, 11 Nov 2024 15:04:44 +0000 (09:04 -0600)] 
tree-wide: Sprinkle _clang_suppress_alloc_

Add the clang::suppress attribute to places where allocation is done and
that rely on the cleanup attribute. Clang analyzer doesn't handle those
(yet), so keep it from giving us false positive.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
8 months agolibkmod: Simplify lookup_builtin_file()
Lucas De Marchi [Thu, 7 Nov 2024 20:26:39 +0000 (14:26 -0600)] 
libkmod: Simplify lookup_builtin_file()

Use cleanup attribute.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
8 months agoshared: Ignore clang-analyzer on cleanup attribute
Lucas De Marchi [Sat, 9 Nov 2024 22:53:22 +0000 (16:53 -0600)] 
shared: Ignore clang-analyzer on cleanup attribute

When using the cleanup attribute we know we are not leaking that
allocation. Most of the time the assignment is together with the
declaration, so we can simplify additional clang annotations by making
the cleanup attribute imply clang::suppress.

In cases declaration and assignment are not together, provide
_clang_suppress_alloc_ to annotate the code. That is only defined for
clang analyzer.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
8 months agobuild: Stop warning for attribute clang::suppress
Lucas De Marchi [Sat, 9 Nov 2024 22:23:02 +0000 (16:23 -0600)] 
build: Stop warning for attribute clang::suppress

That attribute allows us to instruct the Clang Static Analyzer to stop
giving some false positives. However when building the code (with gcc
and clang) they warn that the attribute is ignored. Just ignore as we
know what the attribute is for.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
8 months agoshared: Move cleanup attribute
Lucas De Marchi [Sat, 9 Nov 2024 22:20:18 +0000 (16:20 -0600)] 
shared: Move cleanup attribute

Move to macro.h where other attributes are located. The inline helper
function can also move along as we don't need to keep it separate.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
8 months agoman: add modprobe.conf.5 manpage link
Emil Velikov [Thu, 7 Nov 2024 15:44:30 +0000 (15:44 +0000)] 
man: add modprobe.conf.5 manpage link

Seemingly Fedora and friends have been carrying this one for years. Just
add it to kmod itself so that people using multiple distros have
consistent experience.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/231
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agomeson: install the configuration directories
Emil Velikov [Thu, 7 Nov 2024 15:28:28 +0000 (15:28 +0000)] 
meson: install the configuration directories

Install the /{etc,usr/lib}/{depmod,modprobe}.d/ configuration
directories as part of out install action.

Currently a handful of distros (Debian, Gentoo, Fedora, Arch) do that
manually, where we can have it in the upstream project instead.

As a pie in the sky idea, in the future we may choose to enforce
particular permissions, ownership, etc and this should make it a little
less fragile across the ecosystem.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/231
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agomeson.build: install kmod symlinks to /usr/sbin/
Emil Velikov [Thu, 7 Nov 2024 14:17:28 +0000 (14:17 +0000)] 
meson.build: install kmod symlinks to /usr/sbin/

With earlier commit we added support for kmod itself to install the
symlinks to kmod. While it works across the board, some distributions
still support (to varying degree) split /usr/bin and /usr/sbin.

This commit changes the location where those are created and bears no
functional change for merged bin-sbin users. While for split ones, it
follows what distributions are doing to a varying extend:

 - Fedora, Alpine - this commit matches exactly what they do
 - Debian, Yocto - they have an extra /bin/lsmod -> ../sbin/kmod symlink
 - Gentoo - as Debian plus an extra /bin/modinfo -> ../sbin/kmod symlink

Loosely based on a Debian patch by Marco d'Itri.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/231
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoci: add coreutils to Alpine
Emil Velikov [Mon, 11 Nov 2024 17:02:39 +0000 (17:02 +0000)] 
ci: add coreutils to Alpine

The buxybox version of ln supports only the short options and does not
support -r/--relative.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/231
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoci: add code coverage via Codecov
Emil Velikov [Tue, 5 Nov 2024 15:07:34 +0000 (15:07 +0000)] 
ci: add code coverage via Codecov

Add a simple code coverage pipeline based on the CodeQL one.

Should give us pretty reports in the PRs and web UI with the results. We
can consider having HTML reports on our website (once it's up that is)
in addition or instead of at a future point.

Closes: https://github.com/kmod-project/kmod/issues/61
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/229
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoRevert "testsuite/path: match the full rootpath"
Emil Velikov [Tue, 5 Nov 2024 00:25:39 +0000 (00:25 +0000)] 
Revert "testsuite/path: match the full rootpath"

This reverts commit ae0c0c4c89f60fd379133f46b10c37686eef0c6c.

The commit reasoning was correct, but did not consider the case where
other third-party files are created. Namely: when generating the code
coverage files.

Thus the gcna files were created in $test_rootdir/$abs_top_builddir
which meant they won't get picked when the coverage info/xml/html files
were created and the statistics reported were quite wrong.

Revert the commit and add an inline comment, so we don't feel tempted to
change it in the future.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/229
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoci/codeql: use Ubuntu 24.04, adjust build flags
Emil Velikov [Tue, 5 Nov 2024 16:22:16 +0000 (16:22 +0000)] 
ci/codeql: use Ubuntu 24.04, adjust build flags

While in here drop the docs and manpages flags - both of those combined
take ~1s of CI time - and disable the sanitizers and tests instead.

This means we no longer get pre-existing code problems in the tests,
which is fine considering the number of pre-existing issues in there.
Another nice side effect is that the pipeline time is reduced by ~50%.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/229
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agobuild: Drop define not picked by meson
Lucas De Marchi [Thu, 7 Nov 2024 17:13:11 +0000 (11:13 -0600)] 
build: Drop define not picked by meson

For almost 13 years, since commit 769becb5dbfb ("tools: kmod: Add
handling of compat modinfo") we have a non-spoken joke in the build
system showing "-DANOTHER_BRICK_IN_THE -Wall" in honour of the famous
Pink Floyd song.

With configure flags now being sorted, I'm looking at the logs and
seeing: "-DANOTHER_BRICK_IN_THE -fdata-sections". That makes no sense.
Also the new meson build system did not join the joke. Not fun. Let's
drop it and let this commit serve as recognition of what it was.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/226
8 months agobuild: alpha sort the compiler flags
Emil Velikov [Mon, 4 Nov 2024 19:01:35 +0000 (19:01 +0000)] 
build: alpha sort the compiler flags

Pipe the lot through sort so one can reasonably search, add, edit
without going crazy.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/226
8 months agobuild: remove no longer needed -Wno flags
Emil Velikov [Mon, 4 Nov 2024 18:55:48 +0000 (18:55 +0000)] 
build: remove no longer needed -Wno flags

Nearly all the -Wno flags are not applicable any more - remove them.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/226
8 months agoci: Fix debian/ubuntu installation
Lucas De Marchi [Thu, 7 Nov 2024 20:39:08 +0000 (14:39 -0600)] 
ci: Fix debian/ubuntu installation

Make sure we are running in non-interactive mode and that we don't get
blocked on tzdata update.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/235
8 months agodepmod: Check fstatat return value
Tobias Stoeckmann [Wed, 6 Nov 2024 21:22:35 +0000 (22:22 +0100)] 
depmod: Check fstatat return value

If fstatat fails, do not access the uninitialized variable st.
Instead, filter the file out.

Basically synchronization with libkmod's conf_files_filter_out.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/230
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Prevent ouf of boundary access
Tobias Stoeckmann [Tue, 5 Nov 2024 16:17:57 +0000 (17:17 +0100)] 
libkmod: Prevent ouf of boundary access

Do not access memory out of bounds if the first character read by fgets
is NUL. Treat such a character as EOL instead. This is a purely
defensive measure since /proc/modules should normaly not contain such
characters.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/227
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: const struct index_mm as applicable
Emil Velikov [Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)] 
libkmod: const struct index_mm as applicable

The index_mm_{search,read,dump}* API does not mutate the index_mm
struct. So let's annotate it as constant.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: return bool from lookup_builtin_file()
Emil Velikov [Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)] 
libkmod: return bool from lookup_builtin_file()

The callers are interested if the file is within the list of builtins or
not. So change the return type and push the free() down the stack.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: factor out index_{mm_,}search based lookup
Emil Velikov [Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)] 
libkmod: factor out index_{mm_,}search based lookup

Create a simple helper and reuse it instead of duplicating code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: inline _idx_empty_str
Emil Velikov [Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)] 
libkmod: inline _idx_empty_str

The compiler already creates an empty string as applicable, drop the
extra variable.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: convert index_{,mm_}value to uint32_t ...
Emil Velikov [Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)] 
libkmod: convert index_{,mm_}value to uint32_t ...

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: pass bool alias_prefix to index_{,mm_}dump()
Emil Velikov [Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)] 
libkmod: pass bool alias_prefix to index_{,mm_}dump()

As seen with previous commit, the way we pass an empty string to
index_{,mm_}dump() is very error prone.

Swap that with a bool, which makes things a lot more obvious.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: fix dumps for non-alias indexes
Emil Velikov [Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)] 
libkmod: fix dumps for non-alias indexes

For non-alias indexes prefix is an empty string, where
strbuf_pushchars() returns the number of characters added to the strbuf.

Since those are zero, we end up completely skipping the dump process.

Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Fixes: 889d02b1 ("libkmod: check strbuf return values")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Validate symbol names in ELF files
Tobias Stoeckmann [Fri, 1 Nov 2024 21:50:08 +0000 (22:50 +0100)] 
libkmod: Validate symbol names in ELF files

Make sure that symbol names in ELF files are actually NUL terminated.

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/222
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Unify crclen calculation in ELF parser
Tobias Stoeckmann [Fri, 1 Nov 2024 21:42:11 +0000 (22:42 +0100)] 
libkmod: Unify crclen calculation in ELF parser

Whenever sizeof(mv->crc) is used, it's called crclen, not offcrc.
Move retrieval of field sizes into its own function.
Prepare this as a cleanup for easier auditing.

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/222
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoREADME: Add release/distro/end-user recommendation
Lucas De Marchi [Fri, 1 Nov 2024 20:04:30 +0000 (15:04 -0500)] 
README: Add release/distro/end-user recommendation

This may be useful for anyone trying a non-debug build and serve as
baseline for distros. Even for developers, when benchmarking kmod, it's
better to run a release-oriented kmod rather than the slow one due to
all debug/sanitizers.

By keeping the -D in the command line rather than in a ini file,
we also guarantee meson shows it in the summary, regardless of
https://github.com/mesonbuild/meson/issues/13865.

Closes: https://github.com/kmod-project/kmod/issues/220
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/221
8 months agoREADME: Let autotools follow the same steps as meson
Lucas De Marchi [Fri, 1 Nov 2024 20:03:33 +0000 (15:03 -0500)] 
README: Let autotools follow the same steps as meson

For meson it's configure & build & install in the same snippet.
Do the same for autotools.

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/221
8 months agoci: re-enable sanitizers with Fedora 41
Emil Velikov [Fri, 1 Nov 2024 13:03:46 +0000 (13:03 +0000)] 
ci: re-enable sanitizers with Fedora 41

We had the sanitizers disabled on Fedora 40, since the shared library
sanitizers comings with clang were not packaged. With Fedora 41 that has
changed, so let's try re-enabling them.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoscripts/sanitizer-env.sh: support new clang 19 DSO
Emil Velikov [Fri, 1 Nov 2024 13:32:07 +0000 (13:32 +0000)] 
scripts/sanitizer-env.sh: support new clang 19 DSO

Seemingly with version 19, the CPU arch was dropped from the DSO name.
Try that and fallback to the old one, as applicable.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoscripts/sanitizer-env.sh: check and warn if OUR_PRELOAD is not a file
Emil Velikov [Fri, 1 Nov 2024 13:37:47 +0000 (13:37 +0000)] 
scripts/sanitizer-env.sh: check and warn if OUR_PRELOAD is not a file

As seen with the upcoming clang 19 change, the library name has changed.
Enhance the current test to check if the compiler provided string is a
file and produce a warning with some handy tips when that's not the
case.

v2:
 - convert to heredoc
 - output to stderr

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoscripts/sanitizer-env.sh: promote unknown compiler to warning/stderr
Emil Velikov [Mon, 4 Nov 2024 13:54:56 +0000 (13:54 +0000)] 
scripts/sanitizer-env.sh: promote unknown compiler to warning/stderr

Should make it more distinguishable, depending on shell and/or CI setup,
from the informational message.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoscripts/sanitizer-env.sh: convert to heredoc
Emil Velikov [Mon, 4 Nov 2024 13:45:17 +0000 (13:45 +0000)] 
scripts/sanitizer-env.sh: convert to heredoc

Convert to heredoc and add leading/trailing blank lines so it stands out
from the rest. It makes for cleaner reading experience both of the
script itself and its output.

As suggested by Lucas.

v2:
 - don't escape ", drop spurious instance

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/219
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agomeson: s/modulesi/modules/ typo
Emil Velikov [Thu, 7 Nov 2024 15:14:14 +0000 (15:14 +0000)] 
meson: s/modulesi/modules/ typo

Fix the typo in the option description.

Reported-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/225
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agoREADME.md: adjust the optional dependency note
Emil Velikov [Mon, 4 Nov 2024 18:45:52 +0000 (18:45 +0000)] 
README.md: adjust the optional dependency note

With last commit we've default-enabled a few options. So the optional
dependencies become required now.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/225
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agomeson: default enable compression and openssl
Emil Velikov [Mon, 4 Nov 2024 18:40:51 +0000 (18:40 +0000)] 
meson: default enable compression and openssl

The default for the compressions and openssl is based on the autotools
build ones. With the initial goal to make migration as easy as possible
- identical option names, help messages, defaults...

Although a bunch of these have changed already, plus we want builders to
get support for compressed/signed modules out of the box.

So let's flip the defaults - everyone is welcome to adjust those when
calling `meson setup -D foo=bar`.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/225
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agolibkmod: Fix typo in comment
Tobias Stoeckmann [Sat, 2 Nov 2024 11:05:16 +0000 (12:05 +0100)] 
libkmod: Fix typo in comment

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/223
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agomeson: don't escape module_foo in kmod.pc
Emil Velikov [Thu, 31 Oct 2024 13:16:37 +0000 (13:16 +0000)] 
meson: don't escape module_foo in kmod.pc

The kmod.pc file, contains module_signatures and module_compressions
space-separated lists, indicating how kmod is built. For the meson
generated file, any spaces are escaped where the autotools one does not
do that.

Update the meson build to be consistent with the original autotools one
and omit the escaping that we don't want.

Aside: seems like autotools does not escape the directory variables
either, so if the path(s) have any spaces in them pkg-config (pkgconf at
least) produces rubbish, quite rightfully IMHO.

Eg.
  $ cat .../autotools-file.pc
  prefix=/usr
  includedir=${prefix}/include bar
  Cflags: -I${includedir}
  ...
  $ pkg-config --cflags autotools-file.pc
  bar

  $ cat .../meson-file.pc
  prefix=/usr
  includedir=${prefix}/include\ bar
  Cflags: -I${includedir}
  ...
  $ pkg-config --cflags meson-file.pc
  -I/usr/include\ bar

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/217
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
8 months agomeson: align default distconfdir with autotools
Emil Velikov [Wed, 30 Oct 2024 17:00:28 +0000 (17:00 +0000)] 
meson: align default distconfdir with autotools

Autotools uses $prefix/lib as the default for distconfdir, while meson
$libdir - which is not guaranteed to be the same.

In particular: Debian and derivatives use /usr/lib/$target-triplet as a
$libdir, while still keep the configuration directory as /usr/lib.

Fixes: 370141c1 ("meson: introduce meson, covering libkmod.so")
Reported-by: Marco d'Itri <md@linux.it>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/216
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Properly skip first symbol entry
Tobias Stoeckmann [Tue, 29 Oct 2024 16:45:01 +0000 (17:45 +0100)] 
libkmod: Properly skip first symbol entry

This fixes a regression introduced while converting pointer to
offset arithmetics.

The for-loop itself starts at 1 already, so reflect this with the
manually performed offset + length calculation right at the start.

Closes: https://github.com/kmod-project/kmod/issues/214
Fixes: 25ab561b ("libkmod: Use ELF offsets more often")
Reported-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/215
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
9 months agolibkmod: Unify kmod_module_new_from_* functions
Tobias Stoeckmann [Thu, 24 Oct 2024 19:09:53 +0000 (21:09 +0200)] 
libkmod: Unify kmod_module_new_from_* functions

Return result of kmod_module_new directly in kmod_module_new_from_alias
so this function handles return values like the others.

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: Clean up all dependencies on error path
Tobias Stoeckmann [Thu, 24 Oct 2024 19:07:44 +0000 (21:07 +0200)] 
libkmod: Clean up all dependencies on error path

If kmod_module_parse_depline runs out of memory, it is possible
that not all dependency modules are unlinked.

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: Clarify function signature
Tobias Stoeckmann [Thu, 24 Oct 2024 19:04:28 +0000 (21:04 +0200)] 
libkmod: Clarify function signature

The module_get_dependencies_noref function may modify content of
given kmod_module struct, so clarify this fact.

Actually we would have to adjust kmod API for total clarification,
but let's start with internally used functions first.

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: 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