[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox-cvs
Subject:    [git commit] modprobe: call finit_module with MODULE_INIT_COMPRESSED_FILE if module name doesn't end
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2023-03-31 11:15:58
Message-ID: 20230331111934.413F383708 () busybox ! osuosl ! org
[Download RAW message or body]

commit: https://git.busybox.net/busybox/commit/?id=af5277f883e8fc2e0236aa9ecc5115ecaffd0ccb
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

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>
---
 modutils/modprobe-small.c | 12 +++++++++++-
 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 @@
 #define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
 #ifdef __NR_finit_module
 # define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags)
+# ifndef MODULE_INIT_COMPRESSED_FILE
+#  define MODULE_INIT_COMPRESSED_FILE 4
+# endif
 #endif
 /* linux/include/linux/module.h has limit of 64 chars on module names */
 #undef MODULE_NAME_LEN
@@ -272,7 +275,14 @@ static int load_module(const char *fname, const char *options)
 	{
 		int fd = open(fname, O_RDONLY | O_CLOEXEC);
 		if (fd >= 0) {
-			r = finit_module(fd, options, 0) != 0;
+			int flags = is_suffixed_with(fname, ".ko") ? 0 : MODULE_INIT_COMPRESSED_FILE;
+			for (;;) {
+				r = finit_module(fd, options, flags);
+				if (r == 0 || flags == 0)
+					break;
+				/* Loading non-.ko named uncompressed module? Not likely, but let's try it */
+				flags = 0;
+			}
 			close(fd);
 		}
 	}
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 @@
 #define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts)
 #if defined(__NR_finit_module)
 # define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags)
+# ifndef MODULE_INIT_COMPRESSED_FILE
+#  define MODULE_INIT_COMPRESSED_FILE 4
+# endif
 #endif
 #define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
 
@@ -217,7 +220,14 @@ int FAST_FUNC bb_init_module(const char *filename, const char *options)
 	{
 		int fd = open(filename, O_RDONLY | O_CLOEXEC);
 		if (fd >= 0) {
-			rc = finit_module(fd, options, 0) != 0;
+			int flags = is_suffixed_with(filename, ".ko") ? 0 : MODULE_INIT_COMPRESSED_FILE;
+			for (;;) {
+				rc = finit_module(fd, options, flags);
+				if (rc == 0 || flags == 0)
+					break;
+				/* Loading non-.ko named uncompressed module? Not likely, but let's try it */
+				flags = 0;
+			}
 			close(fd);
 			if (rc == 0)
 				return rc;
_______________________________________________
busybox-cvs mailing list
busybox-cvs@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic