From: peterz at infradead.org (Peter Zijlstra)
Subject: [PATCH 2/4] x86/kprobes: Fix frame pointer annotations
Date: Mon, 13 May 2019 10:15:03 +0200 [thread overview]
Message-ID: <20190513081503.GK2623@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190511095655.405147cde331cd1da539d0e8@kernel.org>
On Sat, May 11, 2019 at 09:56:55AM +0900, Masami Hiramatsu wrote:
> On Fri, 10 May 2019 14:40:54 +0200
> Peter Zijlstra <peterz at infradead.org> wrote:
>
> > On Fri, May 10, 2019 at 01:58:31PM +0900, Masami Hiramatsu wrote:
> > > On Thu, 9 May 2019 19:14:16 +0200
> > > Peter Zijlstra <peterz at infradead.org> wrote:
> > > > > > --- a/arch/x86/kernel/kprobes/core.c
> > > > > > +++ b/arch/x86/kernel/kprobes/core.c
> > > > > > @@ -731,29 +731,8 @@ asm(
> > > > > > ".global kretprobe_trampoline\n"
> > > > > > ".type kretprobe_trampoline, @function\n"
> > > > > > "kretprobe_trampoline:\n"
> >
> > > > > Here, we need a gap for storing ret-ip, because kretprobe_trampoline is
> > > > > the address which is returned from the target function. We have no
> > > > > "ret-ip" here at this point. So something like
> > > > >
> > > > > + "push $0\n" /* This is a gap, will be filled with real return address*/
> > > >
> > > > The trampoline already provides a gap, trampoline_handler() will need to
> > > > use int3_emulate_push() if it wants to inject something on the return
> > > > stack.
> > >
> > > I guess you mean the int3 case. This trampoline is used as a return destination.
> >
> > > When the target function is called, kretprobe interrupts the first instruction,
> > > and replace the return address with this trampoline. When a "ret" instruction
> > > is done, it returns to this trampoline. Thus the stack frame start with
> > > previous context here. As you described above,
> >
> > I would prefer to change that to inject an extra return address, instead
> > of replacing it. With the new exception stuff we can actually do that.
> >
> > So on entry we then go from:
> >
> > <previous context>
> > RET-IP
> >
> > to
> >
> > <previous context>
> > RET-IP
> > return-trampoline
> >
> > So when the function returns, it falls into the trampoline instead.
>
> Is that really possible? On x86-64, most parameters are passed by registers,
> but x86-32 (and x86-64 in rare case) some parameters can be passed by stack.
> If we change the stack layout in the function prologue, the code in
> function body can not access those parameters on stack.
Ooh, I see what you mean... yes that might be trouble indeed. Damn..
WARNING: multiple messages have this Message-ID (diff)
From: peterz@infradead.org (Peter Zijlstra)
Subject: [PATCH 2/4] x86/kprobes: Fix frame pointer annotations
Date: Mon, 13 May 2019 10:15:03 +0200 [thread overview]
Message-ID: <20190513081503.GK2623@hirez.programming.kicks-ass.net> (raw)
Message-ID: <20190513081503.NB7PJ7Inr2g7n_bMhQhWu9jaNWk3yU-JsytzC9XmXWU@z> (raw)
In-Reply-To: <20190511095655.405147cde331cd1da539d0e8@kernel.org>
On Sat, May 11, 2019@09:56:55AM +0900, Masami Hiramatsu wrote:
> On Fri, 10 May 2019 14:40:54 +0200
> Peter Zijlstra <peterz@infradead.org> wrote:
>
> > On Fri, May 10, 2019@01:58:31PM +0900, Masami Hiramatsu wrote:
> > > On Thu, 9 May 2019 19:14:16 +0200
> > > Peter Zijlstra <peterz@infradead.org> wrote:
> > > > > > --- a/arch/x86/kernel/kprobes/core.c
> > > > > > +++ b/arch/x86/kernel/kprobes/core.c
> > > > > > @@ -731,29 +731,8 @@ asm(
> > > > > > ".global kretprobe_trampoline\n"
> > > > > > ".type kretprobe_trampoline, @function\n"
> > > > > > "kretprobe_trampoline:\n"
> >
> > > > > Here, we need a gap for storing ret-ip, because kretprobe_trampoline is
> > > > > the address which is returned from the target function. We have no
> > > > > "ret-ip" here at this point. So something like
> > > > >
> > > > > + "push $0\n" /* This is a gap, will be filled with real return address*/
> > > >
> > > > The trampoline already provides a gap, trampoline_handler() will need to
> > > > use int3_emulate_push() if it wants to inject something on the return
> > > > stack.
> > >
> > > I guess you mean the int3 case. This trampoline is used as a return destination.
> >
> > > When the target function is called, kretprobe interrupts the first instruction,
> > > and replace the return address with this trampoline. When a "ret" instruction
> > > is done, it returns to this trampoline. Thus the stack frame start with
> > > previous context here. As you described above,
> >
> > I would prefer to change that to inject an extra return address, instead
> > of replacing it. With the new exception stuff we can actually do that.
> >
> > So on entry we then go from:
> >
> > <previous context>
> > RET-IP
> >
> > to
> >
> > <previous context>
> > RET-IP
> > return-trampoline
> >
> > So when the function returns, it falls into the trampoline instead.
>
> Is that really possible? On x86-64, most parameters are passed by registers,
> but x86-32 (and x86-64 in rare case) some parameters can be passed by stack.
> If we change the stack layout in the function prologue, the code in
> function body can not access those parameters on stack.
Ooh, I see what you mean... yes that might be trouble indeed. Damn..
next prev parent reply other threads:[~2019-05-13 8:15 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-08 7:49 [PATCH 0/4] x86: int3 fallout peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 7:49 ` [PATCH 1/4] x86/entry/32: Clean up return from interrupt preemption path peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 7:49 ` [PATCH 2/4] x86/kprobes: Fix frame pointer annotations peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 11:54 ` jpoimboe
2019-05-08 11:54 ` Josh Poimboeuf
2019-05-08 12:04 ` peterz
2019-05-08 12:04 ` Peter Zijlstra
[not found] ` <20190508124248.u5ukpbhnh4wpiccq@treble>
[not found] ` <20190508153907.GM2589@hirez.programming.kicks-ass.net>
2019-05-08 18:48 ` jpoimboe
2019-05-08 18:48 ` Josh Poimboeuf
2019-05-09 1:20 ` mhiramat
2019-05-09 1:20 ` Masami Hiramatsu
2019-05-09 8:14 ` peterz
2019-05-09 8:14 ` Peter Zijlstra
2019-05-09 9:27 ` peterz
2019-05-09 9:27 ` Peter Zijlstra
2019-05-09 14:00 ` jpoimboe
2019-05-09 14:00 ` Josh Poimboeuf
2019-05-09 14:01 ` mhiramat
2019-05-09 14:01 ` Masami Hiramatsu
2019-05-09 17:14 ` peterz
2019-05-09 17:14 ` Peter Zijlstra
2019-05-10 4:58 ` mhiramat
2019-05-10 4:58 ` Masami Hiramatsu
2019-05-10 12:31 ` peterz
2019-05-10 12:31 ` Peter Zijlstra
2019-05-11 0:52 ` mhiramat
2019-05-11 0:52 ` Masami Hiramatsu
2019-05-10 12:40 ` peterz
2019-05-10 12:40 ` Peter Zijlstra
2019-05-11 0:56 ` mhiramat
2019-05-11 0:56 ` Masami Hiramatsu
2019-05-13 8:15 ` peterz [this message]
2019-05-13 8:15 ` Peter Zijlstra
2019-05-09 16:20 ` luto
2019-05-09 16:20 ` Andy Lutomirski
2019-05-09 17:18 ` peterz
2019-05-09 17:18 ` Peter Zijlstra
2019-05-09 17:43 ` rostedt
2019-05-09 17:43 ` Steven Rostedt
2019-05-10 3:21 ` mhiramat
2019-05-10 3:21 ` Masami Hiramatsu
2019-05-10 12:14 ` peterz
2019-05-10 12:14 ` Peter Zijlstra
2019-05-10 12:17 ` peterz
2019-05-10 12:17 ` Peter Zijlstra
2019-05-10 14:54 ` rostedt
2019-05-10 14:54 ` Steven Rostedt
2019-05-09 17:37 ` rostedt
2019-05-09 17:37 ` Steven Rostedt
2019-05-09 18:26 ` peterz
2019-05-09 18:26 ` Peter Zijlstra
2019-05-09 18:36 ` rostedt
2019-05-09 18:36 ` Steven Rostedt
2019-05-08 7:49 ` [PATCH 3/4] x86/ftrace: Add pt_regs frame annotations peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 7:49 ` [RFC][PATCH 4/4] x86_32: Provide consistent pt_regs peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 11:57 ` jpoimboe
2019-05-08 11:57 ` Josh Poimboeuf
2019-05-08 20:58 ` torvalds
2019-05-08 20:58 ` Linus Torvalds
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=20190513081503.GK2623@hirez.programming.kicks-ass.net \
--to=linux-kselftest@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox