public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Check compiler version, SMP and PREEMPT.
@ 2003-01-13  5:13 Rusty Russell
  2003-01-13  5:29 ` Linus Torvalds
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Rusty Russell @ 2003-01-13  5:13 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel, tridge, Kai Germaschewski

Linus, please apply if you agree.

Tridge reported getting burned by gcc 3.2 compiled (Debian) XFree
modules not working on his gcc 2.95-compiled kernel.  Interestingly,
(as Tridge points out) modversions probably would not have caught the
change in spinlock size, since the ioctl takes a void*, not a
structure pointer...

Simple bitmask, allows extension later, and prevents this kind of
thing (maybe a warning is more appropriate: this refuses to load it).

Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Module Sanity Check
Author: Rusty Russell
Status: Tested on 2.5.56

D: Stores a simple bitmask in the module structure, for SMP, PREEMPT
D: and compiler version (spinlocks change size on UP with gcc major,
D: at least).  Also printks on modules with common section (becoming
D: an FAQ for third-party modules).

diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5-bk/include/linux/module.h working-2.5-bk-compilerversion/include/linux/module.h
--- linux-2.5-bk/include/linux/module.h	Mon Jan 13 11:17:32 2003
+++ working-2.5-bk-compilerversion/include/linux/module.h	Mon Jan 13 15:33:03 2003
@@ -32,6 +32,21 @@
 #define MODULE_SYMBOL_PREFIX ""
 #endif
 
+/* Simply sanity stamp to place in each module */
+#ifdef CONFIG_SMP
+#define MODULE_SANITY_SMP 1
+#else
+#define MODULE_SANITY_SMP 0
+#endif
+#ifdef CONFIG_PREEMPT
+#define MODULE_SANITY_PREEMPT 1
+#else
+#define MODULE_SANITY_PREEMPT 0
+#endif
+#define MODULE_SANITY						\
+	((MODULE_SANITY_SMP<<16) | (MODULE_SANITY_PREEMPT<<17) 	\
+	 | (__GNUC__<<8) | (__GNUC_MINOR__))
+
 #define MODULE_NAME_LEN (64 - sizeof(unsigned long))
 struct kernel_symbol
 {
@@ -168,6 +183,9 @@ struct module
 {
 	enum module_state state;
 
+	/* Simple compatibility bitmask (useful for non-modversions). */
+	int sanity;
+
 	/* Member of list of modules */
 	struct list_head list;
 
@@ -378,6 +396,7 @@ __attribute__((section(".gnu.linkonce.th
 #ifdef CONFIG_MODULE_UNLOAD
 	.exit = cleanup_module,
 #endif
+	.sanity = MODULE_SANITY,
 };
 #endif /* KBUILD_MODNAME */
 #endif /* MODULE */
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5-bk/kernel/module.c working-2.5-bk-compilerversion/kernel/module.c
--- linux-2.5-bk/kernel/module.c	Fri Jan 10 10:55:43 2003
+++ working-2.5-bk-compilerversion/kernel/module.c	Mon Jan 13 16:07:40 2003
@@ -846,6 +846,8 @@ static int simplify_symbols(Elf_Shdr *se
 			/* We compiled with -fno-common.  These are not
 			   supposed to happen.  */
 			DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name);
+			printk("%s: probably not cimpiled with -fno-common\n",
+			       mod->name);
 			return -ENOEXEC;
 
 		case SHN_ABS:
@@ -1094,6 +1096,13 @@ static struct module *load_module(void *
 		goto free_hdr;
 	}
 	mod = (void *)sechdrs[modindex].sh_addr;
+
+	if (mod->sanity != MODULE_SANITY) {
+		printk(KERN_ERR "Module %s version %08x not %08x\n",
+		       mod->name, mod->sanity, MODULE_SANITY);
+		err = -ENOEXEC;
+		goto free_hdr;
+	}
 
 	/* Now copy in args */
 	err = strlen_user(uargs);

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

end of thread, other threads:[~2003-01-14  2:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-13  5:13 [PATCH] Check compiler version, SMP and PREEMPT Rusty Russell
2003-01-13  5:29 ` Linus Torvalds
2003-01-13  6:51   ` Rusty Russell
2003-01-13 15:48     ` Kai Germaschewski
2003-01-14  0:21       ` Rusty Russell
2003-01-13  5:33 ` Keith Owens
2003-01-13  9:59 ` Arjan van de Ven
2003-01-13 15:19 ` Daniel Jacobowitz
2003-01-13 15:37   ` Kai Germaschewski

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