lkml.org 
[lkml]   [2003]   [Jan]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] Check compiler version, SMP and PREEMPT.
Date
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);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 13:32    [W:0.088 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site