Skip to content

Commit

Permalink
kprobes: return proper error code from register_kprobe()
Browse files Browse the repository at this point in the history
register_kprobe() aborts if the address of the new request falls in a
prohibited area (such as ftrace pouch, __kprobes annotated functions,
non-kernel text addresses, jump label text).  We however don't return the
right error on this abort, resulting in a silent failure - incorrect
adding/reporting of kprobes ('perf probe do_fork+18' or 'perf probe
mcount' for instance).

In V2 we are incorporating Masami Hiramatsu's  feedback.

This patch fixes it by returning -EINVAL upon failure.

While we are here, rename the label used for exit to be more appropriate.

Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Signed-off-by: Prashanth K Nageshappa <prashanth@linux.vnet.ibm.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Prashanth Nageshappa authored and torvalds committed Mar 5, 2012
1 parent c22ab33 commit f986a49
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kernel/kprobes.c
Expand Up @@ -1334,8 +1334,10 @@ int __kprobes register_kprobe(struct kprobe *p)
if (!kernel_text_address((unsigned long) p->addr) || if (!kernel_text_address((unsigned long) p->addr) ||
in_kprobes_functions((unsigned long) p->addr) || in_kprobes_functions((unsigned long) p->addr) ||
ftrace_text_reserved(p->addr, p->addr) || ftrace_text_reserved(p->addr, p->addr) ||
jump_label_text_reserved(p->addr, p->addr)) jump_label_text_reserved(p->addr, p->addr)) {
goto fail_with_jump_label; ret = -EINVAL;
goto cannot_probe;
}


/* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */ /* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */
p->flags &= KPROBE_FLAG_DISABLED; p->flags &= KPROBE_FLAG_DISABLED;
Expand All @@ -1352,7 +1354,7 @@ int __kprobes register_kprobe(struct kprobe *p)
* its code to prohibit unexpected unloading. * its code to prohibit unexpected unloading.
*/ */
if (unlikely(!try_module_get(probed_mod))) if (unlikely(!try_module_get(probed_mod)))
goto fail_with_jump_label; goto cannot_probe;


/* /*
* If the module freed .init.text, we couldn't insert * If the module freed .init.text, we couldn't insert
Expand All @@ -1361,7 +1363,7 @@ int __kprobes register_kprobe(struct kprobe *p)
if (within_module_init((unsigned long)p->addr, probed_mod) && if (within_module_init((unsigned long)p->addr, probed_mod) &&
probed_mod->state != MODULE_STATE_COMING) { probed_mod->state != MODULE_STATE_COMING) {
module_put(probed_mod); module_put(probed_mod);
goto fail_with_jump_label; goto cannot_probe;
} }
/* ret will be updated by following code */ /* ret will be updated by following code */
} }
Expand Down Expand Up @@ -1409,7 +1411,7 @@ int __kprobes register_kprobe(struct kprobe *p)


return ret; return ret;


fail_with_jump_label: cannot_probe:
preempt_enable(); preempt_enable();
jump_label_unlock(); jump_label_unlock();
return ret; return ret;
Expand Down

0 comments on commit f986a49

Please sign in to comment.