Commit Graph

1316 Commits

Author SHA1 Message Date
Lucas De Marchi a1bec0dfdb depmod: fix leak in case of malloc(0)
malloc(0) can return != NULL. We need to pass the pointer to free().
This happens if index__haschildren(node) returned true, but
child_count is set to 0.
2015-02-26 03:40:47 -03:00
Lucas De Marchi 0bcdef9700 build: add helpers to upload coverity tarball 2015-02-25 12:57:31 -03:00
Lucas De Marchi a07ea0329c depmod: use cleanup attribute to simplify free on exit
Reusing the root variable was a bad idea. Doing so we could call free()
on a variable that was not allocated. For example: "depmod -b / -h".
Since we would jump to cmdline_failed, root would not be duplicated.

Instead of fighting the order in the options, just used the cleanup
attribute and remove the calls to free() on "config_paths" and "root".
2015-02-25 12:06:44 -03:00
Colin Walters 0b3aef23b8 depmod: Fix crash in previous commit if root is not set
[This fixes http://build.gnome.org/continuous/buildmaster/builds/2015/02/25/31/build/output.txt ]

The variable we're reading here is "root", not "optarg" which is only
valid inside the getopt call.
2015-02-25 11:27:05 -03:00
Lucas De Marchi e90f0704ea depmod: fix leaking root on exit 2015-02-25 00:50:37 -03:00
David Herrmann 29ad07504b from systemd: build: make sure to test for -Wflag instead of -Wno-flag
gcc does not support testing for negated warnings. See here for details:
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63499

This patch changes CC_CHECK_FLAG_APPEND to always test for the non-negated
warnings.
2015-02-24 22:45:17 -03:00
Zbigniew Jędrzejewski-Szmek a8f3aaebbe from systemd: build-sys: fix conftest.c to work on arm
All tests for compiler support were failing with:

/usr/bin/ld: /tmp/ccwnVc2A.o: relocation R_ARM_MOVW_ABS_NC against `a' can not be used when making a shared object; recompile with -fPIC
2015-02-24 22:42:06 -03:00
David Herrmann 779729cf53 from systemd: build: check for build/link flags harder
Use AC_LINK_IFELSE instead of AC_COMPILE_IFELSE to test for flags that
might succeed during compilation but not during linking. An example is gcc
compiled with libssp support but gnu-ld without it. In this case
-fstack-protector works fine during compilation but fails during linking
as several internal helpers are missing.
2015-02-24 22:41:30 -03:00
Lucas De Marchi c619d89208 from systemd: build: merge trivial changes back
These were trivial changes applied to systemd tree since the files were
synchronized:

  - change some comments
  - replace tab with space
  - fix typo
2015-02-24 22:37:27 -03:00
Lucas De Marchi 80f6ab5c9c build: add missing files to EXTRA_DIST
Fix make distcheck.
2015-02-24 01:50:32 -03:00
Lucas De Marchi 10d783c4a7 module-playground: don clean all .ko files
Rather than calling kernel's make for clean target, do it by ourselves.
This way we can preserve some prebuilt modules.
2015-02-24 01:48:48 -03:00
Marcus Meissner 0af8f786c0 testsuite: move test-blacklist to DEFINE_TEST
otherwise the test will not be executed.

Signed-Off-By: Marcus Meissner <meissner@suse.de>
2015-02-22 13:46:18 -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 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