summaryrefslogtreecommitdiff
path: root/kmodloader.c
Commit message (Collapse)AuthorAgeFilesLines
* kmodloader: fix GCC fanalyzer warningsRosen Penev2022-08-131-0/+12
| | | | | | memory leaks and missing NULL checks. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* kmodloader: fix bad realloc usageRosen Penev2022-08-131-2/+4
| | | | | | | Both cppcheck and gcc's -fanalyzer complain here that realloc is being used improperly. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* kmodloader: fix compilation warning with not checking return of asprintfChristian Marangi2022-07-171-7/+15
| | | | | | | | | | | | | | | Fix the following compilation warning: kmodloader.c: In function 'main_loader': kmodloader.c:1027:41: error: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result' [-Werror=unused-result] make[1]: *** [package/Makefile:116: package/system/ubox/compile] Error 1 1027 | asprintf(&m->opts, "%s %s", prev, opts); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ While at it rework the function to not duplicate too much code with the error handling. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* kmodloader: support loading module options and blacklist from /etc/modules.confFelix Fietkau2022-01-061-6/+111
| | | | | | This has the same format as /etc/modules.d on a regular linux system Signed-off-by: Felix Fietkau <nbd@nbd.name>
* kmodloader: added -a arg to modprobeGerard Ryan2019-12-311-30/+38
| | | | | | | | | | | -a treats all non-op trailing arguments as module names and attempts to load all of them. This behaviour mirrors the behaviour of the respective -a in /tools/modprobe.c from https://git.kernel.org. This is primarily to satiate the multiple modules passed by docker/libnetwork. Signed-off-by: Gerard Ryan <G.M0N3Y.2503@gmail.com>
* kmodloader: print an error when no kernel module dir can be foundPaul Fertser2019-12-281-1/+3
| | | | | | | | Do not just silently fail when kernel modules are nowhere to be found. This is essential for diagnosing mismatched kernel version failures. Signed-off-by: Paul Fertser <fercerpav@gmail.com>
* kmodloader: added -v arg to modeprobeGerard Ryan2019-10-211-2/+12
| | | | | | This is primarily to satiate the usage by docker/libnetwork. Signed-off-by: Gerard Ryan <G.M0N3Y.2503@gmail.com>
* kmodloader: Increase path array size to make it always fitHauke Mehrtens2019-06-161-1/+1
| | | | | | | | | | | | | When DEF_MOD_PATH (10 bytes), s (max 255 bytes) and ver.release (max 64 bytes) are all written into path, 256 bytes will not fit, increase the available size. All given sizes are given without terminating NULL byte and we add one byte to store the NULL byte. GCC 9.1 warns about this condition and we treat warnings as errors in ubox. Reported-by: Joseph Benden <joe@benden.us> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* kmodloader: fix and optimize loading of failed modulesPavel Merzlyakov2019-04-071-15/+24
| | | | | | | | | | | | | | | | | | | | | | | 1) Restore functionality which was lost in commit 876c7f5b. Again at boot time kmodloader can load all modules (/etc/modules.d/*) even if dependency information is completely missing. This functionality is important in case of hidden dependency (not symbol dependency). For example, in kernel 4.4.60 is hidden dependency between nf_nat_ipv6 and nf_conntrack_ipv6. We can't load nf_nat_ipv6 before nf_conntrack_ipv6 and modinfo do not show this dependency. Two sequential load attempts of nf_nat_ipv6 may not be enough (in my case it's definitely not enough). nf_nat_ipv4 has a similar problem. 2) Reduce count of attempts to load failed modules. Now kmodloader try to load failed modules after all others are loaded. main_loader: Count of failed and successful attempts to load nf_nat_ipv6.ko (kernel 4.4.60) depend on ubox version: COMMIT FAILED SUCCESSFUL TOTAL 128bc35f 53 1 54 876c7f5b 2 0 2 this 1 1 2 Signed-off-by: Pavel Merzlyakov <pavel.merzlyakov@gmail.com> Acked-by: Jo-Philipp Wich <jo@mein.io>
* kmodloader: increase module name lengthSergiy Kibrik2019-03-211-1/+3
| | | | | | Otherwise modules with long names, e.g. lttng (>32 chars) can't be loaded. Signed-off-by: Sergiy Kibrik <sakib@darkstar.site>
* kmodloader: load_modprobe: abort after 2 attemptsStijn Tintel2018-12-181-2/+4
| | | | | | | | | | | | | | | | | | | | | The loop in load_modprobe causes dmesg to be flooded with errors when a module fails to load; e.g.: - gpio-nct5104d: Unsupported device 0xffff (246 times on x86 in Qemu) - jitterentropy: Initialization failed with host not compliant with requirements: 2 (229 times on brcm2708/bcm2708) On brcm2708/bcm2708 this also causes vmalloc allocation failures with kernel 4.14 when running headless. If kmod-drm-vc4 and kmod-video-bcm2835 are included in the image, they will be loaded before brcmfmac, and brcmfmac will fail to load: kmodloader: vmalloc: allocation failure: 249856 bytes, mode:0x14000c0(GFP_KERNEL), nodemask=(null) Break the loop after 2 failed attempts to fix these issues. Signed-off-by: Jo-Philipp Wich <jo@mein.io> Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
* kmodloader: log error message in case of out of memoryHans Dedecker2017-09-011-3/+10
| | | | | | Log "out of memory" error message in case of OOM Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* kmodloader: lift restriction on module alias infoHans Dedecker2017-08-311-10/+16
| | | | | | | | | | | kmodloader has a restriction of storing only 32 aliases for a given module; as modules can have easily more than 32 aliases let's remove the restriction by using a dynamic allocation mechanism when retrieving the aliases. While at it also check the get_module_info return value setting an error code in case NULL is returned. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* kmodloader: fix possible segfaultsHans Dedecker2017-08-311-0/+12
| | | | Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* kmodloader: fix endianess checkHans Dedecker2017-08-301-2/+2
| | | | | | | | | | Use __BYTE_ORDER macro to check system endianess as the macro's __LITTLE_ENDIAN, __BIG_ENDIAN are defined irrespective of the sytem endianess leading to an endianess check failure on big endian systems. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> Acked-by: John Crispin <john@phrozen.org>
* kmodloader: Check module endian before loadingFlorian Fainelli2017-07-021-0/+13
| | | | | | | | | | | | | | | | | If we manage to accidentally get a module installed that does not match the system endianess (there is currently nothing preventing that in OpenWrt/LEDE) we will hit a segmentation fault when doing this: sh = (Elf32_Shdr *) (map + e->e_shoff); because e->e_shoff will be wrongly encoded and this most likely will result in an invalid offset to de-reference from. Update elf_find_section() to check that the build time endianess of kmodloader matches that of the module, otherwise nothing would work really. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* kmodloader/get_module_info: initialized aliases to make it more cleanAlexander Couzens2017-06-111-1/+1
| | | | | | | | Even when the callee looks onto the length is a good idea to zero the points. Found-by: Coverity Scan #1412541 Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
* kmodloader: insmod: fix a memoryleak in error caseAlexander Couzens2017-06-111-4/+6
| | | | | Found-by: Coverity Scan #1412469 Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
* kmodloader/get_module_name: null-terminate the stringAlexander Couzens2017-06-111-2/+2
| | | | | Found-by: Coverity Scan #1412291 Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
* kmodloader: modprobe: return 0 for loaded modulesYousong Zhou2017-03-031-1/+1
| | | | | | | | | | | This is the default behaviour with modprobe from kmod package [1] unless it is explicitly told that the module is to be loaded for --first-time [1] http://www.kernel.org/pub/linux/utils/kernel/kmod/ Fixes FS#433 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* kmodloader: don't store aliases info in struct moduleYousong Zhou2017-02-231-28/+4
| | | | | | | | | | | | This also fixes FS#544 as the possible address alignment issue should now disappear function old new delta alloc_module 398 245 -153 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-153) Total: -153 bytes Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* kmodloader: fix not being able to find some modulesNathan Hintz2017-02-211-4/+7
| | | | | | | | | | kmodloader is using slightly different criteria for ordering the AVL tree versus what it uses to traverse it. This sometimes results in not being able to find some modules. Reference: https://bugs.lede-project.org/index.php?do=details&task_id=443 Signed-off-by: Nathan Hintz <nlhintz@hotmail.com>
* kmodloader: support '-q' quiet optionKevin Darbyshire-Bryant2017-02-011-10/+29
| | | | | | | | | | The kernel opportunistically attempts to load modules in advanced with 'predicted' module names. Often these modules don't exist and hence kmodloader produces lots of logfile noise. The kernel commandline to modprobe from kworker proceses is '-q -- modulename' where '-q' means quiet. Support suppressing that noise. Signed-off-by: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
* kmodloader: make insert_module() idempotentYousong Zhou2017-01-151-1/+4
| | | | | | | | | | | | To fix spurious error messages in the following situation 1. scan loaded modules 2. load wireguard.ko and the module itself will request xt_hashlimit to be loaded 3. xt_hashlimit is still in PROBE state here so we also try to load it, but init_module() returns EEXIST Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* kmodloader: add module alias awarenessYousong Zhou2017-01-151-23/+129
| | | | | | | | | | | | | To achieve this, the following changes are made - scan module folders before scaning loaded modules - struct module was splited into struct module_node for the avl tree and struct module for storing actual info about modules The other minor fix is that module.opts is now freed in free_modules() when appliable Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* kmodloader: fix out-of-bound access when parsing .modinfoYousong Zhou2017-01-151-2/+6
| | | | | | | | | | | | | Fixes output of "modinfo nf_conntrack_ipv4" module: /lib/modules/4.4.40/nf_conntrack_ipv4.ko license: GPL alias: ip_conntrack alias: nf_conntrack-2 depends: nf_conntrack,nf_defrag_ipv4 src: %pI4 dst=%pI4 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* kmodloader: modprobe: skip possible command line argumentsYousong Zhou2017-01-151-2/+9
| | | | | | | | The kernel may invocate user mode modprobe with the following scheme modprobe -q -- <module_name> Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* kmodloader: log to kmsg when loading directories of modulesYousong Zhou2017-01-151-2/+4
| | | | | | syslog may not be ready yet before PREINIT Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* kmodloader: remove redundant glob wildcard charYousong Zhou2017-01-151-1/+1
| | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* ubox: Fix some memory leaksRosen Penev2016-12-191-2/+6
| | | | | | Avoids leaking memory when exiting early. Signed-off by: Rosen <rosenp@gmail.com>
* kmodloader: Fix typo in error messageFlorian Fainelli2016-12-041-1/+1
| | | | Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* fix segfault in kmodloader when no modules path was presentJohn Crispin2016-08-171-1/+4
| | | | Signed-off-by: John Crispin <john@phrozen.org>
* kmodloader: fix lsmod depends outputHauke Mehrtens2016-07-191-4/+15
| | | | | | | Without this patch only the first dependency is shown, with this patch all module dependencies are show. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* kmodloader: fix NULL pointer deref in case m->depends is missingFelix Fietkau2016-03-071-1/+1
| | | | | | Observed on an invalid module Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* kmodloader: clean up memory mapping and fix fd leaks in error handlingJo-Philipp Wich2016-02-091-15/+31
| | | | Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* kmodloader: fix open() error handlingJo-Philipp Wich2016-02-091-3/+3
| | | | | | | Fixes kmodloader on systems without stdio and prevents fd leaks in case descriptor zero is opened. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* syslog: use appropriate levels for loggingChristian Mehlis2015-03-271-1/+1
| | | | Signed-off-by: Christian Mehlis <christian@m3hlis.de>
* kmodloader: initialize module folders in insmodJo-Philipp Wich2015-02-261-0/+2
| | | | | | | Fixes a segmentation fault in 'insmod' operation mode, due to uninitialized path list. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* kmodloader: convert to ulog() apiJo-Philipp Wich2015-02-251-48/+35
| | | | Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* kmodloader: search kmods relative to LD_LIBRARY_PATHJo-Philipp Wich2015-02-251-18/+73
| | | | | | | | When LD_LIBRARY_PATH is set, then scan for kmods in each directory pointed to by it. This is mainly useful for early boot invocations of kmodloader, e.g. during the extroot setup phase. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* Use different loglevelsMichel Stam2014-10-021-34/+41
| | | | | | | | | Ubox logs various messages during OpenWRT boot which are not very interesting, such as the number of iterations made. This fix implements several loglevels for debug/info/error so that more useful messages are shown. Signed-off-by: Michel Stam <m.stam@fugro.nl>
* kmodloader: force size argument for syscall to unsigned long to fix issues ↵Felix Fietkau2014-05-281-1/+1
| | | | | | with musl Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* kmodloader: fix insmod when the passed parameter is a valid pathJohn Crispin2014-02-261-1/+3
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* kmodloader: allow /etc/modules.d/ files to pass optionsJohn Crispin2014-01-221-1/+5
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* kmodloader: fix elf header parsing on 64bit machinesJohn Crispin2014-01-161-5/+17
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* fix bogus kmodloader warningJohn Crispin2014-01-121-0/+5
| | | | | | https://dev.openwrt.org/ticket/14659 Signed-off-by: John Crispin <blogic@openwrt.org>
* revert 2fdd374f4214129d93f10b7001adece9239752a2John Crispin2013-11-161-3/+1
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* kmod-loader: fix module options support when using modprobeJohn Crispin2013-11-111-1/+3
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* kmodloader: respect global directory prefix in scan_module_folder()Jo-Philipp Wich2013-10-141-2/+2
|
* kmodloader: use the name of the found module struct for modinfoJo-Philipp Wich2013-09-281-4/+15
| | | | | | | | | | | | The module .ko file might be called differently than the name used by the kernel internally, e.g. "nls_iso8859-1.ko" is called "nls_iso8859_1" in lsmmod. The print_modinfo() procedure expects the filename spelling in order to successfully resolve the full module path. After this change, "modinfo" supports printing module info even if the user gives the kernel internal spelling instead of the file name one, so that e.g. "modinfo "nls_iso8859_1" and "modinfo nls_iso8859-1.ko" will both succeed.