mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 19:56:18 +00:00
kprobes: support probing module __init function
Allow kprobes to probe module __init routines. When __init functions are freed, kprobes which probe those functions are set to "Gone" flag. These "Gone" probes are disarmed from the code and never be enabled. Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com> Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
0deddf436a
commit
f24659d96f
1 changed files with 19 additions and 4 deletions
|
@ -677,6 +677,16 @@ int __kprobes register_kprobe(struct kprobe *p)
|
||||||
preempt_enable();
|
preempt_enable();
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* If the module freed .init.text, we couldn't insert
|
||||||
|
* kprobes in there.
|
||||||
|
*/
|
||||||
|
if (within_module_init((unsigned long)p->addr, probed_mod) &&
|
||||||
|
probed_mod->state != MODULE_STATE_COMING) {
|
||||||
|
module_put(probed_mod);
|
||||||
|
preempt_enable();
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
preempt_enable();
|
preempt_enable();
|
||||||
|
|
||||||
|
@ -1073,19 +1083,24 @@ static int __kprobes kprobes_module_callback(struct notifier_block *nb,
|
||||||
struct hlist_node *node;
|
struct hlist_node *node;
|
||||||
struct kprobe *p;
|
struct kprobe *p;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
int checkcore = (val == MODULE_STATE_GOING);
|
||||||
|
|
||||||
if (val != MODULE_STATE_GOING)
|
if (val != MODULE_STATE_GOING && val != MODULE_STATE_LIVE)
|
||||||
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* module .text section will be freed. We need to
|
* When MODULE_STATE_GOING was notified, both of module .text and
|
||||||
* disable kprobes which have been inserted in the section.
|
* .init.text sections would be freed. When MODULE_STATE_LIVE was
|
||||||
|
* notified, only .init.text section would be freed. We need to
|
||||||
|
* disable kprobes which have been inserted in the sections.
|
||||||
*/
|
*/
|
||||||
mutex_lock(&kprobe_mutex);
|
mutex_lock(&kprobe_mutex);
|
||||||
for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
|
for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
|
||||||
head = &kprobe_table[i];
|
head = &kprobe_table[i];
|
||||||
hlist_for_each_entry_rcu(p, node, head, hlist)
|
hlist_for_each_entry_rcu(p, node, head, hlist)
|
||||||
if (within_module_core((unsigned long)p->addr, mod)) {
|
if (within_module_init((unsigned long)p->addr, mod) ||
|
||||||
|
(checkcore &&
|
||||||
|
within_module_core((unsigned long)p->addr, mod))) {
|
||||||
/*
|
/*
|
||||||
* The vaddr this probe is installed will soon
|
* The vaddr this probe is installed will soon
|
||||||
* be vfreed buy not synced to disk. Hence,
|
* be vfreed buy not synced to disk. Hence,
|
||||||
|
|
Loading…
Reference in a new issue