Commit Graph

1253 Commits

Author SHA1 Message Date
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 a24e17839c fixup! module-playground: allow to cross-compile modules 2015-02-21 15:08:19 -02:00
Lucas De Marchi 5eafc34d66 testsuite: leave arch-specific modules in tree
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.
2015-02-21 15:05:25 -02:00
Lucas De Marchi f6dc239ed2 testsuite: add option to copy output from test
This is helpful while debugging the tests: copy the output from test
(both stdout and stderr) to the stdout of the parent process.
2015-02-21 13:39:36 -02:00
Lucas De Marchi 03a5079f62 testsuite: fix exiting with success on no output activity
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.
2015-02-21 13:15:38 -02:00
Lucas De Marchi 7efa3502dd module-playground: allow to cross-compile modules
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.
2015-02-21 11:40:27 -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 709a465d0e Update TODO 2015-02-19 01:00:05 -02:00
Lucas De Marchi 885e90b6f9 libkmod: better explain a signed module layout 2015-02-18 16:49:01 -02:00
Lucas De Marchi dcbe1846e8 libkmod: consider empty signature key as invalid
A segmentation fault occurs if a module has an empty key attached to
its signature. This is mostly likely due to a corrupted module.

The crash happens because kmod_module_get_info() assumes that
kmod_module_signature_info() returns a signature of at least 1 byte.

The fix is based on a patch from Tobias Stoeckmann
<tobias@stoeckmann.org>, but rather than changing kmod_module_get_info()
to fix the crash, this changes kmod_module_signature_info() to
consider the signature as invalid.
2015-02-18 16:15:45 -02:00
Tobias Stoeckmann 40ef6e69bb Fix out of bounds signature access with 32 bit off_t
If kmod has been configured with --disable-largefile on a 32 bit
system, off_t will be 32 bit. In that case, the parsed sig_len can
bypass a validation check (it's _unsigned_ 32 bit).

Due to the unlikeliness of people using --disable-largefile, this is
a mere validation fix. With an explicit signed 64 bit cast, there is
no binary change for 99.9% of Linux systems out there. ;)
2015-02-18 15:49:10 -02:00
Tobias Stoeckmann 249dc5909b libkmod: properly validate file size
In function kmod_elf_new, the file size has to be properly validated against
section offset. Currently, the file size is considered valid based on
ELF header size + section header size * section count. That is not sufficient.

In fact, ELF specifies a section header offset, which doesn't have to be the
size of the ELF header. The supplied test cases even cover this.

The correct test is: section offset + section header size * section count

This patch also verifies that this value won't overflow.  I don't know a way
to crash a tool due to this bug, because later on the offset check would
prevent out-of-bounds access. An overflow would just mean to access a wrong
part in elf->memory. Yet it's a validation error.

Please note: The file size does not have to be validated against the size
of the ELF header again, elf_identify did this already.
2015-02-17 14:10:31 -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 6684102cd3 libkmod: use helper function to check for overflow 2015-02-10 10:46:26 -02:00
Lucas De Marchi aac5f4514f shared: add helper function to add and check for overflow
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.
2015-02-10 10:43:44 -02:00
Lucas De Marchi 14c3244f04 build: define to 0 if builtin is not available
In order to let us use "#if HAVE__BUILTIN_*" without checking if it's
actually define, make sure we define it to 0 in config.h when the
function is not available.
2015-02-10 10:32:10 -02:00
Tobias Stoeckmann 67466f266d Prevent offset + size overflow.
it is possible to overflow uint64_t by summing variables offset and
size up in elf_get_section_info. Thee values are extracted from module
file and are possibly maliciously tampered with.

If offset is in valid range and size very large, the result will
overflow and the size check passes. Later on, this will most likely
lead to a segmentation fault due to accessing uninitialized memory.

Attached please find a proof of concept module, which will trigger
a segmentation fault on modinfo. Tested on amd64:

