]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
13 months agoman: remove the "Maintained by" references
Emil Velikov [Mon, 8 Jul 2024 13:43:23 +0000 (14:43 +0100)] 
man: remove the "Maintained by" references

At a glance through my system, around 2% of the man pages include such
statement.

Looking through git log, Jon has been active in a while and presumably
have moved on.

Most importantly the Copyright section isn't the best place to reference
the maintainer/contact person.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: modprobe: remove hard-coded /etc/modprobe.d references
Emil Velikov [Mon, 8 Jul 2024 13:43:22 +0000 (14:43 +0100)] 
man: modprobe: remove hard-coded /etc/modprobe.d references

Point the users to modprobe.d(5) instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: add few mentions about MODPROBE_OPTIONS
Emil Velikov [Mon, 8 Jul 2024 13:43:21 +0000 (14:43 +0100)] 
man: add few mentions about MODPROBE_OPTIONS

The environment variable may alter config file ordering, so mention it
in the man page.

In addition, highlight that the format is intentionally undocumented
since the use by third parties is discouraged.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: modprobe.d: factor out a CONFIGURATION FORMAT section
Emil Velikov [Mon, 8 Jul 2024 13:43:20 +0000 (14:43 +0100)] 
man: modprobe.d: factor out a CONFIGURATION FORMAT section

Keep the description neat and tidy.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: modprobe.d: document the config file order handling
Emil Velikov [Mon, 8 Jul 2024 13:43:19 +0000 (14:43 +0100)] 
man: modprobe.d: document the config file order handling

The modprobe.d configuration order/handling aligns with existing tools
such as sysctl.d, even though there is no mention in the manual.

Reorder the list in SYNOPSIS and add a bit of verbiage describing things.

Section is inspired by sysctl.d(5) and sysctl(8).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: depmod: remove hard-coded /etc/depmod.d references
Emil Velikov [Mon, 8 Jul 2024 13:43:18 +0000 (14:43 +0100)] 
man: depmod: remove hard-coded /etc/depmod.d references

Point the users to depmod.d(5) instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: depmod.d: rework the opening description sentence
Emil Velikov [Mon, 8 Jul 2024 13:43:17 +0000 (14:43 +0100)] 
man: depmod.d: rework the opening description sentence

Use a slightly longer, more gradual introduction.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: depmod.d: factor out a CONFIGURATION FORMAT section
Emil Velikov [Mon, 8 Jul 2024 13:43:16 +0000 (14:43 +0100)] 
man: depmod.d: factor out a CONFIGURATION FORMAT section

Keep the description neat and tidy.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: depmod.d: document the config file order handling
Emil Velikov [Mon, 8 Jul 2024 13:43:15 +0000 (14:43 +0100)] 
man: depmod.d: document the config file order handling

The depmod.d configuration order/handling aligns with existing tools
such as sysctl.d, even though there is no mention in the manual.

Reorder the list in SYNOPSIS and add a bit of verbiage describing things.

Section is inspired by sysctl.d(5) and sysctl(8).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: stop removing DISTCONFDIR lines
Emil Velikov [Mon, 8 Jul 2024 13:43:14 +0000 (14:43 +0100)] 
man: stop removing DISTCONFDIR lines

Presently when DISTCONFDIR is identical to /lib we remove the whole
line, since the man pages already have an /lib instance.

At the same time, there are in-text DISTCONFDIR entries, and removing
the whole line outright breaks the documentation.

Drop the removal line - worst case scenario we get a duplicate entry in
the synopsis.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: couple of grammar/language fixes
Emil Velikov [Mon, 8 Jul 2024 13:43:13 +0000 (14:43 +0100)] 
man: couple of grammar/language fixes

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: some options take an argument, mention that
Emil Velikov [Mon, 8 Jul 2024 13:43:12 +0000 (14:43 +0100)] 
man: some options take an argument, mention that

For example modinfo -F requires the field name, although the
documentation was missing the "field".

Similarly modprobe has omissions, so let's fix those as well.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: misc punctuation fixes
Emil Velikov [Mon, 8 Jul 2024 13:43:11 +0000 (14:43 +0100)] 
man: misc punctuation fixes

Some commas and a full stop was missing ;-)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: white space fixes
Emil Velikov [Mon, 8 Jul 2024 13:43:10 +0000 (14:43 +0100)] 
man: white space fixes

These were present in the original xml files and I opted to keep them
separate fix to make the transition/comparison easier.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: add some extra bold/italic annotations
Emil Velikov [Mon, 8 Jul 2024 13:43:09 +0000 (14:43 +0100)] 
man: add some extra bold/italic annotations

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: remove no longer used XML files
Emil Velikov [Tue, 11 Jun 2024 15:05:04 +0000 (16:05 +0100)] 
man: remove no longer used XML files

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agobuild: Require scdoc if building man pages
Lucas De Marchi [Wed, 3 Jul 2024 15:07:12 +0000 (10:07 -0500)] 
build: Require scdoc if building man pages

Instead of creating invalid man pages, make sure the configure step
fails if scdoc is not available.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agogitignore: ignore gtk-doc.m4
Lucas De Marchi [Wed, 3 Jul 2024 15:04:19 +0000 (10:04 -0500)] 
gitignore: ignore gtk-doc.m4

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: build the scdoc based man pages
Emil Velikov [Tue, 11 Jun 2024 15:05:03 +0000 (16:05 +0100)] 
man: build the scdoc based man pages

Note that scdoc does not handle natively handle the dummy
modules.dep.bin.5 entry, so we need to create one manually.

Not a big deal, since it's single static line anyway.

Also: pkg-config --variable=scdoc scdoc, produces the full executable
and path, although for now we stick with the AC_PATH_PROG approach.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
[ Do not add the stub man page (modules.dep.bin.5) to CLEANFILES
  to avoid removing a file that is tracked by git. Also fix a typo
  s/AM_V_SCDOR_/AM_V_SCDOC_/ to make silent rules to work ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: add scdoc based man pages
Emil Velikov [Tue, 11 Jun 2024 15:05:02 +0000 (16:05 +0100)] 
man: add scdoc based man pages

Working with xml is quite fiddly. Swap that for scdoc, which has very
trivial markup-like syntax.

We have opted for scdoc since it's available on practically any linux
distribution. Implementation-wise it's a trivial C99 project, at 1k LoC.

If using scdoc proves to be a burden, we can trivially port these to
pandoc or similar - 90% of the content will stay the same.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite: add tests for weak dependencies
Jose Ignacio Tornos Martinez [Thu, 30 May 2024 07:08:27 +0000 (09:08 +0200)] 
testsuite: add tests for weak dependencies

The following tests to verify weak dependencies have been implemented:
1) modprobe test to check that related weakdep modules are not loaded
   due to being a weakdep.
2) depmod test to check weakdep output.
3) user test to check that configuration files with weakdep are parsed
   correctly and related weakdep modules can be read correctly from user
   applications.

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
Link: https://lore.kernel.org/r/20240530070836.9438-1-jtornosm@redhat.com
[ Minor whitespace issues and define MODULE_WEAKDEP if it's not defined
  already ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months ago.mailmap: Forward to my personal email
Emil Velikov [Tue, 11 Jun 2024 14:34:56 +0000 (15:34 +0100)] 
.mailmap: Forward to my personal email

My Collabora email is bouncing, so forward to my personal Gmail.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240611-mailmap-v1-1-69ce7f7ffbe6@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite: Add missing.h include
Lucas De Marchi [Tue, 11 Jun 2024 13:09:19 +0000 (08:09 -0500)] 
testsuite: Add missing.h include

basename() moved to missing.h when the libc doesn't provide it, but
testsuite is not including it. Add missing include.

Fixes: 11eb9bc67c31 ("Use portable implementation for basename API")
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agodepmod: Fix warning with -D_TIME_BITS=64
Lucas De Marchi [Tue, 11 Jun 2024 13:02:26 +0000 (08:02 -0500)] 
depmod: Fix warning with -D_TIME_BITS=64

Printing time_t, suseconds_t, useconds_t in 32bits with -D_TIME_BITS=64
leads to the following warning:

../tools/depmod.c:2641:61: warning: format ‘%li’ expects argument of type ‘long int’, but argument 6 has type ‘__suseconds64_t’ {aka ‘long long int’} [-Wformat=]
 2641 |                         snprintf(tmp, sizeof(tmp), "%s.%i.%li.%li", itr->name, getpid(),
      |                                                           ~~^
      |                                                             |
      |                                                             long int
      |                                                           %lli
 2642 |                                         tv.tv_usec, tv.tv_sec);
      |                                         ~~~~~~~~~~

Paper it over by casting the argument to 64 bits and switching to long long.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite: wrap _{l,}stat64_time64 in test
Shengjing Zhu [Thu, 18 Apr 2024 14:29:51 +0000 (22:29 +0800)] 
testsuite: wrap _{l,}stat64_time64 in test

Fix building with -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 on 32bit arch.

Closes: https://github.com/kmod-project/kmod/issues/37
Bug: https://bugs.debian.org/1065973
Co-authored-by: Jochen Sprickerhof <github@jochen.sprickerhof.de>
Signed-off-by: Shengjing Zhu <shengjing.zhu@canonical.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agoUse portable implementation for basename API
Khem Raj [Sun, 10 Dec 2023 01:35:59 +0000 (17:35 -0800)] 
Use portable implementation for basename API

musl has removed the non-prototype declaration of basename from
string.h [1] which now results in build errors with clang-17+ compiler

Implement GNU basename behavior using strchr which is portable across libcs

Fixes
../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
71 | "Commands:\n", basename(argv[0]));
| ^

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

