Commit Graph

1355 Commits

Author SHA1 Message Date
Thomas Petazzoni ecab65b35c shared/util.c: assert_cc() can only be used inside functions
shared/macro.h has two versions of assert_cc, one that uses gcc
_Static_assert(), which requires recent enough gcc versions, and one
that uses a fake array to trigger a build error. The latter can only
work inside functions, so assert_cc() should only be used inside
functions.

Fixes the following build failure when building kmod with old gcc
versions such as gcc 4.3.x:

shared/util.c:52: error: expected identifier or '(' before 'do'
shared/util.c:52: error: expected identifier or '(' before 'while'

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-06-05 10:07:00 -07: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 7da6884e73 depmod: implement external directories support
The idea is to add a configuration keyword, external, which
will list directories for scanning for particular kernel version
mask:

external 4.10 /the/modules/dir /second/modules/dir

And extend "search" keyword to set it's priority with pseudo dir
"external" (as it's done for built-in):

search subdir external subdir2 built-in subdir3

(actually, the version is the same as for override keyword: * or
posix regexp, so example above is a bit incorrect).

All other logic left the same: if there are duplicates, only one
is under consideration and it is unloadable if it is bad.

The resulting modules.dep will contain entries a-la:

/the/modules/dir/module1.ko:
kernel/module2.ko: /the/modules/dir/module1.ko

(here /lib/modules/$(uname -r)/kernel/module2.ko depends of
symbols, provided by /the/modules/dir/module1.ko and external has
higher priority).

modprobe and modinfo understand it out of box.

This is a pretty simple extention of existing logic, since now
depmod already is able to:

a) scan modules with full path from command line without -a
switch;
b) detects broken symbol dependencies and broken modversions,
what assumes, that modules are already are not built for the
existing kernel.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-06-01 20:30:03 -07:00
Lucas De Marchi e0ff310d87 test-depmod: avoid warning when we don't have zlib
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)
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-06-01 20:26:23 -07:00
Yauheni Kaliuta 1399c5ad53 depmod: rewrite depmod modules search with scratchbuf
The recursive search code used used pretty big, PATH_MAX,
automatic storage buffer for the module directory scanning. Some
time ago there was scratchbuf implemented, which dynamically
reallocates its buffer on demand. The patch takes it in use for
the scanning code also. The initial size is hardcoded to 256
bytes which sounds good enough for most usecases so there should
be not many reallocations.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-06-01 20:23:13 -07:00
Yauheni Kaliuta 369ca65620 depmod: create depmod dir independent search function
Prepare to implement external directories support.

The patch splits depmod_modules_search() function to two
functions: depmod_modules_search(), called by the high level with
intention to search all possible modules, and
depmod_module_search_path(), which takes path as a parameter and
scans modules under the path only. Initially it is used to scan
the same depmod->cfg->dirname path only.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-06-01 19:17:42 -07:00
Yauheni Kaliuta 0d6b3f9bea depmod: search key: move builtin detection under the add function
Prepare to implement external directories support.

It's better to isolate behaviour difference under the
cfg_search_add() call, then make the client code aware of it.

In case of external modules/directories support, there will be
one more keyword added, so making the clients aware of it makes
even less sense.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-05-09 00:01:50 -07:00
Yauheni Kaliuta cd019a39ea depmod: fix errorpath memleaks in report cycles logic
The c7ce9f0c80 commit (depmod:
handle nested loops) introduced a bunch of possible memory leaks
in error path. In the real world scenario it is not a problem,
since the utility quits if it detects any of the errors, but from
the programming point of view, it is not nice. So, add the
cleanups.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-05-08 23:45:34 -07:00
Yauheni Kaliuta e5b6a658ea libkmod: modinfo: implement signature output
Signature was ignored from the modinfo. Implement its parsing
from the module data and add its output to the modinfo utility.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-04-11 09:04:28 -07:00
Yauheni Kaliuta abcd0bf8ec libkmod: modinfo: implement line splitting in hex_to_str
The key output is usually short, but for signature it is more
readable to output it in several lines.

Implement line splitting. Set line limit hardcoded to 20 hex
numbers (not characters).

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-04-11 09:04:28 -07:00
Yauheni Kaliuta 96b88aea2a libkmod: modinfo: use own function for sig_key hex output
Refactor the code a bit to make it easier to extend for signature
output.

kmod_module_get_info() creats a hex string for the sig_key data
inplace. Separate it into own kmod_module_hex_to_string function
and handle the branch in the new kmod_module_info_append_hex,
keeping the same signature as the non-hex version.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-04-11 09:04:28 -07:00
Yauheni Kaliuta 30fb14f3c8 libkmod: modinfo: fix sig_id output
For some reason the key for sig_id was set to "signature". The
length was calculated against the proper string, as the result in
the output it was truncated to "signat".

Pass the proper key to the kmod_module_info_append() call.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-04-11 09:04:28 -07:00
Lucas De Marchi ef4257b59c kmod 24 2017-02-23 23:32:51 -08:00
Lucas De Marchi 6ee2813602 build: update autogen
Bring new options from systemd and other projects.
2017-02-23 23:18:02 -08:00
Lucas De Marchi 3200780813 depmod: fix leak on error path 2017-02-23 23:18:02 -08:00
Lucas De Marchi 72167ba113 man: make error message clearer for missing xstlproc
We can't do at configure phase since we actually ship the built man pages with
dist, so it's fine not having xsltproc if building from dist. If building from
the repository, it's better to have have a better message saying xsltproc was
not found than trying to execute the argument to xsltproc. Now message is:

  XSLT     depmod.d.5
  /bin/sh: line 1: xsltproc: command not found

Instead of:

  XSLT     depmod.d.5
  /bin/sh: --nonet: command not found
2017-02-23 18:31:15 -08:00
Lucas De Marchi 527658ad89 build: add missing header
Fix failing distcheck
2017-02-23 18:26:54 -08:00
Yauheni Kaliuta c7ce9f0c80 depmod: handle nested loops
This is a rework of depmod report cycles logic to make it
tolerant to more complex loops.

The patch tries to remember own path for vertexes which makes it
possible to handle configurations with common edges and
non-cyclic modules.

It assumes that the previous dependency calculations can not give
as input something like

mod_a -> mod_b -> <loop>, but

<loop> -> mod_a -> mod_b should be fine.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-02-22 04:53:39 -08: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 8df21177fb libkmod-config: replace 0/1 with bool 2017-02-16 08:57:01 -08:00
Bartosz Golaszewski b1982674ae module: fix a memory leak
When a module is removed and re-inserted without unrefing, the
kmod_file is unconditionally re-opened. This results in a memory
and file descriptor leak.

Fix it by checking if the file is already open in
kmod_module_insert_module().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2017-02-16 08:50:01 -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
Lucas De Marchi 55f8286fcd testsuite: fix typo in description 2017-01-23 11:58:29 -08:00
James Minor f27a2b1274 libkmod: Fix handling of quotes in kernel command line
If a module parameter on the command line contains quotes, any
spaces inside those quotes should be included as part of the
parameter.

Signed-off-by: James Minor <james.minor@ni.com>
2017-01-23 10:47:13 -08:00
Lucas De Marchi 67d1534318 build: fix build with disabled test modules
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.
2016-11-10 23:47:19 -02:00
Yauheni Kaliuta b34819bc0e shared: make scratchbuf_str static
It fixes linking problem

tools/depmod.o: In function `output_symbols_bin':
depmod.c:(.text.output_symbols_bin+0x135): undefined reference to `scratchbuf_str'

for -O0 build, where gcc doesn't actually inline it.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2016-11-10 22:14:27 -02: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
Mian Yousaf Kaukab 965886b55a testsuite: depmod: add module dependency outside cyclic chain
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>
2016-11-08 22:28:40 -02:00
Yauheni Kaliuta d242703211 testsuite: fix test_array_sort pointers inderection
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>
2016-11-08 22:21:13 -02:00
Lucas De Marchi cb51a641d6 depmod: fix string overflow
Use scratchbuf to fix issue with strcpy that may overflow the buffer we
declared in the stack.
2016-08-15 10:26:42 -03:00
Lucas De Marchi 780a4e97e2 Add scratchbuf implementation
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"
2016-08-15 10:26:42 -03:00
Lucas De Marchi a6421a04e0 testsuite: include stdio.h
It's used in the log macros so include it.
2016-08-15 10:26:42 -03:00
Lucas De Marchi a6ede6c7ad util: fix warning of equal values on logical OR
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.
2016-08-10 12:45:36 -03:00
Lucas De Marchi 53d3a99ccc libkmod: fix use of strcpy
We were not checking if there was sufficient space in the buffer.
2016-08-08 11:42:52 -03:00
Lucas De Marchi 65a885df5f kmod 23 2016-07-20 01:38:42 -03:00
Lucas De Marchi a29268d00e NEWS: add items for kmod 23 2016-06-28 15:28:47 -03:00
Lucas De Marchi a0f6726e66 libkmod: fix integration with gtk-doc
It was failing to generate doc with recent version of gtk-doc

[kmod]$ ./bootstrap
libkmod/docs/gtk-doc.make:33: error: EXTRA_DIST must be set with '=' before using '+='
libkmod/docs/Makefile.am:29:   'libkmod/docs/gtk-doc.make' included from here
autoreconf: automake failed with exit status: 1

Just add an empty EXTRA_DIST so it works.
2016-06-28 12:15:38 -03:00
Lucas De Marchi e78fe15f0a libkmod-module: modinfo: print signature id
This way it's possible to give at least the signature type for PKCS#7.
2016-06-27 08:17:55 -03:00
Lucas De Marchi 75f45d9bfa libkmod-signature: handle PKCS#7 2016-06-27 08:17:55 -03:00
Lucas De Marchi dcdb17715e libkmod-module: do not crash modinfo on 0 key id len 2016-06-27 08:17:55 -03:00
Michal Marek 2206d7f763 libkmod: Handle long lines in /proc/modules
kmod_module_new_from_loaded() calls fgets with a 4k buffer. When a
module such as usbcore is used by too many modules, the rest of the line
is considered a beginning of another lines and we eventually get errors
like these from lsmod:

libkmod: kmod_module_get_holders: could not open '/sys/module/100,/holders': No such file or directory

together with bogus entries in the output. In kmod_module_get_size, the
problem does not affect functionality, but the line numbers in error
messages will be wrong.

Signed-off-by: Michal Marek <mmarek@suse.com>
2016-06-21 18:00:20 -03:00
Anton Blanchard d46136bb59 depmod: Ignore PowerPC64 ABIv2 .TOC. symbol
The .TOC. symbol on the PowerPC64 ABIv2 identifies the GOT
pointer, similar to how other architectures use _GLOBAL_OFFSET_TABLE_.

This is not a symbol that needs relocation, and should be ignored
by depmod.
2016-06-11 00:27:39 -03:00
Lucas De Marchi f7ed430a53 README: add link to patchwork 2016-05-24 11:45:25 -03:00
Héctor Orón Martínez 90a6e7983f kmod: compiling with old sed version (!ERE support)
Makefile.am uses `sed -E', which it is found on BSD sed; however a
  replacement on GNU sed would be `sed -r'. Both intend to use extended
  regular expressions (ERE). However I have a system that does not support
  those, in benefit for portability could you consider replacing ERE by BRE.

Signed-off-by: Héctor Orón Martínez <hector.oron@gmail.com>
2016-05-21 15:07:27 -03:00
Peter Wu 1930899aae kmod_module_get_refcnt: fix documentation 2016-05-21 14:27:53 -03:00
Lucas De Marchi 9132c59ebc travis: workaround bug in environment setup
Travis is poluting the environment, particularly PYTHON_CFLAGS which
makes the build to fail. Just unset the variable since we don't want to
override these cflags.
2016-01-11 11:19:36 -02:00
Josh Triplett 4c30a11d5f depmod: Don't insert comment in modules.devname if otherwise empty
This allows tools to detect the file as empty, such as via systemd's
ConditionFileNotEmpty.
2016-01-11 10:25:31 -02:00
Marc-Antoine Perennou d64b286a9a insmod: fix wron fallthrough of -f
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2015-11-20 19:26:33 -02:00
Lucas De Marchi 42f32b8ae4 kmod 22 2015-11-17 22:12:07 -02:00