public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kprobes: disable preempt for module_text_address()
@ 2008-11-04  5:56 Lai Jiangshan
  2008-11-04 14:28 ` Ananth N Mavinakayanahalli
  2008-11-05  1:27 ` Masami Hiramatsu
  0 siblings, 2 replies; 17+ messages in thread
From: Lai Jiangshan @ 2008-11-04  5:56 UTC (permalink / raw)
  To: Andrew Morton; +Cc: ananth, David Miller, mhiramat, Linux Kernel Mailing List


__register_kprobe() may be preempted after module_text_address()
but before try_module_get(), and in this interval the module may be
unloaded and try_module_get(probed_mod) will access to invalid address.
this patch uses preempt_disable() to protect it.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 8b57a25..8238ec5 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -622,6 +622,7 @@ static int __kprobes __register_kprobe(struct kprobe *p,
 	/*
 	 * Check if are we probing a module.
 	 */
+	preempt_disable();
 	probed_mod = module_text_address((unsigned long) p->addr);
 	if (probed_mod) {
 		struct module *calling_mod = module_text_address(called_from);
@@ -631,12 +632,15 @@ static int __kprobes __register_kprobe(struct kprobe *p,
 		 * unloading of self probing modules.
 		 */
 		if (calling_mod && calling_mod != probed_mod) {
-			if (unlikely(!try_module_get(probed_mod)))
+			if (unlikely(!try_module_get(probed_mod))) {
+				preempt_enable();
 				return -EINVAL;
+			}
 			p->mod_refcounted = 1;
 		} else
 			probed_mod = NULL;
 	}
+	preempt_enable();
 
 	p->nmissed = 0;
 	INIT_LIST_HEAD(&p->list);




^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2008-11-07  4:47 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-04  5:56 [PATCH] kprobes: disable preempt for module_text_address() Lai Jiangshan
2008-11-04 14:28 ` Ananth N Mavinakayanahalli
2008-11-05  0:53   ` Lai Jiangshan
2008-11-05  1:27 ` Masami Hiramatsu
2008-11-05  1:47   ` Lai Jiangshan
2008-11-05 19:30     ` Hiroshi Shimamoto
2008-11-05 21:40     ` Masami Hiramatsu
2008-11-05 22:46       ` Hiroshi Shimamoto
2008-11-05 23:07         ` Masami Hiramatsu
2008-11-06  0:06           ` [PATCH] kprobes: bugfix: try_module_get even if calling_mod is NULL Masami Hiramatsu
2008-11-07  1:00             ` Andrew Morton
2008-11-07  2:28               ` Masami Hiramatsu
2008-11-07  2:54                 ` Andrew Morton
2008-11-07  4:46                   ` Ananth N Mavinakayanahalli
2008-11-06  1:06       ` [PATCH] kprobes: disable preempt for module_text_address() Lai Jiangshan
2008-11-06 15:37         ` [PATCH] kprobes: disable preempt for module_text_address() and kernel_text_address() Masami Hiramatsu
2008-11-07  0:32           ` Lai Jiangshan

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