[PATCH] kprobes: disable preempt for module_text_address()
From: Lai Jiangshan
Date: Tue Nov 04 2008 - 01:01:59 EST
__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@xxxxxxxxxxxxxx>
---
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);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/