public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: torvalds@transmeta.com
Cc: linux-kernel@vger.kernel.org, tridge@samba.org,
	Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
Subject: [PATCH] Check compiler version, SMP and PREEMPT.
Date: Mon, 13 Jan 2003 16:13:19 +1100	[thread overview]
Message-ID: <20030113051434.DC2092C09F@lists.samba.org> (raw)

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);

             reply	other threads:[~2003-01-13  5:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-13  5:13 Rusty Russell [this message]
2003-01-13  5:29 ` [PATCH] Check compiler version, SMP and PREEMPT 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030113051434.DC2092C09F@lists.samba.org \
    --to=rusty@rustcorp.com.au \
    --cc=kai@tp1.ruhr-uni-bochum.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    --cc=tridge@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox