From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
Ingo Molnar <mingo@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH ftrace/core v3 1/3] [BUGFIX]kprobes/ftrace: Recover original IP if pre_handler doesn't change it
Date: Fri, 18 Jul 2014 10:47:49 +0900 [thread overview]
Message-ID: <53C87CC5.80506@hitachi.com> (raw)
In-Reply-To: <20140717142151.51bde92c@gandalf.local.home>
(2014/07/18 3:21), Steven Rostedt wrote:
> This looks to require an acked-by from hpa.
Oh, I see.
>
> On Tue, 15 Jul 2014 06:00:21 +0000
> Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> wrote:
>
>> Recover original IP register if the pre_handler doesn't change it.
>> Since current kprobes doesn't expect that another ftrace handler
>> may change regs->ip, it sets kprobe.addr + MCOUNT_INSN_SIZE to
>> regs->ip and returns to ftrace.
>> This seems wrong behavior since kprobes can recover regs->ip
>> and safely pass it to other handler.
>
> s/other/another/
>
>>
>> This adds a code which recovers original regs->ip passed from
>
> "... adds code which recovers the original ..."
>
>> ftrace right before returning ftrace, so that another ftrace user
>
> "... returning to ftrace, ..."
Thanks, I'll update the description. :)
>
>> can change regs->ip.
>
> You say BUGFIX in the subject, but as nothing changes the regs->ip
> currently from ftrace, is this currently a real bug?
Hmm, indeed, in-tree ftrace handlers never change regs->ip except
kprobes, and for the out-of-tree modules, we need IPMODIFY flag to
avoid such conflict among them. Thus, we can not solve such problem
only by this patch. OK, I'll drop BUGFIX tag.
Thank you,
>
> -- Steve
>
>>
>> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>> ---
>> arch/x86/kernel/kprobes/ftrace.c | 9 ++++++---
>> 1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/x86/kernel/kprobes/ftrace.c b/arch/x86/kernel/kprobes/ftrace.c
>> index 717b02a..5f8f0b3 100644
>> --- a/arch/x86/kernel/kprobes/ftrace.c
>> +++ b/arch/x86/kernel/kprobes/ftrace.c
>> @@ -27,7 +27,7 @@
>>
>> static nokprobe_inline
>> int __skip_singlestep(struct kprobe *p, struct pt_regs *regs,
>> - struct kprobe_ctlblk *kcb)
>> + struct kprobe_ctlblk *kcb, unsigned long orig_ip)
>> {
>> /*
>> * Emulate singlestep (and also recover regs->ip)
>> @@ -39,6 +39,8 @@ int __skip_singlestep(struct kprobe *p, struct pt_regs *regs,
>> p->post_handler(p, regs, 0);
>> }
>> __this_cpu_write(current_kprobe, NULL);
>> + if (orig_ip)
>> + regs->ip = orig_ip;
>> return 1;
>> }
>>
>> @@ -46,7 +48,7 @@ int skip_singlestep(struct kprobe *p, struct pt_regs *regs,
>> struct kprobe_ctlblk *kcb)
>> {
>> if (kprobe_ftrace(p))
>> - return __skip_singlestep(p, regs, kcb);
>> + return __skip_singlestep(p, regs, kcb, 0);
>> else
>> return 0;
>> }
>> @@ -71,13 +73,14 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
>> if (kprobe_running()) {
>> kprobes_inc_nmissed_count(p);
>> } else {
>> + unsigned long orig_ip = regs->ip;
>> /* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */
>> regs->ip = ip + sizeof(kprobe_opcode_t);
>>
>> __this_cpu_write(current_kprobe, p);
>> kcb->kprobe_status = KPROBE_HIT_ACTIVE;
>> if (!p->pre_handler || !p->pre_handler(p, regs))
>> - __skip_singlestep(p, regs, kcb);
>> + __skip_singlestep(p, regs, kcb, orig_ip);
>> /*
>> * If pre_handler returns !0, it sets regs->ip and
>> * resets current kprobe.
>>
>
>
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
next prev parent reply other threads:[~2014-07-18 1:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-15 6:00 [PATCH ftrace/core v3 0/3] ftrace, kprobes: Introduce IPMODIFY flag for ftrace_ops to detect conflicts Masami Hiramatsu
2014-07-15 6:00 ` [PATCH ftrace/core v3 1/3] [BUGFIX]kprobes/ftrace: Recover original IP if pre_handler doesn't change it Masami Hiramatsu
2014-07-17 18:21 ` Steven Rostedt
2014-07-18 1:47 ` Masami Hiramatsu [this message]
2014-07-15 6:00 ` [PATCH ftrace/core v3 2/3] ftrace, kprobes: Support IPMODIFY flag to find IP modify conflict Masami Hiramatsu
2014-07-17 18:41 ` Steven Rostedt
2014-07-18 7:09 ` Masami Hiramatsu
2014-07-18 13:51 ` Steven Rostedt
2014-07-20 3:19 ` Masami Hiramatsu
2014-07-15 6:00 ` [PATCH ftrace/core v3 3/3] kprobes: Set IPMODIFY flag only if the probe can change regs->ip Masami Hiramatsu
2014-07-18 5:32 ` Namhyung Kim
2014-07-18 7:10 ` Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53C87CC5.80506@hitachi.com \
--to=masami.hiramatsu.pt@hitachi.com \
--cc=ananth@in.ibm.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.