Suggested-by: Rich Felker
Signed-off-by: Khem Raj <raj.khem@gmail.com>
[ Implement a basename() function in missing.h and ensure we always use
  the right include rather than having a separate gnu_basename() ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: add weak dependecies
Jose Ignacio Tornos Martinez [Wed, 27 Mar 2024 14:11:16 +0000 (15:11 +0100)] 
libkmod: add weak dependecies

It has been seen that for some network mac drivers (i.e. lan78xx) the
related module for the phy is loaded dynamically depending on the current
hardware. In this case, the associated phy is read using mdio bus and then
the associated phy module is loaded during runtime (kernel function
phy_request_driver_module). However, no software dependency is defined, so
the user tools will no be able to get this dependency. For example, if
dracut is used and the hardware is present, lan78xx will be included but no
phy module will be added, and in the next restart the device will not work
from boot because no related phy will be found during initramfs stage.

In order to solve this, we could define a normal 'pre' software dependency
in lan78xx module with all the possible phy modules (there may be some),
but proceeding in that way, all the possible phy modules would be loaded
while only one is necessary.

The idea is to create a new type of dependency, that we are going to call
'weak' to be used only by the user tools that need to detect this situation.
In that way, for example, dracut could check the 'weak' dependency of the
modules involved in order to install these dependencies in initramfs too.
That is, for the commented lan78xx module, defining the 'weak' dependency
with the possible phy modules list, only the necessary phy would be loaded
on demand keeping the same behavior, but all the possible phy modules would
be available from initramfs.

A new function 'kmod_module_get_weakdeps' in libkmod will be added for
this to avoid breaking the API and maintain backward compatibility. This
general procedure could be useful for other similar cases (not only for
dynamic phy loading).

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
Link: https://lore.kernel.org/r/20240327141116.97587-1-jtornosm@redhat.com
15 months agolibkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_types
Emil Velikov [Mon, 12 Feb 2024 17:23:13 +0000 (17:23 +0000)] 
libkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_types

It's cleaner to handle all compression types and load functions in the
same style.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: move load_reg() further up
Emil Velikov [Mon, 12 Feb 2024 17:23:12 +0000 (17:23 +0000)] 
libkmod: move load_reg() further up

We're about to reference it in comp_types with next commit.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: tidy-up kmod_file_open()
Emil Velikov [Mon, 12 Feb 2024 17:23:11 +0000 (17:23 +0000)] 
libkmod: tidy-up kmod_file_open()

This commit cleans up the indentation and the error path of the
function. It bears no functional changes.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
[ Move assert to avoid warning with -Wdeclaration-after-statement ]
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: swap alloca usage for a few assert_cc
Emil Velikov [Mon, 12 Feb 2024 17:23:10 +0000 (17:23 +0000)] 
libkmod: swap alloca usage for a few assert_cc

Since all the compression magic is always available now, we don't need
to loop at runtime nor use alloca - latter of which comes with a handful
of caveats.

Simply throw in a few assert_cc(), which will trigger at build-time.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: always detect the module compression
Emil Velikov [Mon, 12 Feb 2024 17:23:09 +0000 (17:23 +0000)] 
libkmod: always detect the module compression

Currently, when built w/o given compression we'll incorrectly report a
"compression_none".

As we reach do_finit_module(), we'll naively assume that the kernel can
handle the compressed module, yet omit the MODULE_INIT_COMPRESSED_FILE
flag.

As result the kernel will barf at us, do_finit_module will fail with non
-ENOSYS and we won't end in the do_init_module codepath (which will also
fail).

In other words: with this change, you can build kmod without zstd, xz
and zlib support and the kernel will load the modules, assuming it
supports the format \o/

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: move kmod_file_load_contents as applicable
Emil Velikov [Mon, 12 Feb 2024 17:23:08 +0000 (17:23 +0000)] 
libkmod: move kmod_file_load_contents as applicable

When dealing with an elf, we don't know or care about loading the file.
The kmod_elf subsystem/API will deal with the required parts itself.

Which in this case, already calls kmod_file_load_contents() as
applicable.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: propagate {zstd,xz,zlib}_load errors
Emil Velikov [Mon, 12 Feb 2024 17:23:07 +0000 (17:23 +0000)] 
libkmod: propagate {zstd,xz,zlib}_load errors

Propagate any errors during decompression further up the call stack.
Without this we could easily pass NULL as mem to init_module(2).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: nuke struct file_ops
Emil Velikov [Mon, 12 Feb 2024 17:23:06 +0000 (17:23 +0000)] 
libkmod: nuke struct file_ops

With the previous commits, we removed the need for a distinct unload
callback.

So nuke the struct all together and only use/keep the load one around.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: clear file->memory if map fails
Emil Velikov [Mon, 12 Feb 2024 17:23:05 +0000 (17:23 +0000)] 
libkmod: clear file->memory if map fails

On mmap failure file->memory is set to -1, which we'll happily pass down
to munmap later on.

More importantly, since we do a NULL check in kmod_file_load_contents()
we will exit the function without (re)attempting the load again.

Since we ignore the return code for the load function(s), one can end up
calling kmod_elf_get_memory() and feed that -1 into init_module.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: remove kmod_file::{zstd,xz}_used flags
Emil Velikov [Mon, 12 Feb 2024 17:23:04 +0000 (17:23 +0000)] 
libkmod: remove kmod_file::{zstd,xz}_used flags

These are used to protect a free(file->memory), within their respective
unload functions. Where the sole caller of the unload function already
does a NULL check prior.

Even so, free(NULL) is guaranteed to be safe by the standard.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: keep gzFile gzf local to load_zlib()
Emil Velikov [Mon, 12 Feb 2024 17:23:03 +0000 (17:23 +0000)] 
libkmod: keep gzFile gzf local to load_zlib()

There is no need to keep the root gzFile context open for the whole
duration. Once we've copied the decompressed module to file->memory we
can close the handle.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: use a dup()'d fd for zlib
Emil Velikov [Mon, 12 Feb 2024 17:23:02 +0000 (17:23 +0000)] 
libkmod: use a dup()'d fd for zlib

The gzdopen() API used, takes ownership of the fd. To make that more
explicit we clear it (-1) as applicable.

Yet again, kmod has explicit API to return the fd to the user - which
currently is used solely when uncompressed, so we're safe.

Regardless - simply duplicate the fd locally and use that with zlib.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agobuild: Ignore directories commonly used for out-of-tree build
Lucas De Marchi [Tue, 30 Apr 2024 14:26:20 +0000 (09:26 -0500)] 
build: Ignore directories commonly used for out-of-tree build

build/ and build-*/ are commonly used to have multiple out-out-tree
builds. Add them to gitignore.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agotestsuite: Fix warnings due to -Wmissing-prototypes
Lucas De Marchi [Mon, 29 Apr 2024 21:19:12 +0000 (16:19 -0500)] 
testsuite: Fix warnings due to -Wmissing-prototypes

