summaryrefslogtreecommitdiff
path: root/tools
AgeCommit message (Collapse)AuthorFilesLines
2020-12-01depmod: output_builtin_alias_bin: free idx on error pathYauheni Kaliuta1-7/+4
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-03-13depmod: do not output .bin to stdoutLucas De Marchi1-1/+5
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: b866b2165ae6 ("Lookup aliases in the modules.builtin.modinfo")
2019-12-18modinfo: Show information about built-in modulesAlexey Gladkov1-18/+21
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2019-12-18Lookup aliases in the modules.builtin.modinfoAlexey Gladkov1-0/+63
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-11-07modprobe: use flags rather than bool argsLucas De Marchi1-8/+8
It's easier to know what the caller is doing when we pass a named flag rather than a list of bools.
2019-11-06modprobe: ignore builtin module on recursive removingYauheni Kaliuta1-6/+12
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-03-08tools: Print a message if refcnt attribute is missingEzequiel Garcia2-6/+12
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.
2018-12-17depmod: shut up gcc insufficinet buffer warningMichal Suchanek1-16/+38
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-17depmod: prevent module dependency files corruption due to parallel invocation.Michal Suchanek1-2/+7
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-17depmod: prevent module dependency files missing during depmod invocationMichal Suchanek1-1/+0
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-11-13modprobe: add --show-exportsYauheni Kaliuta1-0/+36
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 1e48901166ef 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>
2017-12-07depmod: module_is_higher_priority: fix modname length calculationYauheni Kaliuta1-2/+2
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 7da6884e7357ac05772e90f6d7e63b1948103fc4 (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-07depmod: Don't add .TOC. when it's in the kernel.Michal Suchanek1-1/+2
d46136bb59c4 ("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: d46136bb59c4 ("depmod: Ignore PowerPC64 ABIv2 .TOC. symbol") Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2017-06-01depmod: implement external directories supportYauheni Kaliuta1-22/+150
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-01depmod: rewrite depmod modules search with scratchbufYauheni Kaliuta1-12/+21
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-01depmod: create depmod dir independent search functionYauheni Kaliuta1-9/+22
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-05-09depmod: search key: move builtin detection under the add functionYauheni Kaliuta1-4/+4
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-08depmod: fix errorpath memleaks in report cycles logicYauheni Kaliuta1-17/+37
The c7ce9f0c80f3d561078a78205a14c5ba7663cfdd 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-02-23depmod: fix leak on error pathLucas De Marchi1-1/+2
2017-02-22depmod: handle nested loopsYauheni Kaliuta1-84/+211
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>
2016-11-08depmod: ignore related modules in depmod_report_cyclesMian Yousaf Kaukab1-1/+12
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-08-15depmod: fix string overflowLucas De Marchi1-2/+19
Use scratchbuf to fix issue with strcpy that may overflow the buffer we declared in the stack.
2016-06-11depmod: Ignore PowerPC64 ABIv2 .TOC. symbolAnton Blanchard1-0/+2
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-01-11depmod: Don't insert comment in modules.devname if otherwise emptyJosh Triplett1-4/+8
This allows tools to detect the file as empty, such as via systemd's ConditionFileNotEmpty.
2015-11-20insmod: fix wron fallthrough of -fMarc-Antoine Perennou1-0/+2
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2015-10-25insmod: do support -fPhilippe De Swert1-2/+4
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-09-30depmod: Don't fall back to uname on bad versionLaura Abbott1-1/+5
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-30depmod: Remove unprinted debug messagesLaura Abbott1-4/+1
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-30Change default log levelLaura Abbott1-1/+1
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-30modprobe: Update error message when path is missingLaura Abbott1-4/+3
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-06-08tools: display features in --versionLucas De Marchi6-0/+6
Reviewed-by: Andreas Mohr <andim2@users.sf.net>
2015-06-08tools: add PACKAGE definition in messageLucas De Marchi1-1/+1
Reported-by: Andreas Mohr <andim2@users.sf.net>
2015-06-06tools: Hide new commands behind experimental flagLucas De Marchi1-2/+5
Hide the commands behind a flag so we can continue doing releases while the commands aren't ready.
2015-04-16Fix spurious spaces in lsmod outputSantiago Vila1-3/+5
While using "localyesconfig" to build a custom kernel I noticed that lsmod output now has trailing spaces when the list of "Used by" modules is empty. The following patch just delays the space to the point where we are sure that there are more things to print.
2015-03-07tools: add basic versions of insert and removeCaio Marcelo de Oliveira Filho4-0/+282
2015-02-28depmod: add asserts to ensure positive return from ftell()Lucas De Marchi1-2/+4
Also ignore some errors that will later be returned by ferror().
2015-02-28modprobe: stop checking initstate for builtin modulesLucas De Marchi1-30/+4
builtin modules are handled in libkmod by looking at the modules.builtin index. There's no need to check again for the module's initstate to decide if it's builtin.
2015-02-26depmod: fix leak in case of malloc(0)Lucas De Marchi1-1/+2
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-25depmod: use cleanup attribute to simplify free on exitLucas De Marchi1-12/+5
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-25depmod: Fix crash in previous commit if root is not setColin Walters1-1/+1
[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-25depmod: fix leaking root on exitLucas De Marchi1-1/+5
2015-01-14tools: prefer the use of streq()Lucas De Marchi2-8/+9
2015-01-14tools: kmod: use streqLucas De Marchi1-3/+5
2015-01-14tools: kmod: break iteration once a command is executedCaio Marcelo de Oliveira Filho1-4/+4
2015-01-02Fix includes after change to build-sysLucas De Marchi8-8/+8
Make the includes be libkmod/libkmod.h for code outside of library. This fixes the broken build after 1315123 ('build-sys: Don't add libkmod subdirectory to include path').
2014-11-15depmod: point to documentation in libkmodLucas De Marchi1-101/+2
Instead of repeating all documentation, point to the documentation available in libkmod-index.c This also removes INDEX_PRIORITY_MIN that was not being used.
2014-10-28static-nodes: indicate that creation of static nodes should only happen at bootTom Gundersen1-1/+1
udev will only manage static nodes that exist at the time udev is started, so creating static nodes later on will likely not behave as expected. In particular, recreating the static nodes at run-time will reset any permissions udev may have applied to the nodes at boot. See <https://bugzilla.redhat.com/show_bug.cgi?id=1147248> and the discussion following <http://permalink.gmane.org/gmane.comp.sysutils.systemd.devel/23795>. Note that this requires (the yet to be released) systemd v217 or a backport of systemd patch 8c94052ee543c3598a3c7b0c46688150aa2c6168.
2014-10-09Move remaining functions from libkmod-util to sharedLucas De Marchi2-2/+2
2014-10-09depmod: use alias_normalize() from sharedLucas De Marchi1-38/+5
Remove underscores2() function which is essentially the same as alias_normalize() and the latter, which is now in shared/.
2014-10-09Do not rely on prio_to_str() being always inlineLucas De Marchi1-5/+10
This function was declared as always-inline so there was not really a problem in returning prioname, that could possibly point to the local buf[] variable. However static analysis tools are often confused about this and being always-inline was just a workaround to make it work. So, let's move the buffer to the caller. We have only 2 callers so it doesn't matter much. This always reduce the size of log.o, since now the function is not inlined anymore. Below is the size for "-g -O2" with gcc: before: text data bss dec hex filename 1325 4 1 1330 532 tools/log.o after: text data bss dec hex filename 1171 4 1 1176 498 tools/log.o