]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
3 years agotestsuite: allow to re-use single function for tests
Lucas De Marchi [Fri, 12 Feb 2021 09:45:23 +0000 (01:45 -0800)] 
testsuite: allow to re-use single function for tests

Add a new DEFINE_TEST_WITH_FUNC() that accepts the function
alongside the test name. This will allow us to share a single function
for different tests.

3 years agolibkmod-config: re-quote option from kernel cmdline
Lucas De Marchi [Fri, 12 Feb 2021 09:45:22 +0000 (01:45 -0800)] 
libkmod-config: re-quote option from kernel cmdline

It was reported that grub mangles the kernel cmdline. It turns

acpi_cpufreq.dyndbg="file drivers/cpufreq/acpi-cpufreq.c +mpf"

into

"acpi_cpufreq.dyndbg=file drivers/cpufreq/acpi-cpufreq.c +mpf"

However, even though we could blame grub for doing that, the kernel
happily accepts and re-quotes it when the module is built-in.
So, it's better if kmod also understands it this way and does the same.

Here we basically add additional code to un-mangle it, moving the quote
in way that is acceptable to pass through init_module(). Note that the
interface [f]init_module() gives us mandates the quote to be part of the
value: the module name is not passed and the options are separated by
space.

Reported-by: Jiri Slaby <jirislaby@kernel.org>
Tested-by: Jessica Yu <jeyu@kernel.org>
Link: https://bugzilla.suse.com/show_bug.cgi?id=1181111#c10
3 years agolibkmod-config: revamp kcmdline parsing into a state machine
Lucas De Marchi [Fri, 12 Feb 2021 09:45:21 +0000 (01:45 -0800)] 
libkmod-config: revamp kcmdline parsing into a state machine

The handling of spaces and quotes is becoming hard to maintain. Convert
the parser into a state machine so we can check all the states. This
should make it easier to fix a corner case we have right now:
The kernel also accepts a quote before the module name instead of the
value. But this additional is left for later. This is purely an
algorithm change with no behavior change.

Tested-by: Jessica Yu <jeyu@kernel.org>
3 years agotestsuite: also test xz compression
Lucas De Marchi [Sat, 30 Jan 2021 02:34:30 +0000 (18:34 -0800)] 
testsuite: also test xz compression

Reviewed-by: Petr Vorel <pvorel@suse.cz>
3 years agotestsuite: compress modules if feature is enabled
Lucas De Marchi [Sat, 30 Jan 2021 02:28:38 +0000 (18:28 -0800)] 
testsuite: compress modules if feature is enabled

Since the output needs to be the same, regardless if the module is
compressed, change populate-modules.sh to conditionally compress the
module if that feature is enabled.

This way we can execute the tests with any build-time configuration and
it should still pass.

Suggested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Michal Suchánek <msuchanek@suse.de>
Tested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
3 years agopopulate-modules: Use more bash, more quotes
Dave Reisner [Wed, 25 Mar 2020 15:03:58 +0000 (11:03 -0400)] 
populate-modules: Use more bash, more quotes

We're already using associatives arrays, so there's no reason we should
be using 'test'.

3 years agoREADME: make github mirror official
Lucas De Marchi [Thu, 21 Jan 2021 02:50:33 +0000 (18:50 -0800)] 
README: make github mirror official

For some time I've been maintaining a read-only mirror on github.
I think it's time to allow patches flowing from there besides the
mailing list: I created a new org to host the project:

https://github.com/kmod-project/kmod

3 years agoSupport /usr/local for configuration files
Lucas De Marchi [Tue, 19 Jan 2021 02:22:31 +0000 (18:22 -0800)] 
Support /usr/local for configuration files

Add /usr/local to the search path for configuration files. These are
intended for local installs, provided /usr/local is given as prefix.

3 years agodepmod: fix precedence order
Lucas De Marchi [Tue, 19 Jan 2021 02:13:25 +0000 (18:13 -0800)] 
depmod: fix precedence order

Configuration in /etc should have higher prio than /run.
Given how rarely configuration in /run is used with depmod, this is
likely not to cause any problems, even if it's a change in behavior.

3 years agolibkmod: Fix documentation on config precedence order
Lucas De Marchi [Tue, 19 Jan 2021 02:05:09 +0000 (18:05 -0800)] 
libkmod: Fix documentation on config precedence order

/etc is has higher priority than /run.

3 years agoFix "modinfo -F always shows name for built-ins"
Marco d'Itri [Fri, 8 Jan 2021 04:17:48 +0000 (20:17 -0800)] 
Fix "modinfo -F always shows name for built-ins"

Bug reported by Ben Hutchings <ben@decadent.org.uk>:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=970871

Now that the kernel provides module information for potentially
modular code that's actually built-in, it's possible to query these
built-ins with "modinfo -F".  However, this doesn't work quite right:

$ modinfo -Flicense e1000e
GPL v2
$ modinfo -Flicense bitrev
name:           bitrev
GPL

3 years agoREADME: remove leftover from semaphoreci
Lucas De Marchi [Fri, 8 Jan 2021 03:51:40 +0000 (19:51 -0800)] 
README: remove leftover from semaphoreci

We are not currently using semaphoreci, so remove leftover status from
README.

3 years agotestsuite: Automatically skip tests that fail when sysconfdir != /etc.
Marius Bakke [Sat, 1 Aug 2020 16:02:22 +0000 (18:02 +0200)] 
testsuite: Automatically skip tests that fail when sysconfdir != /etc.

3 years agotestsuite: Add facility to skip tests.
Marius Bakke [Sat, 1 Aug 2020 16:02:21 +0000 (18:02 +0200)] 
testsuite: Add facility to skip tests.

The Makefile helpfully warns that some tests will fail when
--sysconfdir != /etc, but there are no provisions to easily disable
those.  This commit provides an escape hatch.

[ Lucas: add comment detailing the purpose of the field ]

