Commit Graph

1297 Commits

Author SHA1 Message Date
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
Philippe De Swert
2b2a503e4f insmod: do support -f
The -f switch is accepted by insmod, but silently ignored. This
causes the user to wonder why things don't work. As insmod is
most often used with "evil" modules, -f is almost default and
thus needs to work.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
2015-10-25 13:57:17 -02:00
Lucas De Marchi
f7f2851024 libkmod: export new kmod_get_dirname() function
Make sure it gets exported and add documentation.
2015-09-30 15:28:24 -03:00
Laura Abbott
f3f62f5ec3 depmod: Don't fall back to uname on bad version
Currently, if a value that doesn't match a kernel version
("%u.%u") is passed in, depmod silently falls back to
using uname. Rather than try and work around the caller passing
bad data, just exit out instead.
2015-09-30 15:17:05 -03:00
Laura Abbott
50f43ce2f6 depmod: Remove unprinted debug messages
In between the start of the program and the call to log_setup_kmod_log,
the only messages that will be printed are the ones at or above the
global default level. Debug messages in this range will never be printed
so remove them.
2015-09-30 15:17:03 -03:00
Laura Abbott
16d863c317 Change default log level
The default log level is currently LOG_ERR. Tools can override this
default but there is a non-trivial amount of setup that needs to
happen before the log level can be changed. Since tools may want to
use the warn level for things such as deprecated flags, change the
default to LOG_WARNING to ensure messages get printed.
2015-09-30 15:17:01 -03:00
Laura Abbott
b87d01d6ef modprobe: Update error message when path is missing
Currently, modprobe fails with no output by default if the
search paths it tries are missing:

$ modprobe -S notakernel dm-crypt
$
$ modprobe -S notakernel lkjjweiojo
$

This is fairly cryptic and not at all obvious there is a problem
unless the error code is checked or verbose flags are used.
Update the error message to indicate a problem and print out the
directory that failed.
2015-09-30 15:16:59 -03:00
Laura Abbott
4cce76eb45 README: Indicate cython requirements
The recommended flags require cython be installed to compile
successfully. Note this in the documentation.
2015-09-30 15:16:57 -03:00
Natanael Copa
e414d087d9 build: let sed use posix ERE instead of GNU extension
Use POSIX Extended Regular Expression (ERE) instead of the GNU extension
\| in the install-exec-hook. This makes it create the symlink properly
with busybox sed built with musl libc. It will silently create a broken
symlink otherwise.

Lucas De Marchi:  fix up added newline.
2015-06-22 11:23:57 -03:00