Commit Graph

1429 Commits

Author SHA1 Message Date
Emil Velikov
83e22ab5e9 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>
2024-07-03 10:14:35 -05:00
Emil Velikov
f3a423b6d8 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>
2024-07-03 10:10:05 -05:00
Jose Ignacio Tornos Martinez
d06712b514 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>
2024-06-14 14:16:17 -05:00
Emil Velikov
a0ed4f8438 .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>
2024-06-14 13:49:03 -05:00
Lucas De Marchi
8837461494 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: 11eb9bc67c ("Use portable implementation for basename API")
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-06-11 08:15:36 -05:00
Lucas De Marchi
22c36b7dac 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>
2024-06-11 08:15:30 -05:00
Shengjing Zhu
68db675078 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>
2024-06-11 07:43:27 -05:00
Khem Raj
11eb9bc67c 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>
2024-06-10 18:15:39 -05:00
Jose Ignacio Tornos Martinez
05828b4a6e 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
2024-05-08 23:37:38 -05:00
Emil Velikov
5a8b16b718 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>
2024-04-30 15:35:37 -05:00
Emil Velikov
045fd571c4 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>
2024-04-30 15:34:28 -05:00
Emil Velikov
61bf8e74b9 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>
2024-04-30 15:33:55 -05:00
Emil Velikov
737744301a 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>
2024-04-30 12:33:52 -05:00
Emil Velikov
0c12738807 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>
2024-04-30 12:33:52 -05:00
Emil Velikov
8cc475f7da 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>
2024-04-30 12:33:52 -05:00
Emil Velikov
81e5c797d0 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>
2024-04-30 12:33:52 -05:00
Emil Velikov
ad15892394 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>
2024-04-30 12:33:52 -05:00
Emil Velikov
90b271fbd2 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>
2024-04-30 12:33:52 -05:00
Emil Velikov
03da2db135 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>
2024-04-30 12:33:52 -05:00
Emil Velikov
09256b9a4f 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>
2024-04-30 12:33:52 -05:00
Emil Velikov
d6cd6c74d2 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>
2024-04-30 12:33:52 -05:00
Lucas De Marchi
b0a78466d0 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>
2024-04-30 09:26:20 -05:00
Lucas De Marchi
93f58b8131 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>
2024-04-29 16:20:30 -05:00
Mike Gilbert
e4130a46dd 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>
2024-03-12 10:30:13 -05:00
Lucas De Marchi
c5054b2150 build: Allow to install over dirty dir
Before commit e98cef6f3f ("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>
2024-03-07 08:21:07 -06:00
Lucas De Marchi
41faa59711 kmod 32 2024-03-05 21:27:42 -06:00
Emil Velikov
dc2440ee31 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>
2024-02-20 16:10:55 -06:00
Emil Velikov
930a40f518 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>
2024-02-20 15:40:16 -06:00
Emil Velikov
e98cef6f3f 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>
2024-02-06 11:31:16 -06:00
Emil Velikov
607abb818a 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>
2024-02-02 12:54:04 -06:00
Lucas De Marchi
b29704cd44 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>
2024-02-02 12:54:04 -06:00
Lucas De Marchi
1043f6f023 testsuite: drop mkosi
It's not being actively used, so drop it.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-02-02 12:54:04 -06:00
Lucas De Marchi
9b8b4af54c 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>
2024-02-02 12:54:04 -06:00
Lucas De Marchi
594f102cf5 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>
2024-02-02 12:54:04 -06:00
Michal Suchanek
48b0c75f79 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>
2023-12-06 09:53:41 -06:00
Michal Suchanek
9d1fb317c8 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>
2023-12-06 09:53:05 -06:00
Dimitri John Ledkov
510c8b7f74 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
2023-11-07 14:05:44 -06:00
Sam James
3af2f475b0 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>
2023-11-05 18:22:05 -06:00
Michal Suchanek
ecef7c1316 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>
2023-10-17 12:27:59 -05:00
Michal Suchanek
8463809f8a 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>
2023-10-17 12:27:59 -05:00
Michal Suchanek
4e7effbdc0 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>
2023-10-17 12:27:59 -05:00
Michal Suchanek
1bb23d7f19 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>
2023-10-17 12:27:59 -05:00
Lucas De Marchi
aff617ea87 kmod 31 2023-09-29 09:18:37 -05:00
Emil Velikov
0140db94c0 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>
2023-09-27 22:37:45 -05:00
Lucas De Marchi
09c9f8c5df 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>
2023-06-20 14:39:25 -07:00
Lucas De Marchi
30077bf171 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>
2023-06-09 10:45:55 -07:00
Lucas De Marchi
e539827635 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>
2023-06-09 10:45:55 -07:00
Lucas De Marchi
e1f0e169de 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>
2023-06-09 10:45:55 -07:00
Lucas De Marchi
7a86f12920 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>
2023-06-09 10:45:51 -07:00
Dmitry Antipov
9c262fdb1c 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>
2023-05-30 22:36:43 -07:00