public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] allow kernel module exclusion on load
@ 2007-05-13 13:25 Dan Aloni
  2007-05-13 16:23 ` Stephen Hemminger
  2007-05-14 20:23 ` Valdis.Kletnieks
  0 siblings, 2 replies; 17+ messages in thread
From: Dan Aloni @ 2007-05-13 13:25 UTC (permalink / raw)
  To: Linux Kernel List

Kernel developers might find it useful for quickly getting out from some 
rough debugging scenarios.

Signed-off-by: Dan Aloni <da-x@monatomic.org>

diff --git a/init/Kconfig b/init/Kconfig
index 4e009fd..796715e 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -682,6 +682,17 @@ config KMOD
 	  runs modprobe with the appropriate arguments, thereby
 	  loading the module if it is available.  If unsure, say Y.
 
+config MODULE_EXCLUSION
+	bool "Refuse loading of modules with certain names"
+	depends on MODULES && DEBUG_KERNEL
+	help
+	  During kernel module development and debugging you might come
+	  into a situation where one of your kernel modules crashes the
+	  kernel on boot. This option lets you specify in the kernel
+	  command line (via exclude-modules=) a comma-separated list 
+	  of kernel modules that the kernel will refuse to load based 
+	  on their names.
+
 config STOP_MACHINE
 	bool
 	default y
diff --git a/kernel/module.c b/kernel/module.c
index 9bd93de..14457dd 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1551,6 +1551,27 @@ static inline void add_kallsyms(struct module *mod,
 }
 #endif /* CONFIG_KALLSYMS */
 
+#ifdef CONFIG_MODULE_EXCLUSION
+
+static char exclusion_names[0x100];
+static int __init module_exclusion_setup(char *str)
+{
+	snprintf(exclusion_names, sizeof(exclusion_names), ",%s,", str);
+	return 1;
+}
+__setup("exclude-modules=", module_exclusion_setup);
+
+static int is_module_excluded(const char *name)
+{
+	char lookup_str[MODULE_NAME_LEN+3];
+	snprintf(lookup_str, sizeof(lookup_str), ",%s,", name);
+	return strstr(exclusion_names, lookup_str) != NULL;
+}
+
+#else
+static inline int is_module_excluded(const char *name) {return 0;}
+#endif
+
 /* Allocate and load the module: note that size of section 0 is always
    zero, and we rely on this for optional sections. */
 static struct module *load_module(void __user *umod,
@@ -1714,6 +1735,11 @@ static struct module *load_module(void __user *umod,
 		goto free_hdr;
 	}
 
+	if (is_module_excluded(mod->name)) {
+		err = -EACCES;
+		goto free_mod;
+	}
+
 	if (find_module(mod->name)) {
 		err = -EEXIST;
 		goto free_mod;


-- 
Dan Aloni
XIV LTD, http://www.xivstorage.com
da-x (at) monatomic.org, dan (at) xiv.co.il

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2007-05-16 21:58 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-13 13:25 [PATCH] allow kernel module exclusion on load Dan Aloni
2007-05-13 16:23 ` Stephen Hemminger
2007-05-13 17:05   ` Nikita V. Youshchenko
2007-05-13 17:15   ` Dan Aloni
2007-05-13 18:04     ` Michael Tokarev
2007-05-13 18:22       ` Dan Aloni
2007-05-13 18:32         ` Michael Tokarev
2007-05-13 18:20   ` Christoph Hellwig
2007-05-13 18:39     ` Michael Tokarev
2007-05-15  8:23     ` Pavel Machek
2007-05-16 16:51       ` Dan Aloni
2007-05-16 19:33         ` Pavel Machek
2007-05-16 21:09           ` Dan Aloni
2007-05-16 22:00             ` Randy Dunlap
2007-05-15 13:07     ` Andi Kleen
2007-05-14 20:23 ` Valdis.Kletnieks
2007-05-15  8:48   ` Dan Aloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox