public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: linux-kernel@vger.kernel.org
Cc: Jon Masters <jonathan@jonmasters.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 3/3] module: don't ignore vermagic string if module doesn't have modversions
Date: Fri, 9 May 2008 16:25:28 +1000	[thread overview]
Message-ID: <200805091625.28705.rusty@rustcorp.com.au> (raw)
In-Reply-To: <200805091624.21659.rusty@rustcorp.com.au>

Linus found a logic bug: we ignore the version number in a module's
vermagic string if we have CONFIG_MODVERSIONS set, but modversions
also lets through a module with no __versions section for modprobe
--force (with tainting, but still).

We should only ignore the start of the vermagic string if the module
actually *has* crcs to check.  Rather than (say) having an
entertaining hissy fit and creating a config option to work around the
buggy code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 init/Kconfig    |    6 +++---
 kernel/module.c |   16 ++++++++++------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff -r 8805b380fdff init/Kconfig
--- a/init/Kconfig	Thu May 08 21:14:37 2008 +1000
+++ b/init/Kconfig	Thu May 08 21:16:20 2008 +1000
@@ -837,9 +837,9 @@ config MODULE_FORCE_LOAD
 	depends on MODULES
 	default n
 	help
-	  This option allows loading of modules even if that would set the
-          'F' (forced) taint, due to lack of version info.  Which is
-	  usually a really bad idea.
+	  Allow loading of modules without version information (ie. modprobe
+	  --force).  Forced module loading sets the 'F' (forced) taint flag and
+	  is usually a really bad idea.
 
 config MODULE_UNLOAD
 	bool "Module unloading"
diff -r 8805b380fdff kernel/module.c
--- a/kernel/module.c	Thu May 08 21:14:37 2008 +1000
+++ b/kernel/module.c	Thu May 08 21:16:20 2008 +1000
@@ -956,11 +956,14 @@ static inline int check_modstruct_versio
 	return check_version(sechdrs, versindex, "struct_module", mod, crc);
 }
 
-/* First part is kernel version, which we ignore. */
-static inline int same_magic(const char *amagic, const char *bmagic)
+/* First part is kernel version, which we ignore if module has crcs. */
+static inline int same_magic(const char *amagic, const char *bmagic,
+			     bool has_crcs)
 {
-	amagic += strcspn(amagic, " ");
-	bmagic += strcspn(bmagic, " ");
+	if (has_crcs) {
+		amagic += strcspn(amagic, " ");
+		bmagic += strcspn(bmagic, " ");
+	}
 	return strcmp(amagic, bmagic) == 0;
 }
 #else
@@ -980,7 +983,8 @@ static inline int check_modstruct_versio
 	return 1;
 }
 
-static inline int same_magic(const char *amagic, const char *bmagic)
+static inline int same_magic(const char *amagic, const char *bmagic,
+			     bool has_crcs)
 {
 	return strcmp(amagic, bmagic) == 0;
 }
@@ -1873,7 +1877,7 @@ static struct module *load_module(void _
 		err = try_to_force_load(mod, "magic");
 		if (err)
 			goto free_hdr;
-	} else if (!same_magic(modmagic, vermagic)) {
+	} else if (!same_magic(modmagic, vermagic, versindex)) {
 		printk(KERN_ERR "%s: version magic '%s' should be '%s'\n",
 		       mod->name, modmagic, vermagic);
 		err = -ENOEXEC;

  reply	other threads:[~2008-05-09  6:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-09  6:23 [PATCH 1/3] module: put modversions in vermagic Rusty Russell
2008-05-09  6:24 ` [PATCH 2/3] module: be more picky about allowing missing module versions Rusty Russell
2008-05-09  6:25   ` Rusty Russell [this message]
2008-05-09 14:44     ` [PATCH 3/3] module: don't ignore vermagic string if module doesn't have modversions Linus Torvalds
2008-05-11  0:57       ` Rusty Russell

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=200805091625.28705.rusty@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=jonathan@jonmasters.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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