summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--arch/alpha/vmlinux.lds.S1
-rw-r--r--arch/arm/vmlinux-armo.lds.in1
-rw-r--r--arch/arm/vmlinux-armv.lds.in1
-rw-r--r--arch/cris/vmlinux.lds.S1
-rw-r--r--arch/i386/vmlinux.lds.S1
-rw-r--r--arch/ia64/vmlinux.lds.S2
-rw-r--r--arch/m68k/vmlinux-std.lds1
-rw-r--r--arch/m68k/vmlinux-sun3.lds2
-rw-r--r--arch/m68knommu/vmlinux.lds.S1
-rw-r--r--arch/mips/vmlinux.lds.S1
-rw-r--r--arch/mips64/ld.script.elf641
-rw-r--r--arch/mips64/vmlinux.lds.S1
-rw-r--r--arch/parisc/vmlinux.lds.S1
-rw-r--r--arch/ppc/vmlinux.lds.S1
-rw-r--r--arch/ppc64/boot/zImage.lds1
-rw-r--r--arch/s390/vmlinux.lds.S1
-rw-r--r--arch/s390x/vmlinux.lds.S1
-rw-r--r--arch/sh/vmlinux.lds.S1
-rw-r--r--arch/sparc64/vmlinux.lds.S1
-rw-r--r--arch/um/uml.lds.S1
-rw-r--r--arch/v850/vmlinux.lds.S1
-rw-r--r--arch/x86_64/vmlinux.lds.S1
-rw-r--r--include/asm-i386/module.h44
-rw-r--r--init/Makefile3
-rw-r--r--init/vermagic.c22
-rw-r--r--kernel/module.c24
-rw-r--r--scripts/Makefile.build13
28 files changed, 133 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 8d91ba80b3c9..85ec18889a20 100644
--- a/Makefile
+++ b/Makefile
@@ -394,6 +394,17 @@ $(SUBDIRS): .hdepend prepare
prepare: include/linux/version.h include/asm include/config/MARKER
@echo ' Starting the build. KBUILD_BUILTIN=$(KBUILD_BUILTIN) KBUILD_MODULES=$(KBUILD_MODULES)'
+# We need to build init/vermagic.o before descending since all modules
+# (*.ko) need it already
+
+ifdef CONFIG_MODULES
+
+prepare: init/vermagic.o
+
+init/vermagic.o: include/linux/version.h
+
+endif
+
# This can be used by arch/$ARCH/Makefile to preprocess
# their vmlinux.lds.S file
diff --git a/arch/alpha/vmlinux.lds.S b/arch/alpha/vmlinux.lds.S
index 20f7cadffedd..4f74c37cf20a 100644
--- a/arch/alpha/vmlinux.lds.S
+++ b/arch/alpha/vmlinux.lds.S
@@ -47,6 +47,7 @@ SECTIONS
}
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
.rodata : { *(.rodata) *(.rodata.*) }
/* Startup code */
diff --git a/arch/arm/vmlinux-armo.lds.in b/arch/arm/vmlinux-armo.lds.in
index ce2b98b67fdc..bb9322ae788b 100644
--- a/arch/arm/vmlinux-armo.lds.in
+++ b/arch/arm/vmlinux-armo.lds.in
@@ -64,6 +64,7 @@ SECTIONS
}
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16);
__ex_table : { /* Exception table */
diff --git a/arch/arm/vmlinux-armv.lds.in b/arch/arm/vmlinux-armv.lds.in
index 2f358b7a6a6a..db6a2c19051a 100644
--- a/arch/arm/vmlinux-armv.lds.in
+++ b/arch/arm/vmlinux-armv.lds.in
@@ -67,6 +67,7 @@ SECTIONS
}
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16);
__ex_table : { /* Exception table */
diff --git a/arch/cris/vmlinux.lds.S b/arch/cris/vmlinux.lds.S
index bc3231c2c3b0..a6e0915266a7 100644
--- a/arch/cris/vmlinux.lds.S
+++ b/arch/cris/vmlinux.lds.S
@@ -33,6 +33,7 @@ SECTIONS
.rodata : { *(.rodata) *(.rodata.__*) }
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(4); /* Exception table */
__start___ex_table = .;
diff --git a/arch/i386/vmlinux.lds.S b/arch/i386/vmlinux.lds.S
index 222deebc9e67..44f952659b70 100644
--- a/arch/i386/vmlinux.lds.S
+++ b/arch/i386/vmlinux.lds.S
@@ -20,6 +20,7 @@ SECTIONS
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/ia64/vmlinux.lds.S b/arch/ia64/vmlinux.lds.S
index 04a2fdf300d3..bc56a3c3cf98 100644
--- a/arch/ia64/vmlinux.lds.S
+++ b/arch/ia64/vmlinux.lds.S
@@ -90,6 +90,8 @@ SECTIONS
{ *(.rodata) *(.rodata.*) }
.kstrtab : AT(ADDR(.kstrtab) - PAGE_OFFSET)
{ *(.kstrtab) }
+ __vermagic : AT(ADDR(__vermagic) - PAGE_OFFSET)
+ { *(__vermagic) }
.opd : AT(ADDR(.opd) - PAGE_OFFSET)
{ *(.opd) }
diff --git a/arch/m68k/vmlinux-std.lds b/arch/m68k/vmlinux-std.lds
index d5ef5629f941..8d6d903be0fa 100644
--- a/arch/m68k/vmlinux-std.lds
+++ b/arch/m68k/vmlinux-std.lds
@@ -14,6 +14,7 @@ SECTIONS
} = 0x4e75
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/m68k/vmlinux-sun3.lds b/arch/m68k/vmlinux-sun3.lds
index 9c35357cb6f9..824da47fcccb 100644
--- a/arch/m68k/vmlinux-sun3.lds
+++ b/arch/m68k/vmlinux-sun3.lds
@@ -14,7 +14,7 @@ SECTIONS
*(.gnu.warning)
} = 0x4e75
.kstrtab : { *(.kstrtab) }
-
+ __vermagic : { *(__vermagic) }
_etext = .; /* End of text section */
diff --git a/arch/m68knommu/vmlinux.lds.S b/arch/m68knommu/vmlinux.lds.S
index 4325450429a5..262e725a8eaf 100644
--- a/arch/m68knommu/vmlinux.lds.S
+++ b/arch/m68knommu/vmlinux.lds.S
@@ -224,6 +224,7 @@ SECTIONS {
. = ALIGN(0x4) ;
*(.kstrtab)
+ *(__vermagic)
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/mips/vmlinux.lds.S b/arch/mips/vmlinux.lds.S
index d97c30432939..92dd587723cd 100644
--- a/arch/mips/vmlinux.lds.S
+++ b/arch/mips/vmlinux.lds.S
@@ -15,6 +15,7 @@ SECTIONS
*(.gnu.warning)
} =0
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/mips64/ld.script.elf64 b/arch/mips64/ld.script.elf64
index 16d1c0eeb045..0b36e34e900e 100644
--- a/arch/mips64/ld.script.elf64
+++ b/arch/mips64/ld.script.elf64
@@ -25,6 +25,7 @@ SECTIONS
*(.gnu.warning)
} = 0
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/mips64/vmlinux.lds.S b/arch/mips64/vmlinux.lds.S
index 4ffd13a3b49a..a6286d452f0d 100644
--- a/arch/mips64/vmlinux.lds.S
+++ b/arch/mips64/vmlinux.lds.S
@@ -14,6 +14,7 @@ SECTIONS
*(.gnu.warning)
} =0
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/parisc/vmlinux.lds.S b/arch/parisc/vmlinux.lds.S
index cb2260ff46e9..4aef57a7e501 100644
--- a/arch/parisc/vmlinux.lds.S
+++ b/arch/parisc/vmlinux.lds.S
@@ -34,6 +34,7 @@ SECTIONS
. = ALIGN(16);
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
.data BLOCK(8192) : { /* Data without special */
data_start = .;
diff --git a/arch/ppc/vmlinux.lds.S b/arch/ppc/vmlinux.lds.S
index 2b0a30627986..dd31c0424930 100644
--- a/arch/ppc/vmlinux.lds.S
+++ b/arch/ppc/vmlinux.lds.S
@@ -47,6 +47,7 @@ SECTIONS
*(.rodata1)
}
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
.fini : { *(.fini) } =0
.ctors : { *(.ctors) }
.dtors : { *(.dtors) }
diff --git a/arch/ppc64/boot/zImage.lds b/arch/ppc64/boot/zImage.lds
index e77113eb440b..f0a4179ab7a4 100644
--- a/arch/ppc64/boot/zImage.lds
+++ b/arch/ppc64/boot/zImage.lds
@@ -42,6 +42,7 @@ SECTIONS
*(.rodata1)
}
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
.fini : { *(.fini) } =0
.ctors : { *(.ctors) }
.dtors : { *(.dtors) }
diff --git a/arch/s390/vmlinux.lds.S b/arch/s390/vmlinux.lds.S
index 0310629bc544..505d7098ec2d 100644
--- a/arch/s390/vmlinux.lds.S
+++ b/arch/s390/vmlinux.lds.S
@@ -19,6 +19,7 @@ SECTIONS
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/s390x/vmlinux.lds.S b/arch/s390x/vmlinux.lds.S
index c8766744dd25..3e5032e51305 100644
--- a/arch/s390x/vmlinux.lds.S
+++ b/arch/s390x/vmlinux.lds.S
@@ -19,6 +19,7 @@ SECTIONS
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/sh/vmlinux.lds.S b/arch/sh/vmlinux.lds.S
index 051d1c5db589..e8a16fb53649 100644
--- a/arch/sh/vmlinux.lds.S
+++ b/arch/sh/vmlinux.lds.S
@@ -27,6 +27,7 @@ SECTIONS
} = 0x0009
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/sparc64/vmlinux.lds.S b/arch/sparc64/vmlinux.lds.S
index b20ac519366a..250c7f780a97 100644
--- a/arch/sparc64/vmlinux.lds.S
+++ b/arch/sparc64/vmlinux.lds.S
@@ -43,6 +43,7 @@ SECTIONS
__gpl_ksymtab : { *(__gpl_ksymtab) }
__stop___gpl_ksymtab = .;
__kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
__start___kallsyms = .; /* All kernel symbols */
__kallsyms : { *(__kallsyms) }
__stop___kallsyms = .;
diff --git a/arch/um/uml.lds.S b/arch/um/uml.lds.S
index 736df4695129..2b75faef3553 100644
--- a/arch/um/uml.lds.S
+++ b/arch/um/uml.lds.S
@@ -32,6 +32,7 @@ SECTIONS
*(.gnu.linkonce.t*)
}
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/arch/v850/vmlinux.lds.S b/arch/v850/vmlinux.lds.S
index d4819c1ef8eb..0e9c9eeaf7cf 100644
--- a/arch/v850/vmlinux.lds.S
+++ b/arch/v850/vmlinux.lds.S
@@ -41,6 +41,7 @@
*(.rodata) \
. = ALIGN (0x4) ; \
*(.kstrtab) \
+ *(__vermagic) \
. = ALIGN (4) ; \
*(.call_table_data) \
*(.call_table_text) \
diff --git a/arch/x86_64/vmlinux.lds.S b/arch/x86_64/vmlinux.lds.S
index a767b86aba8f..4d490c0f1ab7 100644
--- a/arch/x86_64/vmlinux.lds.S
+++ b/arch/x86_64/vmlinux.lds.S
@@ -20,6 +20,7 @@ SECTIONS
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }
+ __vermagic : { *(__vermagic) }
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
diff --git a/include/asm-i386/module.h b/include/asm-i386/module.h
index 1a480b64d876..0accded7894d 100644
--- a/include/asm-i386/module.h
+++ b/include/asm-i386/module.h
@@ -1,5 +1,6 @@
#ifndef _ASM_I386_MODULE_H
#define _ASM_I386_MODULE_H
+
/* x86 is simple */
struct mod_arch_specific
{
@@ -8,4 +9,47 @@ struct mod_arch_specific
#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Ehdr Elf32_Ehdr
+
+#ifdef CONFIG_M386
+#define MODULE_PROC_FAMILY "386 "
+#elif CONFIG_M486
+#define MODULE_PROC_FAMILY "486 "
+#elif CONFIG_M586
+#define MODULE_PROC_FAMILY "586 "
+#elif CONFIG_M586TSC
+#define MODULE_PROC_FAMILY "586TSC "
+#elif CONFIG_M586MMX
+#define MODULE_PROC_FAMILY "586MMX "
+#elif CONFIG_M686
+#define MODULE_PROC_FAMILY "686 "
+#elif CONFIG_MPENTIUMII
+#define MODULE_PROC_FAMILY "PENTIUMII "
+#elif CONFIG_MPENTIUMIII
+#define MODULE_PROC_FAMILY "PENTIUMIII "
+#elif CONFIG_MPENTIUM4
+#define MODULE_PROC_FAMILY "PENTIUM4 "
+#elif CONFIG_MK6
+#define MODULE_PROC_FAMILY "K6 "
+#elif CONFIG_MK7
+#define MODULE_PROC_FAMILY "K7 "
+#elif CONFIG_MK8
+#define MODULE_PROC_FAMILY "K8 "
+#elif CONFIG_MELAN
+#define MODULE_PROC_FAMILY "ELAN "
+#elif CONFIG_MCRUSOE
+#define MODULE_PROC_FAMILY "CRUSOE "
+#elif CONFIG_MWINCHIPC6
+#define MODULE_PROC_FAMILY "WINCHIPC6 "
+#elif CONFIG_MWINCHIP2
+#define MODULE_PROC_FAMILY "WINCHIP2 "
+#elif CONFIG_MWINCHIP3D
+#define MODULE_PROC_FAMILY "WINCHIP3D "
+#elif CONFIG_MCYRIXIII
+#define MODULE_PROC_FAMILY "CYRIXIII "
+#else
+#error unknown processor family
+#endif
+
+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
+
#endif /* _ASM_I386_MODULE_H */
diff --git a/init/Makefile b/init/Makefile
index e8691890702e..f611577436c9 100644
--- a/init/Makefile
+++ b/init/Makefile
@@ -2,7 +2,8 @@
# Makefile for the linux kernel.
#
-obj-y := main.o version.o do_mounts.o initramfs.o
+obj-y := main.o version.o do_mounts.o initramfs.o
+obj-$(CONFIG_MODULES) += vermagic.o
# files to be removed upon make clean
clean-files := ../include/linux/compile.h
diff --git a/init/vermagic.c b/init/vermagic.c
new file mode 100644
index 000000000000..0b4a58b70d07
--- /dev/null
+++ b/init/vermagic.c
@@ -0,0 +1,22 @@
+#include <linux/version.h>
+#include <linux/module.h>
+
+/* Simply sanity version stamp for modules. */
+#ifdef CONFIG_SMP
+#define MODULE_VERMAGIC_SMP "SMP "
+#else
+#define MODULE_VERMAGIC_SMP ""
+#endif
+#ifdef CONFIG_PREEMPT
+#define MODULE_VERMAGIC_PREEMPT "preempt "
+#else
+#define MODULE_VERMAGIC_PREEMPT ""
+#endif
+#ifndef MODULE_ARCH_VERMAGIC
+#define MODULE_ARCH_VERMAGIC ""
+#endif
+
+const char vermagic[] __attribute__((section("__vermagic"))) =
+ UTS_RELEASE " "
+ MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT MODULE_ARCH_VERMAGIC
+ "gcc-" __stringify(__GNUC__) "." __stringify(__GNUC_MINOR__);
diff --git a/kernel/module.c b/kernel/module.c
index 4a31ffeb323d..acae11eea73f 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -963,6 +963,9 @@ static void set_license(struct module *mod, Elf_Shdr *sechdrs, int licenseidx)
}
}
+/* From init/vermagic.o */
+extern char vermagic[];
+
/* 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 *umod,
@@ -973,7 +976,7 @@ static struct module *load_module(void *umod,
Elf_Shdr *sechdrs;
char *secstrings, *args;
unsigned int i, symindex, exportindex, strindex, setupindex, exindex,
- modindex, obsparmindex, licenseindex, gplindex;
+ modindex, obsparmindex, licenseindex, gplindex, vmagindex;
long arglen;
struct module *mod;
long err = 0;
@@ -1012,7 +1015,7 @@ static struct module *load_module(void *umod,
exportindex = setupindex = obsparmindex = gplindex = licenseindex = 0;
/* And these should exist, but gcc whinges if we don't init them */
- symindex = strindex = exindex = modindex = 0;
+ symindex = strindex = exindex = modindex = vmagindex = 0;
/* Find where important sections are */
for (i = 1; i < hdr->e_shnum; i++) {
@@ -1062,6 +1065,11 @@ static struct module *load_module(void *umod,
/* EXPORT_SYMBOL_GPL() */
DEBUGP("GPL symbols found in section %u\n", i);
gplindex = i;
+ } else if (strcmp(secstrings+sechdrs[i].sh_name,
+ "__vermagic") == 0) {
+ /* Version magic. */
+ DEBUGP("Version magic found in section %u\n", i);
+ vmagindex = i;
}
#ifdef CONFIG_KALLSYMS
/* symbol and string tables for decoding later. */
@@ -1082,6 +1090,18 @@ static struct module *load_module(void *umod,
}
mod = (void *)sechdrs[modindex].sh_addr;
+ /* This is allowed: modprobe --force will strip it. */
+ if (!vmagindex) {
+ tainted |= TAINT_FORCED_MODULE;
+ printk(KERN_WARNING "%s: no version magic, tainting kernel.\n",
+ mod->name);
+ } else if (strcmp((char *)sechdrs[vmagindex].sh_addr, vermagic) != 0) {
+ printk(KERN_ERR "%s: version magic '%s' should be '%s'\n",
+ mod->name, (char*)sechdrs[vmagindex].sh_addr, vermagic);
+ err = -ENOEXEC;
+ goto free_hdr;
+ }
+
/* Now copy in args */
arglen = strlen_user(uargs);
if (!arglen) {
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 2db7cc59c2bd..f5886c69a196 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -176,10 +176,15 @@ quiet_cmd_link_multi-y = LD $@
cmd_link_multi-y = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(addprefix $(obj)/,$($(subst $(obj)/,,$(@:.o=-objs))) $($(subst $(obj)/,,$(@:.o=-y)))),$^)
quiet_cmd_link_multi-m = LD [M] $@
-cmd_link_multi-m = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_MODULE) -o $@ $(filter $(addprefix $(obj)/,$($(subst $(obj)/,,$(@:.ko=-objs))) $($(subst $(obj)/,,$(@:.ko=-y)))),$^)
+cmd_link_multi-m = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_MODULE) -o $@ $(filter $(addprefix $(obj)/,$($(subst $(obj)/,,$(@:.ko=-objs))) $($(subst $(obj)/,,$(@:.ko=-y)))),$^) init/vermagic.o
quiet_cmd_link_single-m = LD [M] $@
-cmd_link_single-m = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_MODULE) -o $@ $<
+cmd_link_single-m = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_MODULE) -o $@ $< init/vermagic.o
+
+# Don't rebuilt vermagic.o unless we actually are in the init/ dir
+ifneq ($(obj),init)
+init/vermagic.o: ;
+endif
# We would rather have a list of rules like
# foo.o: $(foo-objs)
@@ -188,10 +193,10 @@ cmd_link_single-m = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_MODULE) -o $@ $<
$(multi-used-y) : %.o: $(multi-objs-y) FORCE
$(call if_changed,link_multi-y)
-$(multi-used-m:.o=.ko) : %.ko: $(multi-objs-m) FORCE
+$(multi-used-m:.o=.ko) : %.ko: $(multi-objs-m) init/vermagic.o FORCE
$(call if_changed,link_multi-m)
-$(single-used-m:.o=.ko) : %.ko: %.o FORCE
+$(single-used-m:.o=.ko) : %.ko: %.o init/vermagic.o FORCE
$(call if_changed,link_single-m)
targets += $(multi-used-y) $(multi-used-m:.o=.ko) $(single-used-m:.o=.ko)