[PATCH] modprobe.blacklist implementation

Serj Kalichev serj.kalichev at gmail.com
Wed Apr 6 10:18:47 UTC 2016


The patch to implement kernel module blacklist using
kernel command line. Use modprobe.blacklist=mod1,mod2 to
blacklist modules. It's compatible to original modprobe.

Signed-off-by: Serj Kalichev <serj.kalichev at gmail.com>
---
 modutils/Config.src | 13 +++++++++++++
 modutils/modprobe.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/modutils/Config.src b/modutils/Config.src
index 0b11832..e94f00b 100644
--- a/modutils/Config.src
+++ b/modutils/Config.src
@@ -108,6 +108,19 @@ config FEATURE_MODPROBE_BLACKLIST
 	  hardware autodetection scripts to load modules like evdev, frame
 	  buffer drivers etc.
 
+config FEATURE_MODPROBE_KCMDLINE_BLACKLIST
+	bool "Kernel cmdline blacklist support"
+	default n
+	depends on MODPROBE
+	select PLATFORM_LINUX
+	help
+	  Say 'y' here to enable support for the 'modprobe.blacklist' in
+	  kernel command line. This feature is used to disable buggy
+	  kernel modules. Use 'modprobe.blacklist=<mname1>,<mname2>' in
+	  kernel command line to blacklist modules with names <mname1>,
+	  <mname2>. The separator is comma. This feature is compatible with
+	  original modprobe utility.
+
 config DEPMOD
 	bool "depmod"
 	default n
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index 8130c40..9adafde 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -366,6 +366,32 @@ static char *parse_and_add_kcmdline_module_options(char *options, const char *mo
 	return options;
 }
 
+#if ENABLE_FEATURE_MODPROBE_KCMDLINE_BLACKLIST
+static void parse_kcmdline_blacklist(void)
+{
+	char *kcmdline_buf;
+	char *kcmdline;
+	char *kptr;
+
+	kcmdline_buf = xmalloc_open_read_close("/proc/cmdline", NULL);
+	if (!kcmdline_buf)
+		return;
+
+	kcmdline = kcmdline_buf;
+	while ((kptr = strsep_quotes(&kcmdline)) != NULL) {
+		char *mline;
+		char *after_modulename = is_prefixed_with(kptr, "modprobe.blacklist=");
+		if (!after_modulename || !*after_modulename)
+			continue;
+		mline = after_modulename;
+		while ((kptr = strsep(&mline, ",")) != NULL) {
+			get_or_add_modentry(kptr)->flags |= MODULE_FLAG_BLACKLISTED;
+		}
+	}
+	free(kcmdline_buf);
+}
+#endif
+
 /* Return: similar to bb_init_module:
  * 0 on success,
  * -errno on open/read error,
@@ -621,6 +647,11 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
 		load_modules_dep();
 	}
 
+#if ENABLE_FEATURE_MODPROBE_KCMDLINE_BLACKLIST
+	/* Get blacklist from kernel cmdline */
+	parse_kcmdline_blacklist();
+#endif
+
 	rc = 0;
 	while ((me = llist_pop(&G.probes)) != NULL) {
 		if (me->realnames == NULL) {
-- 
1.9.1



More information about the busybox mailing list