Commit Graph

1253 Commits

Author SHA1 Message Date
Lucas De Marchi b66381385a libkmod-util: Add missing include file
Fix compilation issue with musl-libc:

  CC       libkmod/libkmod-list.lo
In file included from libkmod/libkmod-private.h:183:0,
                 from libkmod/libkmod-list.c:24:
libkmod/libkmod-util.h:33:45: warning: 'struct stat' declared inside parameter list [enabled by default]
libkmod/libkmod-util.h:33:45: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
2013-03-19 17:52:30 -03:00
Josh Boyer d53abca3be rmmod: Teach rmmod about builtin modules
Currently modprobe -r will fail if a module is built in and report that it
is built in.  rmmod calls the same function to determine state but doesn't
handle the KMOD_MODULE_BUILTIN return code.  This leads to confusing errors
like this:

	libkmod: kmod_module_get_holders: could not open '/sys/module/loop/holders': No such file or directory
	Error: Module loop is in use

Fix this so that it actually reports the correct problem to the user.
2013-03-18 11:16:50 -03:00
Kees Cook c3e8d26946 libkmod: fix address argument to mmap calls
The first argument to mmap should be "NULL" instead of "0".
2013-02-19 19:19:51 -03:00
Kees Cook e87352d289 testsuite: handle finit_module
This adds the finit_module logic to the testsuite.
2013-02-19 19:19:51 -03:00
Kees Cook 144d1826f1 libkmod: add finit_module logic
When a module is being loaded directly from disk (no compression, etc),
pass the file descriptor to the new finit_module() syscall. If the
finit_module syscall is exported by the kernel syscall headers, use it.
Additionally, if the kernel's module.h file is available, map kmod flags
to finit_module flags.
2013-02-19 19:19:51 -03:00
Michal Marek 709b86346e testsuite: Add modinfo test for module signatures 2013-01-17 23:48:43 -02:00
Michal Marek 8fe1681c52 libkmod: Return module signature information in kmod_module_get_info()
If the module is built with CONFIG_MODULE_SIG, add the the signer's
name, hexadecimal key id and hash algorithm to the list returned in
kmod_module_get_info(). The modinfo output then looks like this:

filename:       /home/mmarek/kmod/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha256.ko
license:        GPL
description:    Fourth Extended Filesystem
author:         Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others
alias:          ext3
alias:          ext2
depends:        mbcache,jbd2
intree:         Y
vermagic:       3.7.0 SMP mod_unload
signer:         Magrathea: Glacier signing key
sig_key:        E3:C8:FC:A7:3F:B3:1D:DE:84:81:EF:38:E3:4C:DE:4B:0C:FD:1B:F9
sig_hashalgo:   sha256

The signature algorithm (RSA) and key identifier type (X509) are not
displayed, because they are constant information for every signed
module. But it would be trivial to add this. Note: No attempt is made at
verifying the signature, I don't think that modinfo is the right tool
for this.
2013-01-17 23:48:43 -02:00
Michal Marek 6333934e27 libkmod-module: Do not free the list in kmod_module_info_append
In error case, just return NULL and let the caller free the list.
2013-01-17 23:48:43 -02:00
Lucas De Marchi e6b0e49b4e Update copyright notices 2013-01-16 11:27:45 -02:00
Michal Marek f64458cab5 libkmod-module: Add helper for building the module info list 2013-01-16 09:53:46 -02:00
Lucas De Marchi 4111bc0fc7 gitignore: ignore files generated by Automake's testsuite
These files are generated by Automake 1.13 when running the testsuite.
2013-01-15 18:03:55 -02:00
Lucas De Marchi eecdcf2e42 man: fix lib dir in which we look for config
Thanks to William Hubbs <w.d.hubbs@gmail.com> for spotting the bug.
2013-01-07 23:14:00 -02:00
Andrey Mazo 572a2711e7 depmod: fix builtin symbols resolution when the prefix symbol is set
When the prefix symbol is set, take it into account while adding symbols
from System.map file by skipping it before "__ksymtab_" comparison.

Also, prevent inserted fake symbols (like "__this_module") from being
wrongly truncated from beginning.
2012-12-31 18:23:30 -02:00
Andrey Mazo c02a8e6f9b depmod: --symbol-prefix actually requires an argument
-P requires and uses an argument but its long counterpart --symbol-prefix does not:
depmod: option '--symbol-prefix' doesn't allow an argument
2012-12-13 15:52:42 -02:00
Lucas De Marchi 6feba02878 kmod 12 2012-12-05 01:39:17 -02:00
Lucas De Marchi 650f89cd25 depmod: fix checking file extension
In depfile_up_to_date_dir() we need to check if name has a kmod
extension. "path" variable there will be the directory name, which
doesn't contain an extension.

Without this, "depmod -A" returns that the modules.dep is up to date,
even if it isn't.

In depmod_modules_search_file() it's pointless to compare the basename,
so pass only the name to be checked.
2012-11-28 14:26:23 -02:00
Lucas De Marchi 5d352563bd Use bool instead of int
Also change the last field initializer in array to be empty.
2012-11-28 14:25:50 -02:00
Aleksey Makarov 6f02b6fa7a fix is_module_filename()
modinfo fails if there is a ".ko" substring in the path to the module
2012-11-28 11:22:00 -02:00
Lucas De Marchi a4578669ca libkmod-module: mangle the section header, not the section
When we are told to remove the "__versions" section we were mangling
that section instead of tweaking the SHF_ALLOC flag in its header.
2012-11-21 20:23:02 -02:00
Lucas De Marchi d196b8d99f libkmod-module: Remove key+value vermagic from .modinfo section
When told to force load a module, we were removing only the value of
vermagic instead of the complete entry.

Philippe De Swert (philippe.deswert@jollamobile.com) sent a patch that
was additionally mangling also the last two chars of the key
("vermagic="). Instead of creating an invalid entry in .modinfo section
like this, this patch removes the complete entry, key + value, by
zeroing the entire string.

Much thanks to Philippe who found the issue and pointed to the fix.
2012-11-21 20:22:56 -02:00
Lucas De Marchi 02c64df3c2 depmod: fix asserting mod->kmod == NULL
If we are replacing a lower priority module (due to its location), we
already created a kmod_module, but didn't open the file for reading its
symbols. This means mod->kmod won't be NULL, and this is just ok. Since
all the functions freeing stuff below the previous assert already takes
NULL into consideration, it's safe to just unref mod->kmod and let the
right thing happens.
2012-11-16 12:05:42 -02:00
Lucas De Marchi 06294621a9 depmod: fix hash lookup by relpath instead of uncrelpath
We index modules in depmod by it's uncompressed relative path, not
relative path. We didn't notice this bug before since this function is
only triggered if we release a module to be replaced by one of higher
priority.