/testsuite/module-playground/mod-foo-b.c:13:6: warning: no previous prototype for ‘print_fooB’ [-Wmissing-prototypes]
   13 | void print_fooB(void)
      |      ^~~~~~~~~~
/testsuite/module-playground/mod-foo-a.c:13:6: warning: no previous prototype for ‘print_fooA’ [-Wmissing-prototypes]
   13 | void print_fooA(void)
      |      ^~~~~~~~~~
/testsuite/module-playground/mod-foo-c.c:13:6: warning: no previous prototype for ‘print_fooC’ [-Wmissing-prototypes]
   13 | void print_fooC(void)
      |      ^~~~~~~~~~
/testsuite/module-playground/mod-fake-scsi-mod.c:15:6: warning: no previous prototype for ‘dummy_export’ [-Wmissing-prototypes]
   15 | void dummy_export(void)
      |      ^~~~~~~~~~~~

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agoInstall kmod.pc in ${datadir}/pkgconfig
Mike Gilbert [Fri, 8 Mar 2024 19:06:19 +0000 (14:06 -0500)] 
Install kmod.pc in ${datadir}/pkgconfig

The data in this file isn't related to installed libraries, so put it in
an abi-neutral location.

pkg.m4 provides macros that also allow the user to override the location
with configure switches.

Bug: https://bugs.gentoo.org/926431
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agobuild: Allow to install over dirty dir
Lucas De Marchi [Wed, 6 Mar 2024 14:58:04 +0000 (08:58 -0600)] 
build: Allow to install over dirty dir