tobias:~$ modinfo poc.ko
filename:       /home/tobias/poc.ko
Segmentation fault

There are more errors of this type in the ELF handling code that will be
fixed in other patches.
2015-02-10 09:34:44 -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 e6307200af build: check for required builtin functions
These builtins are implemented by both gcc and clang since a long time
and we don't provide fallback for them. Let the configure phase check
for them.
2015-02-10 00:45:42 -02:00
Lucas De Marchi ba52c77e04 build: add better check for builtin function
It's not used right now in kmod, but may be used in future for other
builtins, so let the macro generic.
2015-02-10 00:31:25 -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 01af61dba4 travis: also test with gcc 4.8 and 4.9 2015-02-04 06:26:06 -02:00
Lucas De Marchi c16b5da2d9 travis: use kernel headers for testsuite
Install kernel headers and export KDIR variable to point to right dir.
2015-02-03 20:41:04 -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 0e68c6258e build: let touch on directory as last step
We need to let these instructions in kmod to be the last executed ones.
Otherwise the subdirectory containing the modules could propagate up the
time access.
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 d2db083ab6 testsuite: make test-dependencies use DEFINE_TEST
It went missing from previous conversions.
2015-02-03 01:09:22 -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
Lucas De Marchi 45f38e8c40 Update TODO 2015-01-26 23:31:04 -02:00
Caio Marcelo de Oliveira Filho 2200a448d4 testsuite: add tests for kmod_list
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.
2015-01-26 19:20:51 -02:00
Lucas De Marchi c677bf2c7d Revert "build: enable LTO and _FORTIFY_SOURCE with optimization"
This reverts commit 27bcc9111b.

Let the distro decide about this flag. It's relatively recent and
doesn't work well with gcc 4.[678] making the testsuite to fail.
2015-01-26 19:16:03 -02:00
Lucas De Marchi 01f9bc6dee Fix uninitialized warning
Initialize variable to NULL before calling kmod_module_new_from_lookup().

libkmod/libkmod-module.c: In function 'kmod_module_new_from_lookup.part.4.constprop':
libkmod/libkmod-module.c:192:8: warning: 'depmod' may be used uninitialized in this function [-Wmaybe-uninitialized]
   list = kmod_list_prepend(list, depmod);
        ^
libkmod/libkmod-module.c:173:23: note: 'depmod' was declared here
   struct kmod_module *depmod;
2015-01-25 23:54:05 -02:00
Lucas De Marchi a5f799af98 build: pass --no-undefined to linker
Do not allow undefined symbols.
2015-01-25 23:29:50 -02:00
Lucas De Marchi 27bcc9111b build: enable LTO and _FORTIFY_SOURCE with optimization
If building with optimization enabled, enable LTO.
2015-01-25 23:28:46 -02:00
Caio Marcelo de Oliveira Filho 88f6ffe449 util: remove dead code in freadline_wrapped
Each loop iteration starts with 'i < size'. When i is changed
the invariant is kept by checking if 'i == size' and growing the
buffer.
2015-01-21 10:18:44 -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
Caio Marcelo de Oliveira Filho 22f602c3c5 testsuite: add test for growing then shrinking a hash 2015-01-21 10:17:27 -02:00
Caio Marcelo de Oliveira Filho 9c2d39c735 testsuite: add test for hash_add_unique 2015-01-21 10:15:40 -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 2d1f8bdec0 testsuite: improve assert report 2015-01-14 16:28:16 -02:00
Lucas De Marchi 5b0436a759 tools: prefer the use of streq() 2015-01-14 14:32:09 -02:00
Lucas De Marchi 5c42c5fced testsuite: prefer the use of streq() 2015-01-14 14:32:09 -02:00
Lucas De Marchi 9b51e13b84 testsuite: test kmod_module_remove_module for failure 2015-01-14 14:32:09 -02:00
Lucas De Marchi bf2fbabb9e shared: add STRINGFY macro 2015-01-14 14:32:09 -02:00