Commit Graph

58 Commits

Author SHA1 Message Date
Emil Velikov 1712a1548e 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>
2023-02-09 07:09:06 -08:00
Gustavo Sousa 883d931d1b 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>
2023-01-13 16:48:02 -08:00
Lucas De Marchi d3a1fe67b6 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
2021-02-15 11:53:43 -08:00
Lucas De Marchi 30c9c4d90f testsuite: add test for empty modules.builtin.aliases.bin 2020-12-27 16:40:08 -08:00
Lucas De Marchi f5434cf5fc 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.
2020-03-23 12:39:58 -07:00
Lucas De Marchi 3c1073e17a 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).
2020-03-13 09:23:58 -07:00
Lucas De Marchi 0f37cf1c18 testsuite: fix modinfo test without openssl 2019-02-04 14:25:03 -08:00
Yauheni Kaliuta dec990483b 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>
2019-02-04 13:49:13 -08:00
Lucas De Marchi eb862179c0 testsuite: move --show-exports test to use regex
This allows it to pass if the kernel is configured with
CONFIG_MODVERSIONS.
2019-01-03 12:43:18 -08:00
Lucas De Marchi 068729e368 testsuite: add simple test for --show-exports 2018-11-13 10:45:00 -08:00
Yauheni Kaliuta 809b9fb6cf 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>
2017-12-07 13:08:00 -08:00
Yauheni Kaliuta df492f5ca3 testsuite: add tests for external directory support
The following tests added:

- depmod_search_order_external_first -- checks if external module
  is taken in use when it has higher priority;
- depmod_search_order_external_last -- checks if external module
  is skipped when it has lower priority;
- test_modinfo_external -- checks if modinfo is able to look up
  correct external module;
- modprobe_external -- checks if modprobe is able to look up
  correct external module and loads it.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-06-01 20:31:37 -07:00
Yauheni Kaliuta 9be03c52cc testsuite: depmod: check netsted loops reporting
The patch adds nested loops configuration for the loop test:

mod-loop-h -> mod-loop-i -> mod-loop-j -> mod-loop-k
   ^                           |               |
    ---------------------------                |
   |                                           |
    -------------------------------------------

making 2 loops with common edges:

mod-loop-h -> mod-loop-i -> mod-loop-j -> mod-loop-h
mod-loop-h -> mod-loop-i -> mod-loop-j -> mod-loop-k -> mod-loop-h

The actual output for the loops is:

depmod: ERROR: Cycle detected: mod_loop_h -> mod_loop_h
depmod: ERROR: Cycle detected: mod_loop_i -> mod_loop_j -> mod_loop_k -> mod_loop_h -> mod_loop_i

(the order in the second doesn't matter, but the first one is
incorrect)

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-02-22 04:50:22 -08:00
Lucas De Marchi 31dd40a6b8 libkmod-config: fix parsing quoted kernel cmdline on params
We can only accept quoted values, not module names or parameter names.
2017-02-16 09:18:35 -08:00
Lucas De Marchi ded0bebca8 testsuite: add test for kernel cmdline with quotes
Add some tests in which we quotes in kernel cmdline and also spaces
inside quotes.  This doesn't yet cover the case in which quotes are used
for module name, wihch should be forbidden.
2017-01-23 11:59:31 -08:00
Mian Yousaf Kaukab 6b77f18896 depmod: ignore related modules in depmod_report_cycles
Only print actual cyclic dependencies. Print count of all the modules
in cyclic dependency at the end of the function so that dependent
modules which are not in cyclic chain can be ignored.

Printing dependent modules which are not in cyclic chain causes buffer
overflow as m->modnamesz is not included in buffer size calculations
(loop == m is never true). This buffer overflow causes kmod to crash.

Update depmod test to reflect the change as well.

Reported-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
2016-11-08 22:38:34 -02:00
Caio Marcelo de Oliveira Filho 037618816c tools: add basic versions of insert and remove 2015-03-07 12:09:51 -03:00
Lucas De Marchi ade6b25c9a testsuite: add test for modprobe -R <builtin-module> 2015-02-28 14:18:54 -03:00
Lucas De Marchi dbf90dc3a8 testsuite: test builtin state
The second test, that creates the module by name and then retrieves the
initstate was broken before b95fa91 ('Fix race while loading modules').
We would check /sys and return either builtin (if the module has
parameters) or give an error because we don't find the module (even if
it's in the modules.builtin index)
2015-02-28 14:18:54 -03:00
Lucas De Marchi 3f0eb43b6d testsuite: port signature-check modules to module-playground
We use a "fake signature" to sign the modules. As far as kmod is
concerned the signature fields are informational only. It's the kernel
the responsible for checking it's valid.

So what we are doing here is: pick the signatures of the ext4-x86_64.ko
module and save as dummy.{hashalgo}. This signature is appended to the
mod-simple.ko module so the ext4-x86_64.ko module can be removed from
tree.
2015-02-21 15:51:42 -02:00
Lucas De Marchi 77fdc66429 testsuite: port arch-specific tests to module-playground
Rename modinfo_jonsmodules() to test_modinfo_signature(): now this test
is responsible only for the signed modules.

The other tests use specific flags to modinfo in order to print only
one field, so we can filter out those fields that are expect to change
if the module is recompiled.
2015-02-21 15:09:12 -02:00
Lucas De Marchi 2a38870e3d testsuite: port modules-order-compressed to module-playground 2015-02-19 19:50:16 -02:00
Lucas De Marchi 246d67d493 testsuite: port kcmdline test to module-playground 2015-02-11 02:59:08 -02:00
Lucas De Marchi 621ac887e7 testsuite: port install-cmd-loop test to module-playground 2015-02-11 02:50:06 -02:00
Lucas De Marchi bf0b87f4e6 testsuite: port alias-to-none test to module-playground 2015-02-10 22:19:53 -02:00
Lucas De Marchi 33c1185239 testsuite: port tests without finit_module() to module-playground 2015-02-10 22:11:25 -02:00
Lucas De Marchi a1a1369051 testsuite: port modprobe --force test to module-playground 2015-02-10 22:01:42 -02:00
Lucas De Marchi 1e128242ed testsuite: port softdep-loop test to module-playground 2015-02-10 21:45:09 -02:00
Lucas De Marchi eeb627004b testsuite: port show-depends tests to module-playground
Another test, modprobe_show_alias_to_none was wrongly checking the
output in the show-depends namespace so it needed changing as well.
2015-02-10 09:30:49 -02:00
Lucas De Marchi d9ab7abe1e testsuite: port detect-loop test to module-playground 2015-02-09 14:07:31 -02:00
Lucas De Marchi 1669be85de testsuite: convert test-init function to use mod-simple.ko 2015-02-03 05:19:38 -02:00
Lucas De Marchi 450c1f037b testsuite: port test-dependencies to module-playground 2015-02-03 01:12:13 -02:00
Lucas De Marchi 8dddac5999 testsuite: use mod-simple.ko for search-order-same-prefix test 2015-02-03 01:09:22 -02:00
Lucas De Marchi 4002d77aff testsuite: beef up module-playground in the build system
Instead of shipping pre-compiled module, this prepares the build system
to be able to compile the necessary modules from module-playground. This
preparations starts by replacing md5.ko with our own dummy
mod-simple.ko, built from source. It works by copying the modules to
their final location while preparing the rootfs.
2015-02-03 01:09:17 -02:00
Caio Marcelo de Oliveira Filho 211e3840fc testsuite: add more input cases to freadline_wrapped test 2015-01-21 10:18:07 -02:00
Lucas De Marchi 9c6084d90c testsuite: improve coverage of shared/util.h
Add tests to improve coverage of shared/util.h functions.
2015-01-14 17:26:36 -02:00
Lucas De Marchi aafd38359a Rename getline_wrapped() to freadline_wrapped() 2014-10-03 03:25:06 -03:00
Lucas De Marchi 7a2d0e6187 testsuite: check for correct error message in detect-loop 2014-05-30 10:26:17 -03:00
Lucas De Marchi 8183cfa9da testsuite: add test to fail depmod on module loops 2014-05-30 09:36:56 -03:00
Lucas De Marchi 3e68b2c455 testsuite: Remove duplicate test
This partially reverts ad7f175 ("Add test for depmod using search dirs
with same prefix"). Testing it twice in the inverted order doesn't
ensure we get the bug with wrong ordering.

As put by Anssi Hannula <anssi@mageia.org>:

	So the bug is triggered only if the shorter name is higher-prio _and_
	shorter name is traversed first. If the long name is traversed first,
	the bug don't trigger with either "search" directive order (and on my
	"make check" runs this is the case).
2014-04-06 17:46:45 -03:00
Michal Marek 73476ec5cb testsuite: Uncompress most modules
Only keep test-depmod/modules-order-compressed to test compressed module
support.
2014-04-04 12:32:16 +02:00
Lucas De Marchi ad7f1757c0 Add test for depmod using search dirs with same prefix
Test depmod with search dirs "foo" and "foobar". Previously to 49b33c1
("depmod: do not allow partial matches with "search" directive") we were
failing this test due to matching the prefix without checking if
it's the full dir name.

We are adding 2 tests here in order to catch the case we only pass the
test due to processing the directories in a favourable order.
2014-03-19 09:22:20 -03:00
Lucas De Marchi aa0abec721 Add test for simple search order in depmod 2014-03-19 08:52:33 -03:00
Lucas De Marchi 49776627e6 testsuite: add test for '.' correctly parsed in param's value
In kcmdline it's possible to have a dot in the param's value. The
support for this was added in 66f3228 ("libkmod: Add support for '.' in
module parameter on kcmdline") and is needed to correctly support some
modules that depend on it.

This test was added in order to make sure the commit  aa87854
("libkmod-config: Only match dot before '=' in /proc/cmdline") didn't
break it. Although that commit  message says it's allowing to match a
dot before '=' it's actually enforcing the first part of the string to
be always in the format "<module-name>.param". Dots after '=' are still
correctly allowed.
2014-03-06 01:36:02 -03:00
Lucas De Marchi 4214902482 testsuite: add test to ignore unrelated strings in kcmdline
Strings unrelated to modules and modprobe should be ignored and not
appear in the output of "modprobe -c".

This adds a test for the fix provided in aa87854 ("libkmod-config: Only
match dot before '=' in /proc/cmdline").
2014-03-06 01:30:56 -03:00
Lucas De Marchi 55bcc4a5bd testsuite: add test for kcmdline params with no value
Use "modprobe -c" to dump the configuration. Since we configure our
rootfs to have only a /proc/cmdline file, this should dump the knowledge
we have from its parsed content.

Test if <module>.option, without any value is correctly parsed, as fixed
in commit 493dc65 ("libkmod: Fix getting param with no value from kcmdline")
2014-03-06 01:29:41 -03:00
Michal Marek be29c40e25 Add some tests for kernels without finit_module(2) 2014-03-05 12:22:37 -03:00
Michal Marek 2ce5de0ae6 testsuite: Add test for modprobe --force
There is no check if the correct flags are passed to finit_module, but
at least we cover the respective code path in kmod.
2014-03-05 12:22:37 -03:00
Lucas De Marchi 1dda626f6b testsuite: add basic test for getline_wrapped 2013-11-18 11:01:16 -02:00
Lucas De Marchi 807c601df2 testsuite: Move test-alias to test-util
Move file so we can use the same file to test other functions from
libkmod-util.c
2013-11-18 04:35:03 -02:00