Before commit e98cef6f3f8c ("make: install/uninstall tools symlinks to
kmod") it was possible to call `make install DESTDIR=<dir>` multiple
times. Use `ln -sf` so the symlink is always re-created.

It would be preferred to remove install in an empty dir, but there's
not a bad consequence of re-using the same, so let the user decide.
Fixes the following errors while installing for the second time:

ln: failed to create symbolic link '/tmp/inst/usr/bin/insmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/lsmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/rmmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/depmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/modprobe': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/modinfo': File exists
make[3]: *** [Makefile:2679: install-exec-hook] Error 1
make[2]: *** [Makefile:2553: install-exec-am] Error 2
make[1]: *** [Makefile:2439: install-am] Error 2
make: *** [Makefile:1848: install-recursive] Error 1

Cc: Emil Velikov <emil.l.velikov@gmail.com>
Closes: https://github.com/kmod-project/kmod/issues/35
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240306145804.135709-1-lucas.de.marchi@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agokmod 32 v32
Lucas De Marchi [Wed, 6 Mar 2024 03:27:42 +0000 (21:27 -0600)] 
kmod 32

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

The kmod insert/remove tools were introduced back in 2015. Since then
they have recieved zero attention, unlike the insmod/rmmod variants.

Glancing around - neither of the following distributions (Arch, Fedora,
Gentoo, Debian) build them, so we're safe to say they have no users.

Remove them and alongside it the --enable-experimental toggle, which no
longer controls anything.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240212-rm-experimental-v1-1-b97ab3004ae3@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agoman: silence autoconf warnings
Emil Velikov [Sat, 17 Feb 2024 16:01:26 +0000 (16:01 +0000)] 
man: silence autoconf warnings

Currently we have a pattern rule, which effective states that two output
files are produced - %.5 and %.8. Although that's not the case in
practise, since each input xml will be generated to a single manual
page.

Add the manpage section as part of the xml filename and tweak the
pattern (match) rule, accordingly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240217-autoconf-manpage-warns-v1-1-e1570cfc286e@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
18 months agomake: install/uninstall tools symlinks to kmod
Emil Velikov [Fri, 26 Jan 2024 14:43:51 +0000 (14:43 +0000)] 
make: install/uninstall tools symlinks to kmod

Currently we create symlinks like modprobe (pointing to kmod), during
the normal `make` build. Although those were never installed.

Add a few lines in the install-exec-hook, to ensure they're present at
`make install` time. Thus one can actually use those without additional
changes. As an added bonus, distributions can drop the similar hunk from
their packaging.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
[ Use a relative symlink ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
18 months agoconfigure: tweak the module_directory help string
Emil Velikov [Fri, 26 Jan 2024 14:43:50 +0000 (14:43 +0000)] 
configure: tweak the module_directory help string

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

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

tools/kmod.pc is generated by build system. Any new *.pc we may have
should follow a similar approach. So, just ignore from git, like we do
for e.g. *.o.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
18 months agotestsuite: drop mkosi
Lucas De Marchi [Fri, 2 Feb 2024 18:36:28 +0000 (12:36 -0600)] 
testsuite: drop mkosi

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

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

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

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

Python bindings are not well maintained. Currently it's just broken when
trying to build with cython 3.0.8:

make --no-print-directory all-recursive
Making all in .
  CYTHON  libkmod/python/kmod/kmod.c

Error compiling Cython file:
------------------------------------------------------------
...
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with python-kmod.  If not, see <http://www.gnu.org/licenses/>.

cimport _libkmod_h
^

Nothing really touched those bindings for 10 years already.
I postponed the removal since they were at least building, but that just
changed. So let's drop it and allow any interested people to give it
a better life outside of libkmod.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
20 months agoconfigure: Check that provided paths are absolute
Michal Suchanek [Fri, 10 Nov 2023 12:13:55 +0000 (13:13 +0100)] 
configure: Check that provided paths are absolute

configure checks that its built-in directory options get an absolute
path. Copy the check for custom options.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Link: https://lore.kernel.org/r/8aff0c9c491d8afeec7f6b2cd96cbd0439e26fbb.1699618135.git.msuchanek@suse.de
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
20 months agolibkmod, depmod, modprobe: Make directory for kernel modules configurable
Michal Suchanek [Fri, 10 Nov 2023 12:13:54 +0000 (13:13 +0100)] 
libkmod, depmod, modprobe: Make directory for kernel modules configurable

Now that modprobe.d is searched under ${prefix}/lib, allow a complete
transition to files only under ${prefix} by adding a ${module_directory}
configuration. This specifies the directory where to search for kernel
modules and should match the location where the kernel/distro installs
them.

With this distributions that do not want to ship files in /lib can also
move kernel modules to /usr while others can keep them in /lib.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Link: https://lore.kernel.org/r/a3765f4e8ae3ce29c0847a0132d4a8d51ad040a9.1699618135.git.msuchanek@suse.de
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agolibkmod: remove pkcs7 obj_to_hash_algo()
Dimitri John Ledkov [Sun, 29 Oct 2023 01:03:19 +0000 (03:03 +0200)] 
libkmod: remove pkcs7 obj_to_hash_algo()

Switch to using OBJ_obj2txt() to calculate and print the pkcs7
signature hash name. This eliminates the need to duplicate libcrypto
NID to name mapping, detect SM3 openssl compile-time support, and
enables using any hashes that openssl and kernel know about. For
example SHA3 are being added for v6.7 and with this patch are
automatically supported.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
Link: https://lore.kernel.org/r/20231029010319.157390-1-dimitri.ledkov@canonical.com
21 months agotools: depmod: fix -Walloc-size
Sam James [Sun, 5 Nov 2023 22:02:25 +0000 (22:02 +0000)] 
tools: depmod: fix -Walloc-size

GCC 14 introduces a new -Walloc-size included in -Wextra which gives:
```
tools/depmod.c:192:14: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size]
tools/depmod.c:255:11: warning: allocation of insufficient size ‘1’ for type ‘struct index_value’ with size ‘16’ [-Walloc-size]
tools/depmod.c:286:35: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size]
tools/depmod.c:315:44: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size]
```

The calloc prototype is:
```
void *calloc(size_t nmemb, size_t size);
```

So, just swap the number of members and size arguments to match the prototype, as
we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not
doing anything wrong.

Signed-off-by: Sam James <sam@gentoo.org>
21 months agokmod: Add pkgconfig file with kmod compile time configuration
Michal Suchanek [Tue, 18 Jul 2023 12:01:55 +0000 (14:01 +0200)] 
kmod: Add pkgconfig file with kmod compile time configuration

Show distconfdir (where system configuration files are searched/to be
installed), sysconfdir (where user configuration files are searched),
module compressions, and module signatures supported.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Link: https://lore.kernel.org/r/468b3f572d3b84f25bb53ec8fcb15ed4871914d4.1689681454.git.msuchanek@suse.de
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agolibkmod, depmod: Load modprobe.d, depmod.d from ${prefix}/lib.
Michal Suchanek [Tue, 18 Jul 2023 12:01:54 +0000 (14:01 +0200)] 
libkmod, depmod: Load modprobe.d, depmod.d from ${prefix}/lib.

There is an ongoing effort to limit use of files outside of /usr (or
${prefix} on general). Currently all modprobe.d paths are hardcoded to
outside of $prefix. Teach kmod to load modprobe.d from ${prefix}/lib.

On some distributions /usr/lib and /lib are the same directory because
of a compatibility symlink, and it is possible to craft configuration
files with sideeffects that would behave differently when loaded twice.
However, the override semantic ensures that one 'overrides' the other,
and only one configuration file of the same name is loaded from any of
the search directories.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Link: https://lore.kernel.org/r/a290343ce32e2a3c25b134e4f27c13b26e06c9e0.1689681454.git.msuchanek@suse.de
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agoman/depmod.d: Fix incorrect /usr/lib search path
Michal Suchanek [Tue, 18 Jul 2023 12:01:53 +0000 (14:01 +0200)] 
man/depmod.d: Fix incorrect /usr/lib search path

depmod searches /lib/depmod.d but the man page says /usr/lib/depmod.d is
searched. Align the documentation with the code.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Link: https://lore.kernel.org/r/9c5a6356b1a111eb6e17ddb110494b7f1d1b44c0.1689681454.git.msuchanek@suse.de
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
21 months agoconfigure: Detect openssl sm3 support
Michal Suchanek [Tue, 18 Jul 2023 12:01:52 +0000 (14:01 +0200)] 
configure: Detect openssl sm3 support

Older openssl versions do not support sm3. The code has an option to
disable the sm3 hash but the lack of openssl support is not detected
automatically.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Link: https://lore.kernel.org/r/b97e20faa07e9e31c6eaf96683011aa24e80760c.1689681454.git.msuchanek@suse.de
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agokmod 31 v31
Lucas De Marchi [Fri, 29 Sep 2023 14:18:37 +0000 (09:18 -0500)] 
kmod 31

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

The symbol was somewhat recently introduced by the kernel and not all
distributions may be have available.

The number is part of the ABI, so we can add a local fallback define.

Closes: https://github.com/kmod-project/kmod/issues/29
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agolibkmod: Use kernel decompression when available
Lucas De Marchi [Thu, 1 Jun 2023 22:40:01 +0000 (15:40 -0700)] 
libkmod: Use kernel decompression when available

With the recent changes to bypass loading the file it's possible to
reduce the work in userspace and delegating it to the kernel. Without
any compression to illustrate:

Before:
read(3, "\177ELF\2\1", 6)               = 6
lseek(3, 0, SEEK_SET)                   = 0
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=238592, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 238592, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd85cbd1000
finit_module(3, "", 0)                  = 0
munmap(0x7fd85cbd1000, 238592)          = 0
close(3)                                = 0

After:
read(3, "\177ELF\2\1", 6)               = 6
lseek(3, 0, SEEK_SET)                   = 0
finit_module(3, "", 0)                  = 0
close(3)                                = 0

When using kernel compression now it's also possible to direct libkmod
to take the finit_module() path, avoiding the decompression in userspace
and just delegating it to the kernel.

Before:
read(3, "(\265/\375\244\0", 6)          = 6
lseek(3, 0, SEEK_SET)                   = 0
read(3, "(\265/\375\244", 5)            = 5
mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3fa431e000
read(3, "\0\244\3\0\\y\6", 7)           = 7
mmap(NULL, 372736, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3fa414f000
brk(0x55944c6a1000)                     = 0x55944c6a1000
read(3, "\356|\6G\27U\20 \312\260s\211\335\333\263\326\330\336\273O\211\356\306K\360Z\341\374U6\342\221"..., 53038) = 53038
mremap(0x7f3fa431e000, 135168, 266240, MREMAP_MAYMOVE) = 0x7f3fa410e000
read(3, ",;\3\nqf\311\362\325\211\7\341\375A\355\221\371L\\\5\7\375 \32\246<(\258=K\304"..., 20851) = 20851
mremap(0x7f3fa410e000, 266240, 397312, MREMAP_MAYMOVE) = 0x7f3fa40ad000
read(3, ")\36\250\213", 4)              = 4
read(3, "", 4)                          = 0
munmap(0x7f3fa414f000, 372736)          = 0
init_module(0x7f3fa40ad010, 238592, "") = 0
munmap(0x7f3fa40ad000, 397312)          = 0
close(3)                                = 0

After:
read(3, "(\265/\375\244P", 6)           = 6
lseek(3, 0, SEEK_SET)                   = 0
finit_module(3, "", 0x4 /* MODULE_INIT_??? */) = 0
close(3)                                = 0

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agolibkmod: Keep track of in-kernel compression support
Lucas De Marchi [Thu, 1 Jun 2023 22:40:00 +0000 (15:40 -0700)] 
libkmod: Keep track of in-kernel compression support

When creating the context, read /sys/kernel/compression to check what's
the compression type supported by the kernel. This will later be used
when loading modules to check if the decompression step has to happen in
userspace or if it can be delegated to the kernel.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agolibkmod: Keep track of compression type
Lucas De Marchi [Thu, 1 Jun 2023 22:39:59 +0000 (15:39 -0700)] 
libkmod: Keep track of compression type

Do not only set the type as direct, but also keep track of the
compression being used. This will allow using the in-kernel compression
in future.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agolibkmod: Extract finit_module vs init_module paths
Lucas De Marchi [Thu, 1 Jun 2023 22:39:58 +0000 (15:39 -0700)] 
libkmod: Extract finit_module vs init_module paths

Extract 2 functions to handle finit_module vs init_modules differences,
with a fallback from the former to the latter.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agolibkmod: Do not inititialize file->memory on open
Lucas De Marchi [Thu, 1 Jun 2023 22:39:57 +0000 (15:39 -0700)] 
libkmod: Do not inititialize file->memory on open

Add a separate function to load the file contents when it's needed.
When it's not needed on the path of loading modules via finit_module(),
there is no need to mmap the file. This will help support loading
modules with the in-kernel compression support.

This is done differently than the lazy initialization for
kmod_file_get_elf() because on the contents case there is also the
file->size to be updated. It would be a weird API to return the pointer
and have the size changed as a side-effect.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agoshared: avoid passing {NULL, 0} array to bsearch()
Dmitry Antipov [Fri, 19 May 2023 07:41:08 +0000 (10:41 +0300)] 
shared: avoid passing {NULL, 0} array to bsearch()

Fix the following warning reported by UBSan (as of gcc-13.1.1):

shared/hash.c:244:35: runtime error: null pointer passed as
argument 2, which is declared to never be null

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
[ reshuffle the code to use return-early style ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agolibkmod: fix possible out-of-bounds memory access
Dmitry Antipov [Fri, 19 May 2023 07:46:38 +0000 (10:46 +0300)] 
libkmod: fix possible out-of-bounds memory access

An attempt to pass too long module name to, say, rmmod, may
cause an out-of-bounds memory access (as repoted by UBSan):

$ rmmod $(for i in $(seq 0 4200); do echo -ne x; done)
libkmod/libkmod-module.c:1828:8: runtime error: index 4107 out of bounds for type 'char [4096]'

This is because 'snprintf(path, sizeof(path), ...)' may return the
value which exceeds 'sizeof(path)' (which happens when an output
gets truncated). To play it safe, such a suspicious output is
better to be rejected explicitly.

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Link: https://lore.kernel.org/r/20230519074638.402045-1-dmantipov@yandex.ru
2 years agolibkmod, depmod: prefer -ENODATA over -ENOENT if no section found
Dmitry Antipov [Fri, 19 May 2023 09:36:30 +0000 (12:36 +0300)] 
libkmod, depmod: prefer -ENODATA over -ENOENT if no section found

When the module is definitely present but CONFIG_MODVERSIONS is
disabled, the following error message may be somewhat confusing:

modprobe --dump-modversions /path/to/module.ko.xz
modprobe: FATAL: could not get modversions of /path/to/module.ko.xz: No such file or directory

Choosing among the convenient errno values, I would suggest to use
ENODATA when the module lacks a particular ELF section (and vermagic
as well). So now it is expected to be:

modprobe: FATAL: could not get modversions of /path/to/module.ko.xz: No data available

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Link: https://lore.kernel.org/r/20230519093630.474185-1-dmantipov@yandex.ru
2 years agomodprobe: rmmod_do_module: Free kmod list of holders
Nicolas Schier [Tue, 18 Apr 2023 08:52:38 +0000 (10:52 +0200)] 
modprobe: rmmod_do_module: Free kmod list of holders

Add a missing kmod_module_unref_list() to fix a memory leak.

Fixes: 42b32d30c38e ("modprobe: Fix holders removal")
Signed-off-by: Nicolas Schier <n.schier@avm.de>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agoconfigure.ac: fix link with -llzma
Fabrice Fontaine [Thu, 2 Mar 2023 17:54:26 +0000 (18:54 +0100)] 
configure.ac: fix link with -llzma

Add liblzma_LIBS to LIBS to avoid the following build failure when
building with a static-only liblzma.a:

/home/autobuild/autobuild/instance-5/output-1/host/lib/gcc/xtensa-buildroot-linux-uclibc/11.3.0/../../../../xtensa-buildroot-linux-uclibc/bin/ld: libkmod/.libs/libkmod-internal.a(libkmod-file.o):(.text.xz_uncompress+0x10): undefined reference to `lzma_code'

For consistency, also update libzstd, zlib and libcrypto

Fixes:
 - http://autobuild.buildroot.org/results/83a4a7ecc77f39639d3e5bc8554bd01a62a3ede0

References: https://github.com/kmod-project/kmod/pull/25
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agoconfigure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES
Emil Velikov [Tue, 21 Feb 2023 13:19:29 +0000 (13:19 +0000)] 
configure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES

Replace the manual sed command, build rules and dist/clean for using
AC_CONFIG_FILES. It does the exact same thing, with an added bonus...

Currently we're missing version.py.in in the EXTRA_DIST. Thus a simple
"touch Makefile" should retrigger the regeneration of version.py. Which
would presumably fail, since the input file isn't in the distribution
tarball.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agoshared: annotate local API as static
Emil Velikov [Tue, 21 Feb 2023 13:19:28 +0000 (13:19 +0000)] 
shared: annotate local API as static

None of the API is used outside of the compilation unit.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agolibkmod: annotate kmod_builtin_iter API as static
Emil Velikov [Tue, 21 Feb 2023 13:19:27 +0000 (13:19 +0000)] 
libkmod: annotate kmod_builtin_iter API as static

It's no longer used outside the compilation unit, as of last commit.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agolibkmod: remove unused kmod_module_get_builtin
Emil Velikov [Tue, 21 Feb 2023 13:19:26 +0000 (13:19 +0000)] 
libkmod: remove unused kmod_module_get_builtin

The last and only user was removed with commit 0246e06 ("depmod: Stop
opening modules.modinfo once per module")

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agotestsuite: Handle different sysconfdir
Lucas De Marchi [Thu, 9 Feb 2023 19:19:46 +0000 (11:19 -0800)] 
testsuite: Handle different sysconfdir

Instead of skipping tests if sysconfdir isn't /etc, just handle it
during the rootfs setup logic.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2 years agotestsuite: Move setup-rootfs logic from Makefile to script
Lucas De Marchi [Thu, 9 Feb 2023 19:19:45 +0000 (11:19 -0800)] 
testsuite: Move setup-rootfs logic from Makefile to script

It's easier to implement the logic outside of the Makefile, so rename
the populate-modules.sh script to setup-rootfs.sh and move the
additional logic from the makefile to the script.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2 years agolibkmod: error out on unknown hash algorithm
Emil Velikov [Mon, 6 Feb 2023 14:32:59 +0000 (14:32 +0000)] 
libkmod: error out on unknown hash algorithm

Currently if we see unknown algorithm, we'll do an OOB read in
pkey_hash_algo. This can happen for example if OPENSSL_NO_SM3 is set and
the kernel module uses a SM3 hash.

Cc: Mikhail Novosyolov <m.novosyolov@rosalinux.ru>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agotestsuite/depmod: use defines for the rootfs/lib_modules
Emil Velikov [Mon, 6 Feb 2023 14:04:49 +0000 (14:04 +0000)] 
testsuite/depmod: use defines for the rootfs/lib_modules

The uname used across the tests is same, so drop "_ORDER" from the macro
name and use it throughout. Similarly - add respective LIB_MODULES
defines and use them in the tests.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agotestsuite: add function declarations for __xstat family
Emil Velikov [Mon, 6 Feb 2023 14:04:47 +0000 (14:04 +0000)] 
testsuite: add function declarations for __xstat family

As the inline comment says - the declarations have been dropped with
glibc 2.32.9000, as a result the build throws a set of lovely warnings.

Inspired by umockdev, which bears the same license as this project.
https://github.com/martinpitt/umockdev/commit/f1b416400479d861deffb4c5a40422dcdf190e85

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agotreewide: add some static const notations
Emil Velikov [Mon, 6 Feb 2023 14:04:46 +0000 (14:04 +0000)] 
treewide: add some static const notations

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

This option is equivalent to basedir, with the small difference being
that's where the meta-data files are generated. In other words, this
allows us to have read-only input modules and modules.dep, while still
being able to generate the meta-data files.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
[ Move files to a different dir so input files (produced by kernel build
  system is separate from the files generated by depmod (output) ]
Signed-off-by: Lucas De Marchi <lucas.demarchi@gmail.com>
2 years agoman/rmmod: explain why modprobe -r is more useful
Yauheni Kaliuta [Thu, 2 Feb 2023 13:47:36 +0000 (15:47 +0200)] 
man/rmmod: explain why modprobe -r is more useful

Improve user experience by explaining the option so the user may
not search explanations in other manpages (modprobe).

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agomodprobe: Allow passing path to module
Gustavo Sousa [Fri, 13 Jan 2023 21:37:45 +0000 (18:37 -0300)] 
modprobe: Allow passing path to module

This is useful to kernel module developers for testing a just compiled
module: instead of using insmod, they can load the module from the path
while getting all the benefits of modprobe (e.g. module dependency
resolution).

v2:
  - Add test for relative path as well. (Lucas)
  - Add note warning about modules with dependencies not matching the
    installed depmod database. (Lucas)

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agomodprobe: Move insertion block into separate function
Gustavo Sousa [Fri, 13 Jan 2023 21:37:44 +0000 (18:37 -0300)] 
modprobe: Move insertion block into separate function

That same logic will be used for enabling modprobe for paths in the next
patch. As such, prepare for that by extracting that block into its own
function.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agotestsuite: Wrap chdir()
Gustavo Sousa [Fri, 13 Jan 2023 21:37:43 +0000 (18:37 -0300)] 
testsuite: Wrap chdir()

One of the tests in an upcoming patch will need to change into a
specific directory to test loading a module from a relative path.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agokmod: configure.ac: In _Noreturn check, include <stdlib.h> for exit
Florian Weimer [Sat, 17 Dec 2022 16:52:34 +0000 (17:52 +0100)] 
kmod: configure.ac: In _Noreturn check, include <stdlib.h> for exit

Otherwise, an implicit functiona declaration is used, causing
a C99 compatibility issue.

Signed-off-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agoautogen.sh: remove --with-rootprefix, it is gone since kmod-11
Adam Gołębiowski [Mon, 28 Nov 2022 09:05:31 +0000 (10:05 +0100)] 
autogen.sh: remove --with-rootprefix, it is gone since kmod-11

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

Example kernel module:
https://file-store.rosalinux.ru/download/7281f97e0c04c0f818ad3f936706f4a407e8dc7e
(/lib/modules/5.15.67-generic-1rosa2021.1-x86_64/kernel/drivers/usb/host/xhci-pci.ko.zst)
It is signed with Streebog 512.

libkmod v30 crashed in libkmod-module.c:2413 in this code:

n = kmod_module_info_append(list,
"sig_hashalgo", strlen("sig_hashalgo"),
sig_info.hash_algo, strlen(sig_info.hash_algo));

because strlen() got null.

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

When _FILE_OFFSET_BITS is 64, glibc headers turn `stat` calls into
`stat64`, and our `stat` override into a `stat64` function.  However,
because we use dlsym to get the address of libc's `stat`, we end up
calling into the "real" `stat` function, which deals with 32-bit off_t,
and we treat its result as if it were returned from stat64.  On most
architectures this seems to have been harmless, but on 32-bit mips,
st_mode's offset in struct stat and struct stat64 are different, so we
read garbage.

To fix this, explicitly unset _FILE_OFFSET_BITS in path.c, to turn off
the redirect magic in glibc headers, and override both the 32-bit and
64-bit functions so each call ends up wrapping the right libc function.

Fixes #16 (https://github.com/kmod-project/kmod/issues/16)

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

The man page modprobe(8) states for the --syslog option:
"This is also automatically enabled when stderr is unavailable."
but it wasn't happening.

This commit now makes modprobe write to syslog if stderr is closed.

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

During dpkg build, in a subdir, it is currently not possible to run
tests. Building testsuite/modules due to non-existance of the
testsuite directory under the build dir. Thus create it, when it is
not there.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
3 years agotestsuite: repair read of uninitialized memory
Jan Engelhardt [Thu, 30 Jun 2022 16:47:25 +0000 (18:47 +0200)] 
testsuite: repair read of uninitialized memory

Function ``test_backoff_time`` does not initialize ``delta``, and
``get_backoff_delta_msec`` then performs a read from uninitialized
memory with the ``!*delta`` expression.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 years agokmod 30 v30
Lucas De Marchi [Thu, 30 Jun 2022 15:19:17 +0000 (08:19 -0700)] 
kmod 30

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

SM3 has been supported in kernel and cryptographic libraries like openssl.
This patch adds support for the SM3 algorithm of kmod.

Signed-off-by: HuaxinLu <luhuaxin1@huawei.com>
3 years agoREADME: Update optional dependencies
Lucas De Marchi [Wed, 29 Jun 2022 05:24:41 +0000 (22:24 -0700)] 
README: Update optional dependencies

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

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

Retry module removal if it fails due to EAGAIN. This allows user to pass
--wait <timeout>, during which `modprobe -r` will keep trying to remove
the module.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
3 years agotestsuite: Add tests for sleep calculation
Lucas De Marchi [Fri, 3 Jun 2022 21:50:46 +0000 (14:50 -0700)] 
testsuite: Add tests for sleep calculation

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>