Also fix a leftover log message referring to relpath instead of
uncrelpath.
2012-11-16 11:39:41 -02:00
Lucas De Marchi c599606f75 kmod 11 2012-11-08 02:30:21 -02:00
Lucas De Marchi 6c29e5c670 TODO: remove completed action 2012-11-08 02:01:59 -02:00
Lucas De Marchi 7c04aeee40 tools: use program_invocation_short_name provided by libc
Thanks to Dave Reisner for pointing this out.
2012-11-06 19:30:16 -02:00
Lucas De Marchi c841273721 tools: staticize functions that are now only used in log.c 2012-11-06 19:06:11 -02:00
Lucas De Marchi fcb0ce9475 tools: share function for logging 2012-11-06 19:02:23 -02:00
Lucas De Marchi 52a50fe2e5 tools: share setting up libkmod log
This also fixes a bug in "e6996c5 rmmod: route all messages to syslog if
told to" in which "+ verbose" was removed. Instead of letting verbose
add to kmod_get_log_priority(), let it be similar to the other programs
instead.
2012-11-06 18:52:09 -02:00
Lucas De Marchi 92aad74925 tools: use a single function for logging libkmod output 2012-11-06 18:35:17 -02:00
Lucas De Marchi 34e06bfb54 tools: make usage() messages go to stdout rather than stderr
When user supplied --help/-h, program should output to stdout the usage,
not to stderr. It's the expected behavior, what the user asked for,
not something to log or an error.
2012-11-06 17:32:41 -02:00
Lucas De Marchi 84341fbe01 tools: share function to convert prio to string
No change is expected in the final binary since right now only an inline
function is shared. Later we expect to share more code.
2012-11-06 17:10:57 -02:00
Lucas De Marchi 4a2e20dfb3 tools: share getting program name from argv for all tools 2012-11-06 16:55:00 -02:00
Lucas De Marchi e6996c5c30 rmmod: route all messages to syslog if told to 2012-11-05 18:32:05 -02:00
Lucas De Marchi 04c26d28be rmmod: prefer ERR over plain fprintf 2012-11-05 18:31:19 -02:00
Lucas De Marchi 9382dbf7aa modinfo: prefer ERR over plain fprintf 2012-11-05 18:31:19 -02:00
Lucas De Marchi e2f9478faf insmod: prefer ERR over plain fprintf 2012-11-05 17:59:23 -02:00
Lucas De Marchi 96b50d3623 depmod: add depmod prefix to log messages 2012-11-05 02:08:16 -02:00
Lucas De Marchi a3f16ff704 depmod: remove inline from _log 2012-11-05 02:08:16 -02:00
Lucas De Marchi 8836ff24b4 TODO: update file with tasks 2012-11-05 02:04:44 -02:00
Lucas De Marchi 61c48db360 depmod: prefer ERR and WRN over plain fprintf 2012-11-05 02:01:06 -02:00
Lucas De Marchi d9a2e15504 modprobe: use ERR() instead of fprintf(stderr, ...) 2012-11-01 13:03:02 -02:00
Lucas De Marchi d96ae03bd9 modprobe: prefix log messages to stderr with modprobe 2012-11-01 12:46:12 -02:00
Lucas De Marchi 07df56eb24 modprobe: move log function 2012-11-01 12:46:12 -02:00
Lucas De Marchi 86cc1f2328 modprobe: prefix libkmod messages to stderr with modprobe:
When we are logging to stderr we are previously relying on libkmod
sending it to the default location in case we are not asked to log to
syslog. The problem is that modprobe may be used in scripts that don't
want to log to syslog (since they are not daemons, like scripts to
generate initrd) and then it's difficult to know where the message comes
from.

This patch treats only the messages coming from libkmod.
2012-11-01 12:46:03 -02:00
Lucas De Marchi 1e947e3c87 modprobe: use prio_to_str() helper 2012-10-31 22:00:40 -02:00
Lucas De Marchi 4434d8ba36 modprobe: exit in one place 2012-10-31 21:29:54 -02:00
Lucas De Marchi e4a7352ad3 depmod: unref kmod_module once we don't need it anymore
Once we read all we need from a module, unref it so any resource taken
by it (including the mmap to access the file in libkmod) will be
dropped. This drastically reduces the number of open file descriptors
and also the memory needed, with no performance penalties. Rather,
there's a small speedup of ~2.6%.

Running depmod in a laptop with 2973 modules and comparing the number of
open file descriptors for kmod-10, before and after the last patches to
depmod (caaf438cb6 and HEAD) we have:

	Before:		2980 simultaneously open fds
	After:		7    simultaneously open fds
	kmod-10:	7    simultaneously open fds

So now we have the speedup of caching the file in kmod_module without
the drawback of increasing the number of open file descriptors.
2012-10-30 04:56:59 -02:00
Lucas De Marchi 447eed8c48 depmod: use our copy of modname instead of calling libkmod
In depmod_module_add() we already called kmod_module_get_name() and
copied the string to our struct. Use it instead of calling again and
again the libkmod function.
2012-10-30 04:11:24 -02:00
Lucas De Marchi ec587f298c depmod: cache dependency_symbol list in struct mod
The overall goal is to coalesce the accesses to a file that is the
backend of a module. This commit addresses the calls to
kmod_module_get_get_dependency_symbols(). Calling it earlier, while we
are iterating the modules allows us to free the struct kmod of each
module much sooner. We are still not freeing it since there are other
places that must be refactored first.

There's a performance penalty of ~2.5% from previous commit.
2012-10-30 04:05:53 -02:00
Lucas De Marchi 7062eca38b depmod: cache info_list in struct mod
The overall goal is to coalesce the accesses to a file that is the
backend of a module. This commit addresses the calls to
kmod_module_get_info(). Calling it earlier, while we are iterating the
modules allows us to free the struct kmod of each module much sooner. We
are still not freeing it since there are other places that must be
refactored first.

A nice side effect is that this commit reduces in ~33% the calls to
malloc(), giving a speedup of ~6% for cold caches (reproduced on only 1
laptop).
2012-10-30 03:24:25 -02:00