diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-03-31 13:15:58 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-03-31 13:15:58 +0200 |
commit | af5277f883e8fc2e0236aa9ecc5115ecaffd0ccb (patch) | |
tree | 1a609920375bc1e1aab72ca661185df9c8d7ed0d | |
parent | 470fa7b3648da2ea120d65fa7cde69cad0421353 (diff) | |
download | busybox-w32-af5277f883e8fc2e0236aa9ecc5115ecaffd0ccb.tar.gz busybox-w32-af5277f883e8fc2e0236aa9ecc5115ecaffd0ccb.tar.bz2 busybox-w32-af5277f883e8fc2e0236aa9ecc5115ecaffd0ccb.zip |
modprobe: call finit_module with MODULE_INIT_COMPRESSED_FILE if module name doesn't end with .ko
IOW: if name doesn't end with .ko, assume it's .gz/.xz or similar,
and ask kernel to uncompress it.
If finit_module(MODULE_INIT_COMPRESSED_FILE) fails, retry with
finit_module(0).
function old new delta
bb_init_module 151 197 +46
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | modutils/modprobe-small.c | 12 | ||||
-rw-r--r-- | modutils/modutils.c | 12 |
2 files changed, 22 insertions, 2 deletions
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c index b61651621..77e42e3fb 100644 --- a/modutils/modprobe-small.c +++ b/modutils/modprobe-small.c | |||
@@ -33,6 +33,9 @@ | |||
33 | #define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) | 33 | #define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) |
34 | #ifdef __NR_finit_module | 34 | #ifdef __NR_finit_module |
35 | # define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags) | 35 | # define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags) |
36 | # ifndef MODULE_INIT_COMPRESSED_FILE | ||
37 | # define MODULE_INIT_COMPRESSED_FILE 4 | ||
38 | # endif | ||
36 | #endif | 39 | #endif |
37 | /* linux/include/linux/module.h has limit of 64 chars on module names */ | 40 | /* linux/include/linux/module.h has limit of 64 chars on module names */ |
38 | #undef MODULE_NAME_LEN | 41 | #undef MODULE_NAME_LEN |
@@ -272,7 +275,14 @@ static int load_module(const char *fname, const char *options) | |||
272 | { | 275 | { |
273 | int fd = open(fname, O_RDONLY | O_CLOEXEC); | 276 | int fd = open(fname, O_RDONLY | O_CLOEXEC); |
274 | if (fd >= 0) { | 277 | if (fd >= 0) { |
275 | r = finit_module(fd, options, 0) != 0; | 278 | int flags = is_suffixed_with(fname, ".ko") ? 0 : MODULE_INIT_COMPRESSED_FILE; |
279 | for (;;) { | ||
280 | r = finit_module(fd, options, flags); | ||
281 | if (r == 0 || flags == 0) | ||
282 | break; | ||
283 | /* Loading non-.ko named uncompressed module? Not likely, but let's try it */ | ||
284 | flags = 0; | ||
285 | } | ||
276 | close(fd); | 286 | close(fd); |
277 | } | 287 | } |
278 | } | 288 | } |
diff --git a/modutils/modutils.c b/modutils/modutils.c index f7ad5e805..cbff20961 100644 --- a/modutils/modutils.c +++ b/modutils/modutils.c | |||
@@ -12,6 +12,9 @@ | |||
12 | #define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts) | 12 | #define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts) |
13 | #if defined(__NR_finit_module) | 13 | #if defined(__NR_finit_module) |
14 | # define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags) | 14 | # define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags) |
15 | # ifndef MODULE_INIT_COMPRESSED_FILE | ||
16 | # define MODULE_INIT_COMPRESSED_FILE 4 | ||
17 | # endif | ||
15 | #endif | 18 | #endif |
16 | #define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) | 19 | #define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) |
17 | 20 | ||
@@ -217,7 +220,14 @@ int FAST_FUNC bb_init_module(const char *filename, const char *options) | |||
217 | { | 220 | { |
218 | int fd = open(filename, O_RDONLY | O_CLOEXEC); | 221 | int fd = open(filename, O_RDONLY | O_CLOEXEC); |
219 | if (fd >= 0) { | 222 | if (fd >= 0) { |
220 | rc = finit_module(fd, options, 0) != 0; | 223 | int flags = is_suffixed_with(filename, ".ko") ? 0 : MODULE_INIT_COMPRESSED_FILE; |
224 | for (;;) { | ||
225 | rc = finit_module(fd, options, flags); | ||
226 | if (rc == 0 || flags == 0) | ||
227 | break; | ||
228 | /* Loading non-.ko named uncompressed module? Not likely, but let's try it */ | ||
229 | flags = 0; | ||
230 | } | ||
221 | close(fd); | 231 | close(fd); |
222 | if (rc == 0) | 232 | if (rc == 0) |
223 | return rc; | 233 | return rc; |