3 years agokmod 28 v28
Lucas De Marchi [Thu, 7 Jan 2021 18:43:36 +0000 (10:43 -0800)] 
kmod 28

3 years agobuild: add comment with rules for libtool version update
Lucas De Marchi [Thu, 7 Jan 2021 18:26:12 +0000 (10:26 -0800)] 
build: add comment with rules for libtool version update

3 years agobuild: fix distcheck due to missing zstd
Lucas De Marchi [Mon, 28 Dec 2020 01:00:43 +0000 (17:00 -0800)] 
build: fix distcheck due to missing zstd

Enable zstd since it's used in the testsuite.

3 years agotestsuite: add test for empty modules.builtin.aliases.bin
Lucas De Marchi [Fri, 18 Dec 2020 16:02:09 +0000 (08:02 -0800)] 
testsuite: add test for empty modules.builtin.aliases.bin

3 years agoshared: fix UNIQ definition
Lucas De Marchi [Fri, 18 Dec 2020 16:02:08 +0000 (08:02 -0800)] 
shared: fix UNIQ definition

We need a macro indirection for UNIQ to work. Otherwise it won't be
unique at all since it will just append "UNIQ" to the name:

In file included from testsuite/test-init.c:30:

testsuite/testsuite.h:142:27: error: redefinition of ‘stest_load_resourcesUNIQ’

3 years agodepmod: unconditionally write builtin.alias.bin
Lucas De Marchi [Fri, 18 Dec 2020 16:02:07 +0000 (08:02 -0800)] 
depmod: unconditionally write builtin.alias.bin

The file is always created and unless we return an error, the temporary
file is renamed to its final destination. All other places write the
index without checking if the index is empty, so just do the same.

Reported-by: Joe Buehler <aspam@cox.net>
3 years agoci: remove semaphoreci
Lucas De Marchi [Fri, 4 Dec 2020 03:34:28 +0000 (19:34 -0800)] 
ci: remove semaphoreci

It's currently failing and we are already covered by travis-ci.

3 years agoci: update travis distro
Lucas De Marchi [Thu, 3 Dec 2020 21:29:48 +0000 (13:29 -0800)] 
ci: update travis distro

Don't bother with gcc 4.8 vs 4.9, just use the latest one for the
distro. Update travis to ubuntu 20.04 so we can get current
dependencies.

3 years agoNEWS: fix typo
Shuo Wang [Wed, 25 Nov 2020 01:31:21 +0000 (09:31 +0800)] 
NEWS: fix typo

3 years agolibkmod: kmod_log_null: qualify ctx argument as const
Yauheni Kaliuta [Sun, 29 Nov 2020 16:47:37 +0000 (18:47 +0200)] 
libkmod: kmod_log_null: qualify ctx argument as const

kmod_log_null() does not change ctx (does nothing).

Fix warnings

In file included from libkmod/libkmod-index.c:33:
libkmod/libkmod-index.c: In function ‘index_mm_open’:
libkmod/libkmod-index.c:757:6: warning: passing argument 1 of ‘kmod_log_null’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  757 |  DBG(ctx, "file=%s\n", filename);

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
3 years agodepmod: output_builtin_alias_bin: free idx on error path
Yauheni Kaliuta [Sun, 29 Nov 2020 16:47:36 +0000 (18:47 +0200)] 
depmod: output_builtin_alias_bin: free idx on error path

idx is allocated in the beginning but it's not freed if there is
a failure after the allocation.

Change the error path: return immediately if idx allocation fails
and then free it in both success and error path at the end.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
3 years agolibkmod: kmod_builtin_get_modinfo: free modinfo on error
Yauheni Kaliuta [Sun, 29 Nov 2020 16:47:35 +0000 (18:47 +0200)] 
libkmod: kmod_builtin_get_modinfo: free modinfo on error

The function allocates array but on building it if get_string()
fails it returns the error leaving the array allocated. The caller
does not care about it in error case either.

Free it to fix memory leak.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
3 years agoman: fix typo
Samanta Navarro [Sun, 4 Oct 2020 11:43:33 +0000 (11:43 +0000)] 
man: fix typo

3 years agotestsuite: add test for zstd-compressed module
Torge Matthies [Tue, 8 Sep 2020 19:59:21 +0000 (21:59 +0200)] 
testsuite: add test for zstd-compressed module

I took away one module from the gzip-compressed modules for this purpose.

Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
3 years agoadd Zstandard compression support
Torge Matthies [Tue, 8 Sep 2020 19:59:20 +0000 (21:59 +0200)] 
add Zstandard compression support

I changed the style of the hackargs variable in autogen.sh to multiline
because said line was becoming a bit long with the new --with-zstd arg
added.

A previous version of this patch has been running on my two Arch Linux
installations (with an accompanying mkinitcpio patch) for several months
over many kernel updates without any issues.
Any additional testing and/or patch review would of course be appreciated.

Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
4 years agotestsuite: add check for kmod_load_resources
Lucas De Marchi [Tue, 10 Mar 2020 05:00:29 +0000 (22:00 -0700)] 
testsuite: add check for kmod_load_resources

Make sure we can call kmod_load_resources when we do have all the
mandatory indexes in place.

4 years agolibkmod: allow modules.alias.builtin to be optional
Lucas De Marchi [Tue, 10 Mar 2020 05:00:28 +0000 (22:00 -0700)] 
libkmod: allow modules.alias.builtin to be optional

4 years agolibkmod: fix return error when opening index
Lucas De Marchi [Tue, 10 Mar 2020 05:00:27 +0000 (22:00 -0700)] 
libkmod: fix return error when opening index

When calling kmod_load_resources() we could end up getting a bogus
return value -ENOMEM due to several other reasons, like the index not
existing. Change index_mm_open() to propagate the failure reason so we
can take actions on it or return to the caller.

4 years agolibkmod: simplify lookup when builtin.modinfo.bin file is missing
Lucas De Marchi [Tue, 10 Mar 2020 05:00:26 +0000 (22:00 -0700)] 
libkmod: simplify lookup when builtin.modinfo.bin file is missing

When we try to lookup a module and builtin.modinfo.bin is missing, we
would do the right thing because the caller was replacing the return
code with 0 (and the list was not modified).

Make it simpler by allowing the caller to check and differentiate the
errors between module not found and index not found.

4 years agodepmod: do not output .bin to stdout
Lucas De Marchi [Thu, 5 Mar 2020 21:33:10 +0000 (13:33 -0800)] 
depmod: do not output .bin to stdout

index_write() relies on fseek/ftell to manage the position to which we
are write and thus needs the file stream to support it.

Right now when trying to write the index to stdout we fail with:

depmod: tools/depmod.c:416: index_write: Assertion `initial_offset >= 0' failed.
Aborted (core dumped)

We have no interest in outputting our index to stdout, so just skip it
like is done with other indexes.

While at it, add/remove some newlines to improve readability.

Reported-by: Yanko Kaneti <yaneti@declera.com>
Fix: b866b2165ae6 ("Lookup aliases in the modules.builtin.modinfo")

4 years agotestsuite: check for ill-formed kcmdline
Lucas De Marchi [Tue, 10 Mar 2020 08:17:12 +0000 (01:17 -0700)] 
testsuite: check for ill-formed kcmdline

Commit ca3bf5d47cec ("iommu/amd: Introduces ivrs_acpihid kernel parameter")
in the kernel introduced an ill-formed kernel parameter, ivrs_acpihid.
The problem is that it may have a dot on the key side:
"ivrs_acpihid[00:14.5]=AMD0020:0". This could potentially trip our
parser of module options, but right now it's working as intended: the
only thing that happens is that after deciding "ivrs_acpihid[00:14" is a
module name, it will fail the underscores() routine and the option will
be ignored from the kmod pov (not kernel's pov since that driver parsers
the kernel command line by itself).

4 years agolibkmod: ignore kcmdline option if we fail to parse modname
Lucas De Marchi [Tue, 10 Mar 2020 08:06:39 +0000 (01:06 -0700)] 
libkmod: ignore kcmdline option if we fail to parse modname

The error message is saying we are ignoring the option on the kernel
command line, so just do it.

4 years agogitignore: ignore .cache.mk when building modules
Lucas De Marchi [Tue, 10 Mar 2020 04:46:32 +0000 (21:46 -0700)] 
gitignore: ignore .cache.mk when building modules

4 years agogitignore: ignore release files
Lucas De Marchi [Fri, 28 Feb 2020 20:53:47 +0000 (12:53 -0800)] 
gitignore: ignore release files

4 years agokmod 27 v27
Lucas De Marchi [Tue, 18 Feb 2020 23:54:07 +0000 (15:54 -0800)] 
kmod 27

4 years agolibkmod: reset was_space on second pass
Lucas De Marchi [Mon, 20 Jan 2020 19:15:38 +0000 (16:15 -0300)] 
libkmod: reset was_space on second pass

The softdep config parser uses a 2-pass approach to use a single
allocation for all the softdep struct. However "was_space" variable
isn't reset between them. This can lead to a buffer overflow.

Reported-by: Jorge Lucangeli Obes <jorgelo@google.com>
Link: https://lore.kernel.org/linux-modules/CAKYuF5QhGCPCazHQjN-=kFc5kHs7Ok8WqmmGLo31CiOEN8TYdA@mail.gmail.com
4 years agolibkmod-module: convert return value from system() to errno
Topi Miettinen [Mon, 23 Dec 2019 16:58:13 +0000 (18:58 +0200)] 
libkmod-module: convert return value from system() to errno

Don't use exit status of a command directly as errno code, callers
will be confused.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
4 years agomodinfo: Show information about built-in modules
Alexey Gladkov [Fri, 8 Nov 2019 17:25:23 +0000 (18:25 +0100)] 
modinfo: Show information about built-in modules

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
4 years agoLookup aliases in the modules.builtin.modinfo
Alexey Gladkov [Fri, 8 Nov 2019 17:25:22 +0000 (18:25 +0100)] 
Lookup aliases in the modules.builtin.modinfo

New modules.builtin.modinfo duplicates modules.builtin in the built-in
module name search. If it exists, then we can use this file, but if not,
then we need to fallback to the old file.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
4 years agolibkmod: Add function to get list of built-in modules
Alexey Gladkov [Fri, 8 Nov 2019 17:25:21 +0000 (18:25 +0100)] 
libkmod: Add function to get list of built-in modules

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
4 years agolibkmod: Add parser for modules.builtin.modinfo
Alexey Gladkov [Fri, 8 Nov 2019 17:25:20 +0000 (18:25 +0100)] 
libkmod: Add parser for modules.builtin.modinfo

The kernel since version v5.2-rc1 exports information about built-in
modules in the modules.builtin.modinfo. Information is stored in
the same format as in the separate modules (null-terminated string
array). The module name is a prefix for each line.

$ tr '\0' '\n' < modules.builtin.modinfo
ext4.softdep=pre: crc32c
ext4.license=GPL
ext4.description=Fourth Extended Filesystem
ext4.author=Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others
ext4.alias=fs-ext4
ext4.alias=ext3
ext4.alias=fs-ext3
ext4.alias=ext2
ext4.alias=fs-ext2
md_mod.alias=block-major-9-*
md_mod.alias=md
md_mod.description=MD RAID framework
md_mod.license=GPL
md_mod.parmtype=create_on_open:bool
md_mod.parmtype=start_dirty_degraded:int
...

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
4 years agoMakefile.am: filter -Wl,--no-undefined
Fabrice Fontaine [Mon, 18 Nov 2019 21:56:17 +0000 (22:56 +0100)] 
Makefile.am: filter -Wl,--no-undefined

Commit 1d14ef82f4a3be741bcdf6b1c6d51ce9dce43567 does not completely fix
the build with python 3.8 as we still get link failure due to
'-z undefs' being ignored by some versions of ld.

Indeed, -z undefs was added by commit
97a232d7335f3bd0231fd9cd39455bde1d563922 in upstream binutils, and this
commit was first present in binutils 2.30.
So any toolchain using binutils version older than that won't have
-z undefs and will build fail on:

/home/buildroot/autobuild/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/mips-linux-gnu/5.3.0/../../../../mips-linux-gnu/bin/ld: warning: -z undefs ignored.

/home/naourr/work/instance-1/output-1/host/opt/ext-toolchain/bin/../lib/gcc/aarch64_be-linux-gnu/7.3.1/../../../../aarch64_be-linux-gnu/bin/ld: warning: -z undefs ignored.

So filter -Wl,--no-undefined to fix the issue

Fixes:
 - http://autobuild.buildroot.org/results/e9645d9969481b09f507f6e0d0b35faaa283eb60
 - http://autobuild.buildroot.org/results/06a6d865b6b7d8ebd793bde214f4a4c40e0962e1

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
4 years agomodprobe: use flags rather than bool args
Lucas De Marchi [Thu, 7 Nov 2019 07:27:28 +0000 (23:27 -0800)] 
modprobe: use flags rather than bool args

It's easier to know what the caller is doing when we pass a named
flag rather than a list of bools.

4 years agotravis: remove old compiler failing to build kernel module
Lucas De Marchi [Thu, 7 Nov 2019 16:34:15 +0000 (08:34 -0800)] 
travis: remove old compiler failing to build kernel module

This is when building the kernel modules for testsuite:

Makefile:718: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
gcc: error: unrecognized command line option ‘-fstack-protector-strong’

Just drop gcc 4.8 from running tests. Failure not really related to kmod.

4 years agotestsuite: update gitignore
Lucas De Marchi [Thu, 7 Nov 2019 07:30:16 +0000 (23:30 -0800)] 
testsuite: update gitignore

4 years agomodprobe: ignore builtin module on recursive removing
Yauheni Kaliuta [Thu, 31 Oct 2019 18:12:53 +0000 (20:12 +0200)] 
modprobe: ignore builtin module on recursive removing

If there are built-in dependencies and any of them is built-in in
the kernel, modprobe -r fails with

modprobe: FATAL: Module module_name is builtin.

It makes sense to ignore such dependencies for the case when
removing is called for non-top level module.

Example: cifs module, it declares bunch of softdeps and the first
one fails on some kernel configs:

modprobe: FATAL: Module gcm is builtin.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
4 years agoDo not check for undefined symbols when building the Python modules
Thomas Petazzoni [Thu, 24 Oct 2019 17:47:10 +0000 (19:47 +0200)] 
Do not check for undefined symbols when building the Python modules

kmod's configure.ac uses the -Wl,--no-undefined linker flag to verify
at link time that all symbols of shared libraries are available, and
that there are no undefined symbols.

This make perfect sense for regular shared libraries. However, for
Python extensions, which will be dlopen()ed inside the Python
interpreter, it makes less sense.

Since Python 3.8, there is a change in python-config script and
Python's pkg-config file: it no longer links Python extensions with
the libpython library. See
https://docs.python.org/dev/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build
which states:

  On the other hand, pkg-config python3.8 --libs no longer contains
  -lpython3.8. C extensions must not be linked to libpython (except on
  Android and Cygwin, whose cases are handled by the script); this
  change is backward incompatible on purpose. (Contributed by Victor
  Stinner in bpo-36721.)

So, when linking the kmod Python extensions, it currently fails with
numerous unresolved symbols, that were previously provided by
libpython:

/home/test/autobuild/run/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/powerpc64-buildroot-linux-gnu/7.4.0/../../../../powerpc64-buildroot-linux-gnu/bin/ld: libkmod/python/kmod/.libs/list_la-list.o: in function `__Pyx_PyObject_GetAttrStr':
list.c:(.text.__Pyx_PyObject_GetAttrStr+0x48): undefined reference to `PyObject_GetAttr'
/home/test/autobuild/run/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/powerpc64-buildroot-linux-gnu/7.4.0/../../../../powerpc64-buildroot-linux-gnu/bin/ld: libkmod/python/kmod/.libs/list_la-list.o: in function `__pyx_tp_dealloc_4kmod_4list_ModListItem':
list.c:(.text.__pyx_tp_dealloc_4kmod_4list_ModListItem+0x78): undefined reference to `PyObject_CallFinalizerFromDealloc'
/home/test/autobuild/run/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/powerpc64-buildroot-linux-gnu/7.4.0/../../../../powerpc64-buildroot-linux-gnu/bin/ld: libkmod/python/kmod/.libs/list_la-list.o: in function `__pyx_tp_dealloc_4kmod_4list_ModList':
list.c:(.text.__pyx_tp_dealloc_4kmod_4list_ModList+0x30): undefined reference to `PyErr_Fetch'

[Complete log at http://autobuild.buildroot.net/results/79a/79a5a0398723e8cfea0d0aa3dec5f7649aee4c63/build-end.log]

Linking with libpython is no longer recommended: those symbols should
remain unresolved in the Python extensions, as they wil be properly
resolved when the Python extension gets loaded into the Python
interpreter.

Since we want to keep -Wl,--no-undefined globally in kmod, we leave
the configure.ac file unchanged, and instead, specifically in the
LDFLAGS used to build the Python extensions, we override
-Wl,--no-undefined with -Wl,-z,undefs. Ideally, -Wl,--no-undefined is
the same as -Wl,-z,defs, and the effect of these options can be
canceled on the linker command line by a following -Wl,-z,undefs (see
the ld man page for details).

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Victor Stinner <victor.stinner@gmail.com>
4 years agolibkmod-signature: use PKCS#7 instead of CMS
Stefan Strogin [Sun, 19 May 2019 00:42:01 +0000 (03:42 +0300)] 
libkmod-signature: use PKCS#7 instead of CMS

Linux uses either PKCS #7 or CMS for signing modules (see
scripts/sign-file.c). CMS is not supported by LibreSSL or older OpenSSL,
so PKCS #7 is used on systems with these libcrypto providers.

CMS and PKCS #7 formats are very similar. CMS is newer but is as much as
possible backward compatible with PKCS #7 [1]. PKCS #7 is supported in
the latest OpenSSL as well as CMS. The fields used for signing kernel
modules are supported both in PKCS #7 and CMS.

For now modinfo uses CMS with no alternative requiring OpenSSL 1.1.0 or
newer.

Use PKCS #7 for parsing module signature information, so that modinfo
could be used both with OpenSSL and LibreSSL.

[1] https://tools.ietf.org/html/rfc5652#section-1.1

Changes v1->v2:
- Don't use ifdefs for keeping redundant CMS code, just use PKCS #7 both
with OpenSSL and LibreSSL.

Signed-off-by: Stefan Strogin <steils@gentoo.org>
5 years agotools: Print a message if refcnt attribute is missing
Ezequiel Garcia [Fri, 8 Mar 2019 20:39:07 +0000 (17:39 -0300)] 
tools: Print a message if refcnt attribute is missing

Currently, check_module_inuse returns a wrong user message
if the kernel is built without module unloading support.

Fix it by returning a more specific error, in case 'refcnt'
attribute is missing.

5 years agobuild: Stop using dolt
Adrian Bunk [Wed, 20 Feb 2019 12:22:04 +0000 (14:22 +0200)] 
build: Stop using dolt

This does regress "make -12" from 0.7s to 0.9s on my
Coffee Lake machine, but even on slower hardware this
will not amount to a noticable slowdown.

On the other hand using dolt can create problems for
people doing cross-compilation, e.g. Yocto has two
hacks just for dolt in kmod:
https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-kernel/kmod/kmod.inc?id=a17abae00785c76cfffe5381a22fb2c86b982e82

(Lucas: remove leftover entry in Makefile and reformat commit message)

5 years agoLink against libcrypto, not all of openssl
Dave Reisner [Wed, 13 Feb 2019 15:27:51 +0000 (10:27 -0500)] 
Link against libcrypto, not all of openssl

In the previous build setup, libkmod.so would link to not just
libcrypto.so, but also libssl.so:

$ readelf -d /lib/libkmod.so | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [liblzma.so.5]
 0x0000000000000001 (NEEDED)             Shared library: [libz.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libssl.so.1.1]
 0x0000000000000001 (NEEDED)             Shared library: [libcrypto.so.1.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

We don't need any symbols from libssl, though. This patch ensures that
we pass 'libcrypto' to pkgconfig rather than 'openssl', getting only the
library that we need:

$ readelf -d  ./libkmod/.libs/libkmod.so.2.3.4 | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [liblzma.so.5]
 0x0000000000000001 (NEEDED)             Shared library: [libz.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libcrypto.so.1.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

5 years agokmod 26 v26
Lucas De Marchi [Thu, 7 Feb 2019 21:46:40 +0000 (13:46 -0800)] 
kmod 26

5 years agobuild: fix make distcheck
Lucas De Marchi [Thu, 7 Feb 2019 21:44:39 +0000 (13:44 -0800)] 
build: fix make distcheck

Make sure to add the dummy.pkcs7 file to the dist files.

While at it, also change the distcheck flags to include --with-openssl.

5 years agotestsuite: mkosi: update files
Lucas De Marchi [Tue, 5 Feb 2019 00:01:01 +0000 (16:01 -0800)] 
testsuite: mkosi: update files

  - Add openssl
  - Disable python (quick hack to avoid more dependencies)
  - Update Fedora to 29

5 years agobuild: check openssl version
Lucas De Marchi [Mon, 4 Feb 2019 23:02:20 +0000 (15:02 -0800)] 
build: check openssl version

5 years agobuild: add openssl to CI deps
Lucas De Marchi [Mon, 4 Feb 2019 22:34:51 +0000 (14:34 -0800)] 
build: add openssl to CI deps

Travis-ci is at most on Ubuntu 16.04, that doesn't have openssl >= 1.1,
so disable openssl there.

Semaphore 2.0 was also missing a call to update the package database.

5 years agobuild: enable openssl by default
Lucas De Marchi [Mon, 4 Feb 2019 22:27:29 +0000 (14:27 -0800)] 
build: enable openssl by default

Like with other features, let's enable it for developers.

5 years agotestsuite: fix modinfo test without openssl
Lucas De Marchi [Mon, 4 Feb 2019 22:25:03 +0000 (14:25 -0800)] 
testsuite: fix modinfo test without openssl

5 years agolibkmod-signature: implement pkcs7 parsing with openssl
Yauheni Kaliuta [Fri, 1 Feb 2019 20:20:02 +0000 (22:20 +0200)] 
libkmod-signature: implement pkcs7 parsing with openssl

The patch adds data fetching from the PKCS#7 certificate using
openssl library (which is used by scripts/sign-file.c in the linux
kernel to sign modules).

In general the certificate can contain many signatures, but since
kmod (modinfo) supports only one signature at the moment, only first
one is taken.

With the current sign-file.c certificate doesn't contain signer
key's fingerprint, so "serial number" is used for the key id.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
5 years agotestsuite: add modinfo pkcs7 signature test
Yauheni Kaliuta [Fri, 1 Feb 2019 20:36:41 +0000 (22:36 +0200)] 
testsuite: add modinfo pkcs7 signature test

Use the same approach to generate the signed module, like in the
old signature test: just append the pregenerated binary signature
to the module (the signature check will fail).

In case of need of generating correct signature, from the linux
kernel makefiles (certs/Makefile) it could be like:

$ openssl req -new -nodes -utf8  -sha256 -days 36500 -batch -x509
-config  ./x509.genkey -outform PEM -out signing_key.pem -keyout signing_key.pem
$ /lib/modules/$(uname -r)/build/scripts/extract-cert signing_key.pem signing_key.x509
$ /lib/modules/$(uname -r)/build/scripts/sign-file sha256 signing_key.pem signing_key.x509 module.ko

where x509.genkey is:

```
[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
prompt = no
string_mask = utf8only
x509_extensions = myexts

[ req_distinguished_name ]
CN = Build time autogenerated kernel key

[ myexts ]
basicConstraints=critical,CA:FALSE
keyUsage=digitalSignature
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
```

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
5 years agoman: Fix typo
Daniel Kahn Gillmor [Sat, 12 Jan 2019 17:22:19 +0000 (12:22 -0500)] 
man: Fix typo

5 years agotestsuite: factor out fd related parameters to a structure
Yauheni Kaliuta [Fri, 4 Jan 2019 21:41:34 +0000 (23:41 +0200)] 
testsuite: factor out fd related parameters to a structure

This is a more abstract implementation of "file descriptor
comparation". With the current implementation the code is full of
conditions based on the descriptor type. It makes sense to
initialize the parameters once based on the descriptor type.

stdout and stderr are handled in almost the same way, but for
monitor descriptor branch, based on the type check is necessary in
some cases.

Since epoll's context now contains pointers to the structures, so no
direct manipulations there.

Most of the patch is just replacing direct buffer manipulations with
the structures' ones.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
5 years agotestsuite: track number of descriptors instead of their state
Yauheni Kaliuta [Fri, 4 Jan 2019 21:41:33 +0000 (23:41 +0200)] 
testsuite: track number of descriptors instead of their state

use the number of tracked descriptors to determine the end of the
loop.

This is a preparation for more abstract descriptor comparation
implementation where checking of the descriptor state may be more
expensive than just checking of the local variables.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
5 years agoAdd semaphoreci 2.0 configuration
Lucas De Marchi [Tue, 18 Dec 2018 22:11:58 +0000 (14:11 -0800)] 
Add semaphoreci 2.0 configuration

Add another CI as alternative to travis-ci. Test on gcc 6, 7 and 8 on
Ubuntu 18.04. Not sure if this is the best way to define the yml file,
but it works.

The old badge doesn't work. It will be added back later.

5 years agotestsuite: move --show-exports test to use regex
Lucas De Marchi [Tue, 18 Dec 2018 23:37:35 +0000 (15:37 -0800)] 
testsuite: move --show-exports test to use regex

This allows it to pass if the kernel is configured with
CONFIG_MODVERSIONS.

5 years agotestsuite: add support for testing output against regex
Lucas De Marchi [Tue, 18 Dec 2018 23:36:11 +0000 (15:36 -0800)] 
testsuite: add support for testing output against regex

Allow to test outputs when they don't match exactly, but should follow
some regex patterns. This can be used when the info we are printing is
randomized or depends on kernel configuration.

5 years agotestsuite: split out function to compare outputs exactly
Lucas De Marchi [Tue, 18 Dec 2018 21:42:09 +0000 (13:42 -0800)] 
testsuite: split out function to compare outputs exactly

Move functionality to compare the exact output to a separate function
and allocate one buffer per output/match pair. This will allow us to
extend this to allow other types of comparisons. Since now we are using
heap-allocated buffer, keep the buffer allocation to the caller, so we
don't have to allocate and free it on every invocation. It also avoids
the different comparison functions to have to deal with it.

5 years agodepmod: shut up gcc insufficinet buffer warning
Michal Suchanek [Mon, 10 Dec 2018 21:29:34 +0000 (22:29 +0100)] 
depmod: shut up gcc insufficinet buffer warning

In a couple of places depmod concatenates the module directory and filename
with snprintf. This can technically overflow creating an unterminated string if
module directory name is long. Use openat instead as is done elsewhere in
depmod. This avoids the snprintf, the extra buffer on stack, and the gcc
warning. It may even fix a corner case when the module direcotry name is just
under PATH_MAX.

[ Lucas: fix up coding style and closing fd on error path ]

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
5 years agodepmod: prevent module dependency files corruption due to parallel invocation.
Michal Suchanek [Mon, 17 Dec 2018 22:46:28 +0000 (23:46 +0100)] 
depmod: prevent module dependency files corruption due to parallel invocation.

Depmod does not use unique filename for temporary files. There is no
guarantee the user does not attempt to run mutiple depmod processes in
parallel. If that happens a temporary file might be created by
depmod(1st), truncated by depmod(2nd), and renamed to final name by
depmod(1st) resulting in corrupted file seen by user.

Due to missing mkstempat() this is more complex than it should be.
Adding PID and timestamp to the filename should be reasonably reliable.
Adding O_EXCL as mkstemp does fails creating the file rather than
corrupting existing file.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
5 years agodepmod: prevent module dependency files missing during depmod invocation
Michal Suchanek [Mon, 10 Dec 2018 21:29:32 +0000 (22:29 +0100)] 
depmod: prevent module dependency files missing during depmod invocation

depmod deletes the module dependency files before moving the temporary
files in their place. This results in user seeing no dependency files
while they are updated. Remove the unlink call. The rename call should
suffice to move the new file in place and unlink the old one. It should
also do both atomically so there is no window when no dependency file
exists.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
5 years agoRemove bootstrap* scripts
Lucas De Marchi [Mon, 17 Dec 2018 17:52:05 +0000 (09:52 -0800)] 
Remove bootstrap* scripts

Let's just use autogen.sh, no need for wrapper scripts. Now
`autogen.sh c` uses the same recommended options for developing kmod and
also accepts extra arguments.

5 years agoREADME: Add link to mailing list archive
Lucas De Marchi [Fri, 30 Nov 2018 20:37:43 +0000 (12:37 -0800)] 
README: Add link to mailing list archive

We now have a proper archive for the mailing list.

5 years agosignature: do not report wrong data for pkc#7 signature
Yauheni Kaliuta [Fri, 16 Nov 2018 08:56:34 +0000 (10:56 +0200)] 
signature: do not report wrong data for pkc#7 signature

when PKC#7 signing method is used the old structure doesn't contain
any useful data, but the data are encoded in the certificate.

The info getting/showing code is not aware of that at the moment and
since 0 is a valid constant, shows, for example, wrong "md4" for the
hash algo.

The patch splits the 2 mothods of gethering the info and reports
"unknown" for the algo.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
5 years agotestsuite: add simple test for --show-exports
Lucas De Marchi [Tue, 13 Nov 2018 18:45:00 +0000 (10:45 -0800)] 
testsuite: add simple test for --show-exports

5 years agomodprobe: add --show-exports
Yauheni Kaliuta [Tue, 13 Nov 2018 09:00:29 +0000 (11:00 +0200)] 
modprobe: add --show-exports

modprobe has --show-modversions switch, which dumps symbols with
their modversion crcs from the __versions sections.

At the moment the section contains information for the dependency
symbols only, while exported symbols add to symtab entries with
__crc_ prefix (the format may differ, see 1e48901166ef libkmod-elf:
resolve CRC if module is built with MODULE_REL_CRCS).

The patch makes it to show exported symbols as well.

The function is basically cut'n'paste of show_modversions(),
but 'version' family replaced with 'symbol' one.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
5 years agomkosi: allow Clear to use test modules
Lucas De Marchi [Wed, 10 Oct 2018 20:47:50 +0000 (13:47 -0700)] 
mkosi: allow Clear to use test modules

Now Clear has a bundle for the kernel headers, let's use it.

5 years agoman: depmod: remove deprecated -m option
Lucas De Marchi [Fri, 20 Jul 2018 20:23:57 +0000 (13:23 -0700)] 
man: depmod: remove deprecated -m option

Thanks to Howard Johnson <hwj@bridgeportcontractor.com> for noticing.

5 years agokmod: build: cure compiler warnings showing up externally
Jan Engelhardt [Sat, 16 Jun 2018 06:45:20 +0000 (08:45 +0200)] 
kmod: build: cure compiler warnings showing up externally

When building a C source file with gcc-7 -Wshift-overflow=2, this warning
springs up:

libkmod.h: warning: result of "1 << 31" requires 33 bits to
represent, but "int" only has 32 bits [-Wshift-overflow=]

Change the two _KMOD_* identifiers to fit into 32 bits.

5 years agobuild: fix wrong quotes on bootstrap
Jakov Simunic [Wed, 16 May 2018 17:24:37 +0000 (10:24 -0700)] 
build: fix wrong quotes on bootstrap

5 years agoPhrasing correction in modprobe man page
Chris Stackpole [Fri, 20 Apr 2018 19:46:58 +0000 (14:46 -0500)] 
Phrasing correction in modprobe man page

6 years agolibkmod-module: check for NULL before accessing pointers
Luca Bruno [Wed, 7 Mar 2018 10:51:21 +0000 (10:51 +0000)] 
libkmod-module: check for NULL before accessing pointers

This introduces a few missing NULL-checks in public functions, and
align their docstrings with real behavior by getting rid of copy-paste
mistakes.

Signed-off-by: Luca Bruno <luca.bruno@coreos.com>
6 years agotestsuite: raise arch image to 3GB
Lucas De Marchi [Fri, 9 Feb 2018 17:19:53 +0000 (09:19 -0800)] 
testsuite: raise arch image to 3GB

6 years agotestsuite: add Clear's mkosi configuration
Caio Marcelo de Oliveira Filho [Thu, 8 Feb 2018 23:08:22 +0000 (15:08 -0800)] 
testsuite: add Clear's mkosi configuration

Adapted the mkosi.build script to account for not building
test-modules in Clear. It doesn't have the headers available yet.

6 years agokmod 25 v25
Lucas De Marchi [Tue, 9 Jan 2018 01:30:39 +0000 (17:30 -0800)] 
kmod 25

6 years agotestsuite: also wrap gettid in syscall()
Lucas De Marchi [Mon, 8 Jan 2018 16:22:29 +0000 (08:22 -0800)] 
testsuite: also wrap gettid in syscall()

Not a perfect solution for overriding syscall(), but at least
it makes the testsuite to pass in a modified nsswitch.conf (one that has
a module which calls syscall() to get the thread id).

6 years agotestsuite: explain why overriding function may fail
Lucas De Marchi [Wed, 3 Jan 2018 22:14:06 +0000 (14:14 -0800)] 
testsuite: explain why overriding function may fail

On my computer `testsuite/test-modprobe modprobe_install_cmd_loop` was
failing because when it forks off the shell the child process ends up
calling syscall() which are are supposed to wrap. Here's the backtrace:

#0  0x00007ffff6fdb66b in raise () from /lib64/libc.so.6
#1  0x00007ffff6fdd381 in abort () from /lib64/libc.so.6
#2  0x00007ffff77bac97 in syscall (__sysno=<optimized out>)
    at testsuite/init_module.c:362
#3  0x00007fffef92d4e7 in hashmap_base_new.lto_priv () from /lib64/libnss_systemd.so.2
#4  0x00007fffef953f50 in sd_bus_open_system () from /lib64/libnss_systemd.so.2
#5  0x00007fffef943123 in _nss_systemd_getpwuid_r () from /lib64/libnss_systemd.so.2
#6  0x00007ffff707eea5 in getpwuid_r@@GLIBC_2.2.5 () from /lib64/libc.so.6
#7  0x00007ffff707e608 in getpwuid () from /lib64/libc.so.6
#8  0x00005555555859e1 in get_current_user_info.part ()
#9  0x00005555555a375a in initialize_shell_variables ()
#10 0x0000555555580fde in shell_initialize ()
#11 0x00005555555846ff in main ()<Paste>

The reason it fails on my system and not on, for e.g., a new one set up with
mkosi is that the call to getpwuid() depends on the contents
/etc/nsswitch.conf. The systemd module calls syscall() to implement gettid()
which we can't forward due to being a variadic function.

No fix is provided here, but at least it's explained why this happens.

6 years agotestsuite: add missing error handling
Lucas De Marchi [Wed, 3 Jan 2018 21:37:59 +0000 (13:37 -0800)] 
testsuite: add missing error handling

If we passed an invalid argument to a test it would segfault rather than
returning an error code.

6 years agotestsuite: add Fedora's mkosi configuration
Lucas De Marchi [Wed, 3 Jan 2018 19:23:51 +0000 (11:23 -0800)] 
testsuite: add Fedora's mkosi configuration

To use the Fedora configuration rather than the default, one should
use:

# make DISTRO=fedora mkosi

While at it also reduce the root partition size for Arch, since it
doesn't need that much.

6 years agotestsuite: generalize mkosi support for other distros
Lucas De Marchi [Wed, 3 Jan 2018 19:19:02 +0000 (11:19 -0800)] 
testsuite: generalize mkosi support for other distros

Instead of using the mkosi.default symlink, use an env var passed from
the build system. We would need to pass the --default switch nonetheless
or change the symlink, making the git tree dirty.

Also, search for installed kernel headers in a way that's compatible
with more distros. On Fedora, for example, the
/usr/lib/modules/<kver>/build symlink is only available if there's a
kernel installed. We don't care about a kernel installed since we don't
need to boot it on a real machine: the only thing we need is the
kernel-devel package.

6 years agobuild: use tool from configure
Lucas De Marchi [Wed, 3 Jan 2018 02:17:51 +0000 (18:17 -0800)] 
build: use tool from configure

This way we make sure the tool will be the one we actually configured
before going through sudo.

6 years agobuild: add mkosi hooks
Lucas De Marchi [Tue, 2 Jan 2018 22:08:03 +0000 (14:08 -0800)] 
build: add mkosi hooks

Right now there's support for building on Archlinux only.

6 years agodepmod: module_is_higher_priority: fix modname length calculation
Yauheni Kaliuta [Thu, 7 Dec 2017 19:16:08 +0000 (21:16 +0200)] 
depmod: module_is_higher_priority: fix modname length calculation

depmod_module_is_higher_priority checks module's path if it is under
module root directory and if so uses relative to the root path to
lookup the module in override and search lists.

Originally only relative path was used in the function, so the
variables with full path and and path length were changed:

       newpath += cfg->dirnamelen + 1;
       newlen -= cfg->dirnamelen + 1;
       oldpath += cfg->dirnamelen + 1;
       oldlen -= cfg->dirnamelen + 1;

Commit 7da6884e7357ac05772e90f6d7e63b1948103fc4 (depmod: implement
external directories support) changed the logic since it need the
full path to the module for comparations as well.

Unfortunately, it introduce a mistake in calculation of the relative
paths replacing '-=' with assignment to a new variable -- the
'cfg->dirnamelen + 1' value must be substracted all together. It
breaks, for example, overrides lookup.

Fix the calculation by putting braces around the value in the
subsctuction expression.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
6 years agotestsuite: depmod: add override test
Yauheni Kaliuta [Thu, 7 Dec 2017 19:16:07 +0000 (21:16 +0200)] 
testsuite: depmod: add override test

Simple test to check if depmod honors override keyword. Uses
mod-simple.ko for foo/ and override/ directories, search.conf to
search in foo and built-in and simple override configuration:

override mod-simple 4.4.4 override

The resulting modules.dep should point to the override directory.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
6 years agodepmod: Don't add .TOC. when it's in the kernel.
Michal Suchanek [Thu, 7 Dec 2017 14:31:19 +0000 (15:31 +0100)] 
depmod: Don't add .TOC. when it's in the kernel.

d46136bb59c4 ("depmod: Ignore PowerPC64 ABIv2 .TOC. symbol") adds fake
.TOC. unconditionally but when there is .TOC. in the kernel adding the
fake one breaks resolving .TOC.

Fixes: d46136bb59c4 ("depmod: Ignore PowerPC64 ABIv2 .TOC. symbol")
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
6 years agoman/depmod: Add references in other man pages
Christopher Díaz Riveros [Mon, 16 Oct 2017 15:48:42 +0000 (10:48 -0500)] 
man/depmod: Add references in other man pages

Depmod man page is not referenced in some man pages. This makes it
harder to find through reading documentation.

References added to:

-man/insmod.xml
-man/lsmod.xml
-man/modprobe.xml
-man/rmmod.xml

Signed-off-by: Christopher Díaz Riveros <chrisadr@gentoo.org>
6 years agolibkmod-elf: resolve CRC if module is built with MODULE_REL_CRCS
Yauheni Kaliuta [Wed, 19 Jul 2017 14:56:49 +0000 (17:56 +0300)] 
libkmod-elf: resolve CRC if module is built with MODULE_REL_CRCS

Normally exported symbol's crc is stored as absolute (SHN_ABS)
value of special named symbol __crc_<symbol name>.

When the kernel and modules are built with the config option
CONFIG_MODULE_REL_CRCS, all the CRCs are put in a special section
and the __crc_<symbol name> symbols values are offsets in the
section. See patch description of the commit:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=56067812d5b0e737ac2063e94a50f76b810d6ca3

Add kmod support of this configuration.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>