* [PATCH v2] Return proper error code from register_kprobe()
@ 2012-02-15 7:16 Prashanth Nageshappa
2012-02-15 21:23 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Prashanth Nageshappa @ 2012-02-15 7:16 UTC (permalink / raw)
To: masami.hiramatsu.pt, ananth, akpm, linux-kernel
Cc: jbaron, rostedt, srikar, stable
Missed lkml in my previous posting, hence resending....
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>
Cc: stable@vger.kernel.org
---
kernel/kprobes.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
Index: linux-14feb/kernel/kprobes.c
===================================================================
--- linux-14feb.orig/kernel/kprobes.c
+++ linux-14feb/kernel/kprobes.c
@@ -1334,8 +1334,10 @@ int __kprobes register_kprobe(struct kpr
if (!kernel_text_address((unsigned long) p->addr) ||
in_kprobes_functions((unsigned long) p->addr) ||
ftrace_text_reserved(p->addr, p->addr) ||
- jump_label_text_reserved(p->addr, p->addr))
- goto fail_with_jump_label;
+ jump_label_text_reserved(p->addr, p->addr)) {
+ ret = -EINVAL;
+ goto cannot_probe;
+ }
/* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */
p->flags &= KPROBE_FLAG_DISABLED;
@@ -1352,7 +1354,7 @@ int __kprobes register_kprobe(struct kpr
* its code to prohibit unexpected unloading.
*/
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
@@ -1361,7 +1363,7 @@ int __kprobes register_kprobe(struct kpr
if (within_module_init((unsigned long)p->addr, probed_mod) &&
probed_mod->state != MODULE_STATE_COMING) {
module_put(probed_mod);
- goto fail_with_jump_label;
+ goto cannot_probe;
}
/* ret will be updated by following code */
}
@@ -1409,7 +1411,7 @@ int __kprobes register_kprobe(struct kpr
return ret;
-fail_with_jump_label:
+cannot_probe:
preempt_enable();
jump_label_unlock();
return ret;
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] Return proper error code from register_kprobe()
2012-02-15 7:16 [PATCH v2] Return proper error code from register_kprobe() Prashanth Nageshappa
@ 2012-02-15 21:23 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2012-02-15 21:23 UTC (permalink / raw)
To: Prashanth Nageshappa
Cc: masami.hiramatsu.pt, ananth, linux-kernel, jbaron, rostedt,
srikar, stable
On Wed, 15 Feb 2012 12:46:03 +0530
Prashanth Nageshappa <prashanth@linux.vnet.ibm.com> wrote:
> register_kprobe() aborts if the address of the new request falls in a
> prohibited area (such as ftrace pouch, __kprobes annotated functions,
I'm sitting here wondering what you meant to type when you typed
"ftrace pouch". I'm stumped! But you're not allowed to tell us - that
would take all the fun out of it.
> 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>
> Cc: stable@vger.kernel.org
So we want this for 3.3 with a -stable backport.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-02-15 21:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-15 7:16 [PATCH v2] Return proper error code from register_kprobe() Prashanth Nageshappa
2012-02-15 21:23 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox