mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 3/6] module: assume first entry in __versions is the layout.
@ 2009-01-28 13:35 Rusty Russell
  0 siblings, 0 replies; only message in thread
From: Rusty Russell @ 2009-01-28 13:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: Shawn Bohrer, Shawn Bohrer


This has always been true, but by insisting on it we can avoid
examining the string associated with the symbol name.  This is
important once we change that string to be a pointer, which will need
relocation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 kernel/module.c       |   24 +++++++++++++++++++++++-
 scripts/mod/modpost.c |    6 +++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1022,10 +1022,32 @@ static inline int check_modstruct_versio
 					  struct module *mod)
 {
 	const unsigned long *crc;
+	unsigned int num_versions;
+	struct modversion_info *versions;
 
 	if (IS_ERR_VALUE(find_symbol("module_layout", NULL, &crc, true, false)))
 		BUG();
-	return check_version(sechdrs, versindex, "module_layout", mod, crc);
+
+	/* First symbol is the module_layout version.  This means we
+	 * can check it before relocations are performed (since we
+	 * don't need to look at the name field). */
+
+	/* No versions at all?  modprobe --force does this. */
+	if (versindex == 0)
+		return !try_to_force_load(mod, "no version for module_layout");
+
+	if (sechdrs[versindex].sh_size < sizeof(*versions)) {
+		printk(KERN_WARN "%s: bad __versions section size\n",
+		       mod->name);
+		return 0;
+	}
+
+	versions = (void *)sechdrs[versindex].sh_addr;
+	if (versions->crc == *crc)
+		return 1;
+	printk(KERN_WARNING "%s: disagrees about version of module_layout\n",
+	       mod->name);
+	return 0;
 }
 
 /* First part is kernel version, which we ignore if module has crcs. */
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -14,6 +14,7 @@
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <ctype.h>
+#include <assert.h>
 #include "modpost.h"
 #include "../../include/linux/license.h"
 
@@ -1607,7 +1608,7 @@ static void read_symbols(char *modname)
 	/* Our trick to get versioning for module struct etc. - it's
 	 * never passed as an argument to an exported function, so
 	 * the automatic versioning doesn't pick it up, but it's really
-	 * important anyhow */
+	 * important anyhow.  This has to be the first symbol (last added)! */
 	if (modversions)
 		mod->unres = alloc_symbol("module_layout", 0, mod->unres);
 }
@@ -1769,6 +1770,9 @@ static int add_versions(struct buffer *b
 	buf_printf(b, "static const struct modversion_info ____versions[]\n");
 	buf_printf(b, "__used\n");
 	buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n");
+
+	/* First symbol must be module layout: loader relies on it. */
+	assert(strcmp(mod->unres->name, "module_layout") == 0);
 
 	for (s = mod->unres; s; s = s->next) {
 		if (!s->module)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-01-28 13:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-28 13:35 [PATCH 3/6] module: assume first entry in __versions is the layout Rusty Russell

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

Powered by JetHome