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).
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.
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.
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.
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>
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>
testsuite/test-depmod.c:31:21: warning: ‘depmod_modules_order_for_compressed’ defined but not used [-Wunused-function]
static noreturn int depmod_modules_order_for_compressed(const struct test *t)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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>
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.
install: cannot stat 'testsuite/module-playground/mod-loop-f.ko': No
such file or directory
Makefile:2881: recipe for target 'rootfs' failed
make[1]: *** [rootfs] Error 1
make[1]: *** Waiting for unfinished jobs....
Makefile:2101: recipe for target 'check-recursive' failed
We need to ship pre-compiled binaries so it's possible to run
"make check" on servers without kernel headers.
Also add them to EXTRA_DIST as other sources.
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>
Check that depmod do not report modules outside cyclic chain
Two modules f and g are added which do not have any dependency.
modules a and b are made dependent on f and g.
Here is the output of loop dependency check test after adding this
patch:
TESTSUITE: ERR: wrong:
depmod: ERROR: Found 7 modules in dependency cycles!
depmod: ERROR: Cycle detected: mod_loop_d -> mod_loop_e -> mod_loop_d
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_b
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_g
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_f
Buffer overflow occurs in the loop when last two lines are printed.
43 bytes buffer is allocated and 53 bytes are used.
Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
The array elements in the tests are strings, what means "char *"
in С. The comparation funtion takes pointers to the elements, so
the arguments become "char **". It means, that strcmp() cannot be
used directrly.
The patch creates a wrapper on strcmp() which perfoms
dereferencing of the "char **" to supply the actual strings to
strcmp(), and uses the wrapper as a comparation function for the
qsort() call.
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
This should fill the requirements for "we need to loop over a lot of
strings that usually are small enough to remain on stack, but we want to
protect ourselves against huge strings not fitting in the static
buffer we estimated as sufficient"
shared/util.c: In function ‘read_str_safe’:
shared/util.c:211:24: warning: logical ‘or’ of equal expressions [-Wlogical-op]
if (errno == EAGAIN || errno == EWOULDBLOCK ||
^~
shared/util.c: In function ‘write_str_safe’:
shared/util.c:237:24: warning: logical ‘or’ of equal expressions [-Wlogical-op]
if (errno == EAGAIN || errno == EWOULDBLOCK ||
^~
This is because EAGAIN and EWOULDBLOCK have the same value. Prefer
EAGAIN, but add a static assert to catch if it's not the same in another
architecture.
Now that we are able to build our own test modules, also allow to use
cached modules so a) kernel headers are not required and b) distro
maintainers are happy. It's still need a "--disable-test-modules" in
the configure since the default is enabled.
There's no license problems anymore since all modules come from our own
repository, we ship the sources and the modules can be easily rebuilt.
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)
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.
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.
This is for convenience for development and testing since we don't want
to needlessly cross-compile the modules. There's a README file
explaining the building process for those who want to update them.
These files are compiled from their respective .c and thus have LPGL
license.
If we were expecting output on stdout or stderr but the test didn't
produce any, we were incorrectly assuming the test was successful.
Now test on exit if there was activity on the monitored fd. If there
was, check also if the file size to check for output is > 0 for the
cases in which we want to assert there was no activity on certain fd.
This adds the needed infra to cross-compile modules so we can test them
in our testsuite. Right now we are only compiling mod-simple.ko for x86,
x86_64 and sparc64.
The makefiles are organized in a way it's easy to force a rebuild of a
module by calling the Makefile.arch directly and that allows the rule in
Makefile to not trigger in case we want to ship the modules
pre-compiled.
Use _builtin_uaddll_overflow/_builtin_uaddl_overflow when available,
abstracting the type to use it with uint64_t.
Otherwise fallback to the implementation as added in 67466f2 ("Prevent
offset + size overflow.").
This also adds the tests for this new helper in the testsuite.
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.
Some tests cover internal API that wasn't used
elsewhere. The choice here was to test and keep the
list implementation complete instead of removing it.
It was not saving _modules in modules and thus all check were falling in
the fallback "consider a success if module is not in the list". Also the
name check wasn't right: replace with streq().
The parsing could be better implemented, but this is left for later.
If we are accessing a file inside the build directory we should really
not trap the path. Right now this isn't important because we never do
such accesses. However it will be needed when gcov is integrated because
it dumps files to the same place where the binaries are located.
Make the includes be libkmod/libkmod.h for code outside of library. This
fixes the broken build after 1315123 ('build-sys: Don't add libkmod
subdirectory to include path').
It has changed in the past, and these days, anyone can get a copy of the
LGPL via the web rather than by post.
Like 657a122 (Remove FSF mailing address) in libabc by Josh Tripplet,
but let the FSF website in which the license can be found.
Intead of having to declare an array of tests, tweak the definition of
DEFINE_TEST and TESTSUITE_MAIN so they know the tests are put in a
particular section of the ELF file.
This avoids the mistake of adding a test and forgetting to add it to the
array. Now once a test is defined, it's ready to run, so one less step
to define new tests.
The removal of the arrays is left for another patch so not to clutter
the diff on this one.
Add assert_return to use in testcases instead of assert. The issues
with assert are:
1) It's disabled when NDEBUG is defined
2) Even if it's well supported by testsuite (the parent will
report the child died) it can't output any meaningful
error message
If a test has expected_fail=true, it means the return code must be
different from 0 *and* the outputs must match. This way it's possible to
check if the error messages are printed as they should.
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).
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.
In a specific configuration (chroot with the linux32 personality), the
modprobe_install_cmd_loop test failed, because the bash process handling
the install command segfaulted. The backtrace showed a uname() call
during libpthread initialization, at which point the environ pointer
hadn't been initialized yet:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x080c1591 in getenv (name=<optimized out>,
name@entry=0xf775f850 "TESTSUITE_UNAME_R") at getenv.c:81
81 for (i = 0, len = strlen (name); environ[i]; i++)
(gdb) bt
#0 0x080c1591 in getenv (name=<optimized out>,
name@entry=0xf775f850 "TESTSUITE_UNAME_R") at getenv.c:81
#1 0xf775f754 in uname (u=u@entry=0xff946350) at testsuite/uname.c:32
#2 0xf74ffc6c in is_smp_system ()
at ../nptl/sysdeps/unix/sysv/linux/i386/smp.h:39
#3 __pthread_initialize_minimal_internal () at nptl-init.c:460
#4 0xf74fe32c in _init () at ../sysdeps/i386/crti.S:74
#5 0x00000000 in ?? ()
(gdb) p environ
$1 = (char **) 0x0
I don't know why it only happend in the chroot, but glibc can call its
own functions and impose any restrictions before main() is started, so
we have to adapt.
Also, do not return error if there is an environment, but the
environment variable is not found. If uname() is called by kmod, then
the respective test will simply fail later. If it's something else
calling uname(), then we do not want to disturb the program.
These redirecting makefiles simplifies compiling from some editors and
when CWD is not the root of the source tree. This is similar to what was
introduced in systemd in 340d89e ("build-sys: add small redirecting
Makefiles to simplify compilation from within emacs")
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.
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").
We are not only checking if those options are correctly parsed from
kcmdline, but if in fact they are being passed to the final
(f)init_module call. This is why we use 'modprobe --show-depends'
instead of the simpler 'modprobe -c'.
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")