Lucas De Marchi [Thu, 3 Apr 2025 04:17:27 +0000 (23:17 -0500)]
depmod: Fix possible 0 return on error
errno may be long overwritten at this point and doesn't mean much on a
return from the cb(). Just replace with the same error we are output on
the log.
Lucas De Marchi [Thu, 3 Apr 2025 04:39:17 +0000 (23:39 -0500)]
tmpfile-util: Drop libgen.h
We don't want the version of basename() that may leak memory - we want
the sane one. I remembered to add the missing.h while editing commit aae48bc9f73a ("depmod: add tmpfile-util to generate temporary file") to
merge it, but completely forgot to remove the libgen.h. Fix it now.
Fixes: aae48bc9f73a ("depmod: add tmpfile-util to generate temporary file") 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/335
Wang, Wenjie2 [Wed, 19 Mar 2025 01:54:08 +0000 (01:54 +0000)]
depmod: add tmpfile-util to generate temporary file
* we use `mkstemp` to create the temporary file since it's a general
function in linux system and O_TMPFILE is not supported on all linux
system.
* add `struct tmpfile` to keep the `dirfd`, temp file `fd` and the
filename.
Co-developed-by: Wenjie Wang <wenjie2.wang@intel.com> Signed-off-by: Wenjie Wang <wenjie2.wang@intel.com> Co-developed-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Dan He <dan.h.he@intel.com> Signed-off-by: Qingqing Li <qingqing.li@intel.com> Signed-off-by: Yuchi Chen <yuchi.chen@intel.com> Link: https://github.com/kmod-project/kmod/pull/305 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
He Dan [Fri, 28 Mar 2025 15:06:13 +0000 (23:06 +0800)]
Remove the softdep modinfo in the modules mod-softdep-a and mod-softdep-b
Since the soft dependencies are defined in modprobe config, we do not
have to add those info in the modinfo section of the modules.
Co-developed-by: Dan He <dan.h.he@intel.com> Signed-off-by: Dan He <dan.h.he@intel.com> Co-developed-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Yuchi Chen <yuchi.chen@intel.com> Signed-off-by: Wenjie Wang <wenjie2.wang@intel.com> Signed-off-by: Qingqing Li <qingqing.li@intel.com> Signed-off-by: He Dan <dan.h.he@intel.com> Link: https://github.com/kmod-project/kmod/pull/311 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Gongjun Song [Fri, 7 Mar 2025 15:03:18 +0000 (23:03 +0800)]
Added the test case of using multiple softdep for a module
We defined two modules mod-softdep-a and mod-softdep-b. The softdep
statements are split into two separate modprobe configure files.
The unit test case is supposed to fail, since the libkmod will take
only the first softdep statement based on the current implementation.
Co-developed-by: Dan He <dan.h.he@intel.com> Signed-off-by: Dan He <dan.h.he@intel.com> Co-developed-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Yuchi Chen <yuchi.chen@intel.com> Signed-off-by: Wenjie Wang <wenjie2.wang@intel.com> Signed-off-by: Qingqing Li <qingqing.li@intel.com> Link: https://github.com/kmod-project/kmod/pull/311 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
a6f9cd0 ("tools/rmmod: consistently use ERR logging facility") fixed
the split between syslog and stderr of various error message substrings
by calling the ERR macro instead of writing directly to stderr, but in
doing so also completely mangled the output because the ERR macro
decorates its arguments:
$ rmmod iwlwifi
rmmod: ERROR: Module iwlwifi is in use by:rmmod: ERROR: iwlmvmrmmod: ERROR:
And in syslog:
$ rmmod -s iwlwifi
2025-03-24T17:22:34.878318+01:00 mangolassi rmmod: ERROR: Module iwlwifi is in use by:
2025-03-24T17:22:34.889145+01:00 mangolassi rmmod: ERROR: iwlmvm
2025-03-24T17:22:34.889224+01:00 mangolassi rmmod: ERROR:
This commit fixes that by building the holder names list with a strbuf
and then passes the whole thing at once to ERR.
Emil Velikov [Tue, 11 Mar 2025 14:32:37 +0000 (14:32 +0000)]
ci/main: alpha sort distributions/variants
Fixes: ae7b0c30 ("ci: Test with Debian bullseye") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/322 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Tue, 11 Mar 2025 12:26:07 +0000 (12:26 +0000)]
tools: use space for long opts
The getopt_long() API handles both space and = separated long options
just fine. On the other hand, supporting both in the shell completions
means that we'll have to quadruple them in terms of size/complexity.
So let's try to keep things simple and consistent, by recommending only
the space variant.
Make sure to update both the tools' --help and the respective man pages.
Jakub Ślepecki [Fri, 21 Mar 2025 10:41:35 +0000 (10:41 +0000)]
libkmod: fix buffer-overflow in weakdep_to_char
modprobe -c with any sample weakdep command in modprobe.d will overflow
memcpy due to size calculation not incorporating trailing null byte,
for example:
==462449==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x50200000067b at pc 0x7a83fe6faf59 bp 0x7ffdf6c25060 sp 0x7ffdf6c24808
WRITE of size 12 at 0x50200000067b thread T0
0 0x7b687e6faf58 in memcpy /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:115
1 0x5e22b821235f in weakdep_to_char ../libkmod/libkmod-config.c:623
2 0x5e22b821235f in weakdep_get_plain_weakdep ../libkmod/libkmod-config.c:1166
3 0x5e22b821d049 in kmod_config_iter_get_value ../libkmod/libkmod-config.c:1317
4 0x5e22b81fd5ec in show_config ../tools/modprobe.c:187
5 0x5e22b81fd5ec in do_modprobe ../tools/modprobe.c:946
6 0x7b687d635487 (/usr/lib/libc.so.6+0x27487) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
7 0x7b687d63554b in __libc_start_main (/usr/lib/libc.so.6+0x2754b) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
8 0x5e22b81da114 in _start ($PWD/kmod+0xaa114) (BuildId: c36444aefc2ca73423765d4ebf017a24e55017ee)
Signed-off-by: Jakub Ślepecki <jakub.slepecki@intel.com> Link: https://github.com/kmod-project/kmod/pull/324 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com> Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Lucas De Marchi [Wed, 12 Mar 2025 16:20:32 +0000 (11:20 -0500)]
ci: Improve double checkout where needed
In the main workflow the problem needing a double checkout is that
git may not be available in the containers we are using which causes the
action/checkout to use a tarball. However some of the steps (e.g. meson
dist) need the checkout to be a real git checkout.
Improve the double checkout by doing the first checkout to a local-actions
directory that can be removed after the setup is done. Even if doing it
in a separate dir, the CWD still belongs to a different user as
additional debugs show before removing that directory:
ls -la .
total 12
drwxr-xr-x 3 1001 118 4096 Mar 12 18:35 .
drwxr-xr-x 3 1001 118 4096 Mar 12 18:35 ..
drwxr-xr-x 10 root root 4096 Mar 12 18:35 local-actions
ls -la ..
total 12
drwxr-xr-x 3 1001 118 4096 Mar 12 18:35 .
drwxr-xr-x 6 1001 root 4096 Mar 12 18:35 ..
drwxr-xr-x 3 1001 118 4096 Mar 12 18:35 kmod
Move the safe directory setting to the cleanup step.
Another alternative would be to use the setup-os action from a "remote"
repository, i.e. kmod-project/kmod/.github/actions/setup-os. However it
would make harder to update it in PRs since it would fetch the action
from a different branch.
Lucas De Marchi [Wed, 12 Mar 2025 15:53:45 +0000 (10:53 -0500)]
ci: Drop container objects for other workflows
Commit 23b45fc385c7 ("ci: Drop container object") dropped the container
object for the main workflow. Do the same for the other workflows.
Even if they don't need a matrix (since they run in just one
configuration), keep using it to make the structure common to all
workflows.
Lucas De Marchi [Wed, 12 Mar 2025 13:55:03 +0000 (08:55 -0500)]
ci: Generalize OS setup in one action
Use just one action for OS setup and make it call the right script. This
makes it easier to maintain as when devs are working with containers,
they can just call the script, and it also avoids repeated conditional
steps in the workflows.
If a distro is not supported, the action will simply fail and support
may be added later.
With the move to .sh files, also run shellcheck in them: surprisingly
just one quote missing.
Emil Velikov [Tue, 11 Mar 2025 12:46:10 +0000 (12:46 +0000)]
ci: remove Debian/pahole dependency
The dependency was added as a workaround to the Debian bug linked. With
that resolved we can remove pahole.
Reference: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1098706 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/314 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Tue, 11 Mar 2025 14:22:46 +0000 (14:22 +0000)]
ci: remove no longer needed libtool
We've dropped libtool across all distros but Fedora. The tool is not
needed anymore, so let's remove it.
Fixes: 04520dc9 ("ci: Remove autotools dependencies from containers") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/318 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Tue, 11 Mar 2025 12:49:54 +0000 (12:49 +0000)]
NEWS: squash a couple of typos
Namely:
- ondemand -> on demand
- mson -> meson
Fixes: 88940379 ("kmod 34") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/315 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Chen, Yuchi [Fri, 7 Mar 2025 05:15:01 +0000 (13:15 +0800)]
ci: Push documentation to kmod-project.github.io and trigger publishing
1. When master or a new tag is pushed, build API documentation
2. Push the newly built document to kmod-project.github.io
3. Dispatch kmod-project.github.io to publish documents
Co-developed-by: Chen, Yuchi <yuchi.chen@intel.com> Signed-off-by: Chen, Yuchi <yuchi.chen@intel.com> Signed-off-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Dan He <dan.h.he@intel.com> Signed-off-by: Wenjie Wang <wenjie2.wang@intel.com> Signed-off-by: Qingqing Li <qingqing.li@intel.com> Link: https://github.com/kmod-project/kmod/pull/308 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
dependabot[bot] [Sat, 1 Mar 2025 01:10:03 +0000 (01:10 +0000)]
ci: bump the all-actions group across 1 directory with 2 updates
Bumps the all-actions group with 2 updates in the / directory: [github/codeql-action](https://github.com/github/codeql-action) and [codecov/codecov-action](https://github.com/codecov/codecov-action).
Updates `github/codeql-action` from 3.27.1 to 3.28.10
- [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/4f3212b61783c3c68e8309a0f18a699764811cda...b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d)
Updates `codecov/codecov-action` from 4.6.0 to 5.4.0
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238...0565863a31f2c772f9f0395002a31e3f06189574)
If strbuf is used (depmod, modprobe -c) then strbuf_reserve_extra is
performance critical. This reduces amount of instructions for
modprobe -c by around 10 %, the total instruction count for depmod
by 1 % (majority is within reading module files).
The strbuf_reserve_extra call is only left for a possible '/' addition,
which only occurs before depmod_modules_search_dir recursively calls
itself.
By adding the slash at the start, it also simplifies
depmod_modules_search_path which does not have to do this before calling
depmod_modules_search_dir on its own.
The function depmod_modules_search_dir is supposed to ignore all errors
encountered during directory entry iteration. This was not true for
out of memory conditions, which could also lead to wrong output.
Clarify this fact by turning it void and adjust callers accordingly.
The hex output uses a heap-based strbuf. It can be turned into a
stack-based strbuf by refactoring kmod_module_hex_to_str. Instead of
returning a C string, a supplied strbuf can be filled with hex values
in ASCII representation. Renamed to kmod_module_strbuf_pushhex.
A size of 512 is sufficient for signatures on Arch Linux and removes
heap allocations. Additional benefit is implicit strbuf_init and
strbuf_release due to DECLARE_STRBUF_WITH_STACK.
The strbuf content is never returned, so it's easy to switch to a
stack-based solution. It removes heap allocations and the need to
manually call strbuf_init and strbuf_release since these are covered
through DECLARE_STRBUF_WITH_STACK as well.
Clarify that the code does not perform error checks, for which we
regularly use checks and continue at the start, but merely checks
how to print/filter the data.
Gongjun Song [Fri, 7 Mar 2025 02:33:51 +0000 (10:33 +0800)]
testsuite: Improve fake_delete behavior
- When fake delete_module() succeeds, remove its entry from /sys/module.
- Add tests to ensure module is properly removed.
Co-developed-by: Qingqing Li <qingqing.li@intel.com> Signed-off-by: Qingqing Li <qingqing.li@intel.com> Signed-off-by: Dan He <dan.h.he@intel.com> Signed-off-by: Gongjun Song <gongjun.song@intel.com> Signed-off-by: Yuchi Chen <yuchi.chen@intel.com> Signed-off-by: Wenjie Wang <wenjie2.wang@intel.com> Link: https://github.com/kmod-project/kmod/pull/309 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Thu, 27 Feb 2025 16:47:08 +0000 (10:47 -0600)]
ci: Switch most builds to 64b
Due to a mistake on using "multilib" fixed in commit 271d8ab ("ci: Fix 32b build ignoring options") and commit 6897912 ("ci: s/multilib/x32/"), most of our builds were actually
testing 32b, which is not the most common thing.
Leave just 2 32b builds, one with Archlinux and the other with Ubuntu
and remove the FIXME about configuration.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Thu, 27 Feb 2025 14:48:56 +0000 (08:48 -0600)]
ci: Fix 32b build ignoring options
In some configurations we pass meson_setup and x32 options, but the
options were being ignored in 32b builds. Unify the configure/build/test
steps since just the 32b configuration step that needs to be handled
differently, then make sure --native-file and the configure options
are also handled for 32b builds.
Add a 64b configuration for Archlinux and disable test on Archlinux x32
since it's failing due to packages installed and/or distro
configuration.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Thu, 27 Feb 2025 14:38:19 +0000 (08:38 -0600)]
ci: s/multilib/x32/
It's confusing using "multilib" because it's not about adding the
"capability of building 32b", it's rather "this is really building and
testing 32b, which takes different steps.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Thu, 27 Feb 2025 06:36:33 +0000 (00:36 -0600)]
ci: Use include to completly specify the matrix
The permutation available in github and extending it "include" or
reducing it with "exclude" are much harder than needed. It doesn't seem
we can have a mix of "properties" with the configurations. Just give up
and completly specify the matrix. Now that there's only 1 build system,
at least doing all the permutations doesn't make it too big.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Hendrik Donner [Mon, 3 Mar 2025 15:13:01 +0000 (16:13 +0100)]
meson: Use short options for ln everywhere
Some implementations of ln (toybox, busybox) typically only support the
short option format, so use it consistently.
The short options are already used in other places and it's usually
supported on more implementations: -s and -f are POSIX and the few
ln that support --relative understand -r. Which are GNU coreutils,
the Rust uutils coreutils, toybox (-r only) and there is an old
patch for busybox (-r only). The BSDs and MacOS don't seem to
support --relative at all.
kmod: use program_invocation_short_name more often
Remove the explicit basename(argv[0]) calls because we already
rely on program_invocation_short_name even before reaching
these lines. Unifies code and slightly reduces binary size.
The write_* functions have different return statement handling. Unify
them by removing "else" if the if-block itself returns and also unify
the error handling by checking for the error case, leaving the success
return statement at the end of the function.
If no -o option is given, use stdout directly without opening
/dev/stdout manually. In a chroot environment, this could lead
to /dev/stdout creation as a regular file.
Since log_open takes a booln as argument, turn use_syslog into a
bool instead of using an int. Shrinks binary size with GCC and from
C point of view, this makes the code cleaner.
Lucas De Marchi [Mon, 6 Jan 2025 15:16:13 +0000 (09:16 -0600)]
clang-format: Add new attribute macros
Commits 44855d7 ("shared/macro: Add _alignedptr_") and d7e7c4c
("shared/macro: Add macros for more attributes") added the macros, but
forgot to add them to the clang-format configuration.
Suggested-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Fri, 3 Jan 2025 19:01:14 +0000 (13:01 -0600)]
testsuite: Fix build when linking with lld
When building with clang and linking with lld there is an issue with
keeping the kmod_tests sections: On ELF targets, __attribute__((used))
prevents compiler discarding, but does not affect linker --gc-sections,
according to https://lld.llvm.org/ELF/start-stop-gc.
Make sure the _start/_stop symbols are not weak and add the "retain"
attribute.
Grayson Nocera [Mon, 25 Nov 2024 20:33:02 +0000 (15:33 -0500)]
tools: specify buffer to be size PATH_MAX
Using a CodeQL query, I discovered that the destination of a `sscanf` call could overflow.
Thus, we bound the buffer size to be PATH_MAX, to ensure that it is
not larger than `modname` or `devname`.
Signed-off-by: Grayson Nocera <gnocera@purdue.edu> Suggested-by: Tobias Stoeckmann <tobias@stoeckmann.org> Link: https://github.com/kmod-project/kmod/pull/260 Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Sat, 30 Nov 2024 18:46:21 +0000 (12:46 -0600)]
ci: Fix fail due to existent build dir
The second check is a "should fail" check, but it will fail because the
build dir already exists rather than for the true reason. Use a
different dir for the configure tests and move the `rm` inside the
function.
Lucas De Marchi [Wed, 4 Dec 2024 07:19:32 +0000 (01:19 -0600)]
meson: Allow to set dlopen option for compression libraries
Add a dlopen option that allows toggling what libraries libkmod should
attempt to dlopen. If -Ddlopen=foo is passed, it means that library is
required to build, regardless of -Dfoo=*. However that library will
only be linked in if it's not set as dlopen.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
[ with disagreement on the need to toggle each one individually,
it'd be better to be all-or-nothing dlopen'ed ] Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/262
Lucas De Marchi [Wed, 4 Dec 2024 07:04:09 +0000 (01:04 -0600)]
build: Always define ENABLE_* macros
Define either to 0 or 1 so codebase is forced to used `#if ENABLE_*` or
similar. It's confusing to have some leaving undefined and others
defining as 0 or 1.
Lucas De Marchi [Sat, 30 Nov 2024 16:53:49 +0000 (10:53 -0600)]
libkmod/zstd: Do not re-use size_t for ret
size_t is unsigned, while the function returns a negative number.
Instead of using `ret` for the return from ZSTD_decompress(), re-use
dst_size that should be the same as we passed in for that call since
it already checks for ZSTD_CONTENTSIZE_UNKNOWN and ZSTD_CONTENTSIZE_ERROR.
Even if it's not the same, it's more correct to use that value to
assign to file->size to avoid accessing uninitialized memory.
Lucas De Marchi [Sat, 30 Nov 2024 06:30:53 +0000 (00:30 -0600)]
util: Add dlfcn helpers
Heavily based on systemd: add similar (but simplified) functions to
dlopen() a library and load specific symbols from it. This will be
useful to allow to load the compression libraries as needed. A few
differences from the systemd implementation:
1) It's allowed to link directly to the library and hence bypass the
dlopen() + dlsym()
2) The only entrypoint is dlsym_many() which is already declared with
the sentinel: it's expected callers will use an x-macro that doesn't
allow forgetting the sentinel
3) No support yet for ELF info annotation yet