public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <dada1@cosmosbay.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	systemtap-ml <systemtap@sources.redhat.com>
Subject: Re: [PATCH] module: fix refptr allocation and release order
Date: Tue, 17 Mar 2009 04:24:36 +0100	[thread overview]
Message-ID: <49BF17F4.7040908@cosmosbay.com> (raw)
In-Reply-To: <200903171250.16585.rusty@rustcorp.com.au>

Rusty Russell a écrit :
> From: Masami Hiramatsu <mhiramat@redhat.com>
> 
> Impact: fix ref-after-free crash on failed module load
> 
> Fix refptr bug: Change refptr allocation and release order not to access a module
> data structure pointed by 'mod' after freeing mod->module_core.
> This bug will cause kernel panic(e.g. failed to find undefined symbols).
> 
> This bug was reported on systemtap bugzilla.
> http://sources.redhat.com/bugzilla/show_bug.cgi?id=9927
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
> Cc: Eric Dumazet <dada1@cosmosbay.com>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


My original patch did not have this problem, because I used a local variable
to hold refptr.

http://www.archivum.info/linux-kernel@vger.kernel.org/2008-05/msg07400.html

A simpler patch could just use a local variable again, since we are very
late in rc phase ?


From: Masami Hiramatsu <mhiramat@redhat.com>

Impact: fix ref-after-free crash on failed module load

Fix refptr bug: Change refptr release not to access a module
data structure pointed by 'mod' after freeing mod->module_core.
This bug will cause kernel panic(e.g. failed to find undefined symbols).

This bug was reported on systemtap bugzilla.
http://sources.redhat.com/bugzilla/show_bug.cgi?id=9927

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


diff --git a/kernel/module.c b/kernel/module.c
index ba22484..4dd1228 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1874,6 +1874,9 @@ static noinline struct module *load_module(void __user *umod,
 	struct kernel_param *kp;
 	struct module *mod;
 	long err = 0;
+#if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
+	void *refptr = NULL;
+#endif
 	void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
 	unsigned long *mseg;
 	mm_segment_t old_fs;
@@ -2018,6 +2021,7 @@ static noinline struct module *load_module(void __user *umod,
 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
 	mod->refptr = percpu_modalloc(sizeof(local_t), __alignof__(local_t),
 				      mod->name);
+	refptr = mod->refptr;
 	if (!mod->refptr) {
 		err = -ENOMEM;
 		goto free_mod;
@@ -2292,10 +2296,14 @@ static noinline struct module *load_module(void __user *umod,
  free_core:
 	module_free(mod, mod->module_core);
  free_percpu:
+	/*
+	 * Do not access to mod anymore, it's now freed
+	 */
 	if (percpu)
 		percpu_modfree(percpu);
 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
-	percpu_modfree(mod->refptr);
+	if (refptr)
+		percpu_modfree(refptr);
 #endif
  free_mod:
 	kfree(args);


  reply	other threads:[~2009-03-17  3:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-17  2:20 [PATCH] module: fix refptr allocation and release order Rusty Russell
2009-03-17  3:24 ` Eric Dumazet [this message]
2009-03-17 21:21   ` 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=49BF17F4.7040908@cosmosbay.com \
    --to=dada1@cosmosbay.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=systemtap@sources.redhat.com \
    --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