Commit Graph

277 Commits

Author SHA1 Message Date
Emil Velikov efc2e4b467 treewide: add some static const notations
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-09 07:15:56 -08:00
Emil Velikov 1712a1548e depmod: Introduce outdir option
This option is equivalent to basedir, with the small difference being
that's where the meta-data files are generated. In other words, this
allows us to have read-only input modules and modules.dep, while still
being able to generate the meta-data files.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
[ Move files to a different dir so input files (produced by kernel build
  system is separate from the files generated by depmod (output) ]
Signed-off-by: Lucas De Marchi <lucas.demarchi@gmail.com>
2023-02-09 07:09:06 -08:00
Gustavo Sousa 883d931d1b modprobe: Allow passing path to module
This is useful to kernel module developers for testing a just compiled
module: instead of using insmod, they can load the module from the path
while getting all the benefits of modprobe (e.g. module dependency
resolution).

v2:
  - Add test for relative path as well. (Lucas)
  - Add note warning about modules with dependencies not matching the
    installed depmod database. (Lucas)

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-01-13 16:48:02 -08:00
Gustavo Sousa f3db15e900 modprobe: Move insertion block into separate function
That same logic will be used for enabling modprobe for paths in the next
patch. As such, prepare for that by extracting that block into its own
function.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-01-13 16:48:02 -08:00
Quentin Armitage c1fb98a30d modprobe: Write error messages to syslog if stderr is unavailable
The man page modprobe(8) states for the --syslog option:
"This is also automatically enabled when stderr is unavailable."
but it wasn't happening.

This commit now makes modprobe write to syslog if stderr is closed.
2022-06-30 09:59:38 -07:00
Lucas De Marchi 2b98ed8886 modprobe: Add --wait
Retry module removal if it fails due to EAGAIN. This allows user to pass
--wait <timeout>, during which `modprobe -r` will keep trying to remove
the module.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26 23:23:46 -07:00
Lucas De Marchi 081fff2c67 modprobe: Move -R to "Query options"
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26 23:23:46 -07:00
Lucas De Marchi 6f7ab21645 modprobe: re-use modname variable
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26 23:21:44 -07:00
Lucas De Marchi 07bf5e1520 depmod: Fix writing over array length
Make sure return value in flush_stream_to() is the length written
if the value didn't the size. Fix warning on gcc 12.1:

	tools/depmod.c: In function ‘output_builtin_alias_bin’:
	tools/depmod.c:2465:24: warning: array subscript 4096 is above array bounds of ‘char[4096]’ [-Warray-bounds]
	 2465 |                 modname[len] = '\0';
	      |                 ~~~~~~~^~~~~
	tools/depmod.c:2460:22: note: while referencing ‘modname’
	 2460 |                 char modname[PATH_MAX];
	      |                      ^~~~~~~
	tools/depmod.c:2477:22: warning: array subscript 4096 is above array bounds of ‘char[4096]’ [-Warray-bounds]
	 2477 |                 value[len] = '\0';
	      |                 ~~~~~^~~~~
	tools/depmod.c:2461:22: note: while referencing ‘value’
	 2461 |                 char value[PATH_MAX];
	      |                      ^~~~~

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26 23:21:44 -07:00
Lucas De Marchi ea3c8adfd3 modprobe: Make rmmod_do_module() contain all the removal sequence
Move the remaining part of the removal sequence dangling in
rmmod_do_remove_module() to rmmod_do_module() so we can consider this
function is the one controlling all the module removals.

While at it, add some comments about the removal order and normalize
coding style in this function.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-04-06 22:04:42 -07:00
Lucas De Marchi d29ed6ef9f modprobe: move check for remove_holders to caller
Do not mix the flags with and additional boolean from arguments.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-04-06 22:04:38 -07:00
Lucas De Marchi 42b32d30c3 modprobe: Fix holders removal
The idea behind --remove-dependencies was to remove other modules that
depend on the current module being removed. It's the reverse
dependency list, not the dependency list of the current module: that
never works since the current module would still hold a ref on it.

Fix it by replacing the call to kmod_module_get_dependencies() with
kmod_module_get_holders() when using that option. Also try to cleanup
the confusion by renaming the option to --remove-holders: "holder" is
the name used in sysfs and by libkmod to refer to a "live" reverse
dependency like what we are interested in.

Before:
	./tools/modprobe -D -r --remove-dependencies video
	rmmod video

After:
	./tools/modprobe -D -r --remove-holders video
	rmmod i915
	rmmod thinkpad_acpi
	rmmod video

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-04-06 22:03:59 -07:00
Masahiro Yamada d890179b45 modprobe: remove unneeded variable str_start
The variable 'str_start' is not useful here.

Replace it with 'str'.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2022-04-04 08:14:41 -07:00
Masahiro Yamada 757b359923 modprobe: fix the NULL-termination of new_argv
The number of new arguments is (i + argc - 1) as it is set to *p_argc
one line below.

The correct location of NULL termination is new_argv[i + argc - 1].

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2022-04-04 08:14:40 -07:00
Saul Wold f50e2d6757 depmod: Add support for excluding a directory
This adds support to depmod to enable a new exclude directive in
the depmod.d/*.conf configuration file. Currently depmod
already excludes directories named source or build. This change
will allow additional directories like .debug to be excluded also
via a new exclude directive.

depmod.d/exclude.conf example:
exclude	.debug

Signed-off-by: Saul Wold <saul.wold@windriver.com>
[ Fix warnings and make should_exclude_dir() return bool ]
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2022-04-01 21:44:15 -07:00
Lucas De Marchi 7089386eef modprobe: Rename rmmod_do_deps_list
It's used not only for dependencies, but also for pre and post softdep.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-04-01 21:43:59 -07:00
Lucas De Marchi 94f7683c5a modinfo: Allow to force arg as module name
If the Linux kernel or userspace sets an alias with the same name as a
module, they force the tools to use that. However in some situations it
may be desired to query the module itself. Getting the module
information through modinfo is one such situation. So, add a option to
modinfo to explicitly instruct it to handle the argument as a module
name.

Example, when trying to output information about the crc32 module that
is builtin:

	$ modinfo crc32
	filename:       /lib/modules/5.15.19-1-MANJARO/kernel/arch/x86/crypto/crc32-pclmul.ko.zst
	alias:          crypto-crc32-pclmul
	alias:          crc32-pclmul
	alias:          crypto-crc32
	alias:          crc32
	license:        GPL
	author:         Alexander Boyko <alexander_boyko@xyratex.com>
	srcversion:     B6B2FF9236731E69418A2E5
	alias:          cpu:type:x86,ven*fam*mod*:feature:*0081*
	depends:
	retpoline:      Y
	intree:         Y
	name:           crc32_pclmul
	vermagic:       5.15.19-1-MANJARO SMP preempt mod_unload
	sig_id:         PKCS#7
	signer:         Build time autogenerated kernel key
	sig_key:        77:FB:AA:BD:48:78:A4:C6:56:18:9A:7E:A6:F3:29:3E:C5:6B:E9:37
	sig_hashalgo:   sha512
	signature:      30:65:02:31:00:B0:D4:49:9D:1D:F1:71:4C:3C:BB:70:B2:3E:46:5D:
			38:5A:F1:00:95:FD:7A:96:C4:2C:24:35:A2:1B:0B:A8:1C:29:6F:02:
			7A:68:EE:BA:A4:1C:01:4B:86:39:15:3E:66:02:30:7F:7A:66:5E:F2:
			2F:98:73:3D:AD:96:66:81:8B:94:6E:F3:3F:44:0F:85:E1:73:3A:9E:
			F9:C4:BE:9B:88:02:BD:83:04:B9:2E:72:0B:93:BC:82:B6:A1:1B:6A:
			C2:ED:8C
	filename:       /lib/modules/5.15.19-1-MANJARO/kernel/crypto/crc32_generic.ko.zst
	alias:          crypto-crc32-generic
	alias:          crc32-generic
	alias:          crypto-crc32
	alias:          crc32
	license:        GPL
	description:    CRC32 calculations wrapper for lib/crc32
	author:         Alexander Boyko <alexander_boyko@xyratex.com>
	srcversion:     F08036C38DDB06BCD1E6091
	depends:
	retpoline:      Y
	intree:         Y
	name:           crc32_generic
	vermagic:       5.15.19-1-MANJARO SMP preempt mod_unload
	sig_id:         PKCS#7
	signer:         Build time autogenerated kernel key
	sig_key:        77:FB:AA:BD:48:78:A4:C6:56:18:9A:7E:A6:F3:29:3E:C5:6B:E9:37
	sig_hashalgo:   sha512
	signature:      30:65:02:31:00:E3:9E:C8:80:15:0E:D7:74:96:B5:25:EA:32:F7:DF:
			E9:FC:3C:82:D9:B9:B9:37:C5:20:8D:06:31:02:62:B3:54:E8:DF:F2:
			7E:E2:7C:A4:CF:49:17:CB:75:DF:2C:7A:2F:02:30:25:DE:7C:2A:2C:
			97:3F:65:16:76:B3:71:FB:62:DB:8F:F3:33:65:77:98:F3:57:ED:D7:
			87:78:FF:C2:04:55:70:00:10:63:1E:B2:FE:22:D8:E5:6D:5F:95:4E:
			7D:2C:6B

That is because the Linux kernel exports "crc32" as an alias to those modules,
besides being a module itself:

	$ grep crc32 /lib/modules/$(uname -r)/modules.builtin
	kernel/lib/crc32.ko
	$ $ grep "alias crc32 " /lib/modules/$(uname -r)/modules.alias
	alias crc32 crc32_pclmul
	alias crc32 crc32_generic

With the new -m|--modname option it's possible to query the information about this (builtin)
module explicitly:

	$ modinfo --modname crc32
	name:           crc32
	filename:       (builtin)
	license:        GPL
	file:           lib/crc32
	description:    Various CRC32 calculations
	author:         Matt Domsch <Matt_Domsch@dell.com>

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20 20:58:25 -08:00
Lucas De Marchi e343a82499 modinfo: Update help message with "modulename"
man page correctly states the a module name can be used in place of a
file name:

	modinfo [-0] [-F field] [-k kernel] [modulename|filename...]

Update the help message accordingly.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20 20:58:11 -08:00
Lucas De Marchi 0246e06340 depmod: Stop opening modules.modinfo once per module
Since the addition of modules.aliases.bin, depmod has to open that
index multiple times and parse it over and over again:

	$ sudo strace -e openat  ./tools/depmod 2>&1 | grep modules.builtin.modinfo  | wc -l
	299
	$ time sudo  ./tools/depmod
	real    0m7.814s
	user    0m7.571s
	sys     0m0.237s

Rework the logic in depmod so it does everything: open, read and parse. The
format is very straightforward and we don't need to keep it in a data structure
since we only want to add the result to a index. New output:

	$ sudo strace -e openat  ./tools/depmod 2>&1 | grep modules.builtin.modinfo  | wc -l
	1
	$ time sudo  ./tools/depmod
	real    0m7.663s
	user    0m7.516s
	sys     0m0.139s

Indexes still match:

	$ cmp /tmp/modules.builtin.alias.bin.new
	/tmp/modules.builtin.alias.bin.old; echo $?
	0

Fix: https://github.com/kmod-project/kmod/issues/11
2022-02-11 22:06:34 -08:00
Lucas De Marchi 7a0f593de3 depmod: Do not duplicate builtin index
Now that libkmod uses modules.builtin.bin again, we don't need to add
the module names in modules.builtin.alias.bin and just add the aliases.

After this change, here are the new sizes for the indexes:

Before	After	index
21k	6.4K	modules.builtin.alias.bin
11k	 11K	modules.builtin.bin
2022-02-11 22:06:34 -08:00
Lucas De Marchi f0a1360761 depmod: fix modules.builtin.alias.bin output
Due to wrong documentation on kmod_module_get_info() we ended up
checking for 0 as return. Check for > 0 to decided if we want to write
the index to the file, otherwise we would output a 0-sized index on
success.
2021-05-11 09:49:35 -07:00
Lucas De Marchi 9319b0f4cb Support /usr/local for configuration files
Add /usr/local to the search path for configuration files. These are
intended for local installs, provided /usr/local is given as prefix.
2021-01-18 18:26:36 -08:00
Lucas De Marchi 1c10f32483 depmod: fix precedence order
Configuration in /etc should have higher prio than /run.
Given how rarely configuration in /run is used with depmod, this is
likely not to cause any problems, even if it's a change in behavior.
2021-01-18 18:26:36 -08:00
Marco d'Itri fa67110f89 Fix "modinfo -F always shows name for built-ins"
Bug reported by Ben Hutchings <ben@decadent.org.uk>:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=970871

	Now that the kernel provides module information for potentially
	modular code that's actually built-in, it's possible to query these
	built-ins with "modinfo -F".  However, this doesn't work quite right:

	$ modinfo -Flicense e1000e
	GPL v2
	$ modinfo -Flicense bitrev
	name:           bitrev
	GPL
2021-01-07 20:17:48 -08:00
Lucas De Marchi 220b4c55ec depmod: unconditionally write builtin.alias.bin
The file is always created and unless we return an error, the temporary
file is renamed to its final destination. All other places write the
index without checking if the index is empty, so just do the same.

Reported-by: Joe Buehler <aspam@cox.net>
2020-12-27 16:40:08 -08:00
Yauheni Kaliuta bd96d05256 depmod: output_builtin_alias_bin: free idx on error path
idx is allocated in the beginning but it's not freed if there is
a failure after the allocation.

Change the error path: return immediately if idx allocation fails
and then free it in both success and error path at the end.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2020-12-01 00:44:17 -08:00
Lucas De Marchi 53b30aeba2 depmod: do not output .bin to stdout
index_write() relies on fseek/ftell to manage the position to which we
are write and thus needs the file stream to support it.

Right now when trying to write the index to stdout we fail with:

	depmod: tools/depmod.c:416: index_write: Assertion `initial_offset >= 0' failed.
	Aborted (core dumped)

We have no interest in outputting our index to stdout, so just skip it
like is done with other indexes.

While at it, add/remove some newlines to improve readability.

Reported-by: Yanko Kaneti <yaneti@declera.com>
Fix: b866b2165a ("Lookup aliases in the modules.builtin.modinfo")
2020-03-13 09:23:58 -07:00
Alexey Gladkov e7e2cb61fa modinfo: Show information about built-in modules
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2019-12-18 16:57:14 -08:00
Alexey Gladkov b866b2165a Lookup aliases in the modules.builtin.modinfo
New modules.builtin.modinfo duplicates modules.builtin in the built-in
module name search. If it exists, then we can use this file, but if not,
then we need to fallback to the old file.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2019-12-18 16:56:58 -08:00
Lucas De Marchi a6b540deaa modprobe: use flags rather than bool args
It's easier to know what the caller is doing when we pass a named
flag rather than a list of bools.
2019-11-07 09:46:51 -08:00
Yauheni Kaliuta 52a0ba82e1 modprobe: ignore builtin module on recursive removing
If there are built-in dependencies and any of them is built-in in
the kernel, modprobe -r fails with

modprobe: FATAL: Module module_name is builtin.

It makes sense to ignore such dependencies for the case when
removing is called for non-top level module.

Example: cifs module, it declares bunch of softdeps and the first
one fails on some kernel configs:

modprobe: FATAL: Module gcm is builtin.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-11-06 23:17:06 -08:00
Ezequiel Garcia ea3e508f61 tools: Print a message if refcnt attribute is missing
Currently, check_module_inuse returns a wrong user message
if the kernel is built without module unloading support.

Fix it by returning a more specific error, in case 'refcnt'
attribute is missing.
2019-03-08 13:06:52 -08:00
Michal Suchanek 4a894aeaeb depmod: shut up gcc insufficinet buffer warning
In a couple of places depmod concatenates the module directory and filename
with snprintf. This can technically overflow creating an unterminated string if
module directory name is long. Use openat instead as is done elsewhere in
depmod. This avoids the snprintf, the extra buffer on stack, and the gcc
warning. It may even fix a corner case when the module direcotry name is just
under PATH_MAX.

[ Lucas: fix up coding style and closing fd on error path ]

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2018-12-17 15:31:55 -08:00
Michal Suchanek a06bacf500 depmod: prevent module dependency files corruption due to parallel invocation.
Depmod does not use unique filename for temporary files. There is no
guarantee the user does not attempt to run mutiple depmod processes in
parallel. If that happens a temporary file might be created by
depmod(1st), truncated by depmod(2nd), and renamed to final name by
depmod(1st) resulting in corrupted file seen by user.

Due to missing mkstempat() this is more complex than it should be.
Adding PID and timestamp to the filename should be reasonably reliable.
Adding O_EXCL as mkstemp does fails creating the file rather than
corrupting existing file.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2018-12-17 15:10:05 -08:00
Michal Suchanek c2996b5fa8 depmod: prevent module dependency files missing during depmod invocation
depmod deletes the module dependency files before moving the temporary
files in their place. This results in user seeing no dependency files
while they are updated. Remove the unlink call. The rename call should
suffice to move the new file in place and unlink the old one. It should
also do both atomically so there is no window when no dependency file
exists.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2018-12-17 10:19:50 -08:00
Yauheni Kaliuta 3ada8df85c modprobe: add --show-exports
modprobe has --show-modversions switch, which dumps symbols with
their modversion crcs from the __versions sections.

At the moment the section contains information for the dependency
symbols only, while exported symbols add to symtab entries with
__crc_ prefix (the format may differ, see 1e48901166 libkmod-elf:
resolve CRC if module is built with MODULE_REL_CRCS).

The patch makes it to show exported symbols as well.

The function is basically cut'n'paste of show_modversions(),
but 'version' family replaced with 'symbol' one.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2018-11-13 09:50:49 -08:00
Yauheni Kaliuta bb83f6ac68 depmod: module_is_higher_priority: fix modname length calculation
depmod_module_is_higher_priority checks module's path if it is under
module root directory and if so uses relative to the root path to
lookup the module in override and search lists.

Originally only relative path was used in the function, so the
variables with full path and and path length were changed:

       newpath += cfg->dirnamelen + 1;
       newlen -= cfg->dirnamelen + 1;
       oldpath += cfg->dirnamelen + 1;
       oldlen -= cfg->dirnamelen + 1;

Commit 7da6884e73 (depmod: implement
external directories support) changed the logic since it need the
full path to the module for comparations as well.

Unfortunately, it introduce a mistake in calculation of the relative
paths replacing '-=' with assignment to a new variable -- the
'cfg->dirnamelen + 1' value must be substracted all together. It
breaks, for example, overrides lookup.

Fix the calculation by putting braces around the value in the
subsctuction expression.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-12-07 13:08:23 -08:00
Michal Suchanek e22e1c1f6e depmod: Don't add .TOC. when it's in the kernel.
d46136bb59 ("depmod: Ignore PowerPC64 ABIv2 .TOC. symbol") adds fake
.TOC. unconditionally but when there is .TOC. in the kernel adding the
fake one breaks resolving .TOC.

Fixes: d46136bb59 ("depmod: Ignore PowerPC64 ABIv2 .TOC. symbol")

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2017-12-07 11:04:37 -08: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
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
Lucas De Marchi 3200780813 depmod: fix leak on error path 2017-02-23 23:18:02 -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
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
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
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
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