diff options
author | Prashanth Nageshappa <prashanth@linux.vnet.ibm.com> | 2012-03-05 17:59:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-05 18:49:42 -0500 |
commit | f986a499ef6f317d906e6f6f281be966e1237a10 (patch) | |
tree | 88ceafe9a214907bd25e8a8ffd8990fd5bd2b40e /kernel/kprobes.c | |
parent | c22ab332902333f83766017478c1ef6607ace681 (diff) |
kprobes: return proper error code from register_kprobe()
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>
Diffstat (limited to 'kernel/kprobes.c')
-rw-r--r-- | kernel/kprobes.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 9788c0ec6f43..c62b8546cc90 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -1334,8 +1334,10 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
1334 | if (!kernel_text_address((unsigned long) p->addr) || | 1334 | if (!kernel_text_address((unsigned long) p->addr) || |
1335 | in_kprobes_functions((unsigned long) p->addr) || | 1335 | in_kprobes_functions((unsigned long) p->addr) || |
1336 | ftrace_text_reserved(p->addr, p->addr) || | 1336 | ftrace_text_reserved(p->addr, p->addr) || |
1337 | jump_label_text_reserved(p->addr, p->addr)) | 1337 | jump_label_text_reserved(p->addr, p->addr)) { |
1338 | goto fail_with_jump_label; | 1338 | ret = -EINVAL; |
1339 | goto cannot_probe; | ||
1340 | } | ||
1339 | 1341 | ||
1340 | /* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */ | 1342 | /* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */ |
1341 | p->flags &= KPROBE_FLAG_DISABLED; | 1343 | p->flags &= KPROBE_FLAG_DISABLED; |
@@ -1352,7 +1354,7 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
1352 | * its code to prohibit unexpected unloading. | 1354 | * its code to prohibit unexpected unloading. |
1353 | */ | 1355 | */ |
1354 | if (unlikely(!try_module_get(probed_mod))) | 1356 | if (unlikely(!try_module_get(probed_mod))) |
1355 | goto fail_with_jump_label; | 1357 | goto cannot_probe; |
1356 | 1358 | ||
1357 | /* | 1359 | /* |
1358 | * If the module freed .init.text, we couldn't insert | 1360 | * If the module freed .init.text, we couldn't insert |
@@ -1361,7 +1363,7 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
1361 | if (within_module_init((unsigned long)p->addr, probed_mod) && | 1363 | if (within_module_init((unsigned long)p->addr, probed_mod) && |
1362 | probed_mod->state != MODULE_STATE_COMING) { | 1364 | probed_mod->state != MODULE_STATE_COMING) { |
1363 | module_put(probed_mod); | 1365 | module_put(probed_mod); |
1364 | goto fail_with_jump_label; | 1366 | goto cannot_probe; |
1365 | } | 1367 | } |
1366 | /* ret will be updated by following code */ | 1368 | /* ret will be updated by following code */ |
1367 | } | 1369 | } |
@@ -1409,7 +1411,7 @@ out: | |||
1409 | 1411 | ||
1410 | return ret; | 1412 | return ret; |
1411 | 1413 | ||
1412 | fail_with_jump_label: | 1414 | cannot_probe: |
1413 | preempt_enable(); | 1415 | preempt_enable(); |
1414 | jump_label_unlock(); | 1416 | jump_label_unlock(); |
1415 | return ret; | 1417 | return ret; |