* [v2,3/7] x86: stop calling fixup_exception() from kprobe_fault_handler()
@ 2018-08-28 1:21 Masami Hiramatsu
0 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2018-08-28 1:21 UTC (permalink / raw)
To: Jann Horn
Cc: Andy Lutomirski, mhiramat, naveen.n.rao, anil.s.keshavamurthy,
David S. Miller, Kees Cook, Thomas Gleixner, Ingo Molnar,
the arch/x86 maintainers, Kernel Hardening, tony.luck,
Borislav Petkov, kernel list, Dmitry Vyukov, linux-edac
On Mon, 27 Aug 2018 21:22:19 +0200
Jann Horn <jannh@google.com> wrote:
> On Mon, Aug 27, 2018 at 9:02 PM Andy Lutomirski <luto@kernel.org> wrote:
> >
> > On Mon, Aug 27, 2018 at 11:56 AM, Jann Horn <jannh@google.com> wrote:
> > > This removes the call into exception fixup that was added in
> > > commit c28f896634f2 ("[PATCH] kprobes: fix broken fault handling for
> > > x86_64").
> > >
> > > On X86, kprobe_fault_handler() is called from two places:
> > > do_general_protection() (for #GP) and kprobes_fault() (for #PF).
> > > In both paths, the fixup_exception() call in the kprobe fault handler is
> > > redundant.
> > >
> > > For #GP, fixup_exception() is called immediately before
> > > kprobe_fault_handler() is invoked - if someone wanted to fix up our #GP,
> > > they've already done so, no need to try again. (This assumes that the
> > > kprobe's fault handler isn't going to do something crazy like changing RIP
> > > so that it suddenly points to an instruction that does userspace access.)
> >
> > This needs review by someone who understands kprobes better than I do.
> > What happens if someone puts a kprobe on a uaccess instruction and the
> > uaccess subsequently faults?
>
> Ugh, good point. I'll admit to not having thought about that properly.
>
> I think that's the "if (unlikely(regs->ip == (unsigned
> long)cur->ainsn.insn))" branch in kprobe_fault_handler(), which I'm
> not touching.
Correct, probing on uaccess is handled by that block.
So this fixup_exception() is just for safeness.
As Jann said, no_context() handles it correctly, we don't need it.
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Thank you!
>
> For #PF, both without and with my patch, stuff should get fixed up by
> the normal pagefault handler, since the fixup happens after the kprobe
> handler has fiddled with the exception state.
>
> For #GP, we're already past the fixup call, and I think both without
> and with my patch, nothing will catch it - so I think that's a bug,
> but I don't think it's one I'm introducing.
>
> > > For #PF on a kernel address from kernel space, after the kprobe fault
> > > handler has run, we'll go into no_context(), which calls fixup_exception().
> > >
> > > Signed-off-by: Jann Horn <jannh@google.com>
> > > ---
> > > arch/x86/kernel/kprobes/core.c | 7 -------
> > > 1 file changed, 7 deletions(-)
> > >
> > > diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> > > index 467ac22691b0..7315ac202aad 100644
> > > --- a/arch/x86/kernel/kprobes/core.c
> > > +++ b/arch/x86/kernel/kprobes/core.c
> > > @@ -1021,13 +1021,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
> > > if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
> > > return 1;
> > >
> > > - /*
> > > - * In case the user-specified fault handler returned
> > > - * zero, try to fix up.
> > > - */
> > > - if (fixup_exception(regs, trapnr))
> > > - return 1;
> > > -
> > > /* fixup routine could not handle it. */
> > > }
> > >
> > > --
> > > 2.19.0.rc0.228.g281dcd1b4d0-goog
> > >
^ permalink raw reply [flat|nested] 5+ messages in thread* [v2,3/7] x86: stop calling fixup_exception() from kprobe_fault_handler()
@ 2018-08-27 19:25 Andy Lutomirski
0 siblings, 0 replies; 5+ messages in thread
From: Andy Lutomirski @ 2018-08-27 19:25 UTC (permalink / raw)
To: Jann Horn
Cc: Andy Lutomirski, Masami Hiramatsu, Naveen N . Rao,
Anil S Keshavamurthy, David S. Miller, Kees Cook, Thomas Gleixner,
Ingo Molnar, the arch/x86 maintainers, Kernel Hardening,
Tony Luck, Borislav Petkov, kernel list, Dmitry Vyukov,
linux-edac
On Mon, Aug 27, 2018 at 12:22 PM, Jann Horn <jannh@google.com> wrote:
> On Mon, Aug 27, 2018 at 9:02 PM Andy Lutomirski <luto@kernel.org> wrote:
>>
>> On Mon, Aug 27, 2018 at 11:56 AM, Jann Horn <jannh@google.com> wrote:
>> > This removes the call into exception fixup that was added in
>> > commit c28f896634f2 ("[PATCH] kprobes: fix broken fault handling for
>> > x86_64").
>> >
>> > On X86, kprobe_fault_handler() is called from two places:
>> > do_general_protection() (for #GP) and kprobes_fault() (for #PF).
>> > In both paths, the fixup_exception() call in the kprobe fault handler is
>> > redundant.
>> >
>> > For #GP, fixup_exception() is called immediately before
>> > kprobe_fault_handler() is invoked - if someone wanted to fix up our #GP,
>> > they've already done so, no need to try again. (This assumes that the
>> > kprobe's fault handler isn't going to do something crazy like changing RIP
>> > so that it suddenly points to an instruction that does userspace access.)
>>
>> This needs review by someone who understands kprobes better than I do.
>> What happens if someone puts a kprobe on a uaccess instruction and the
>> uaccess subsequently faults?
>
> Ugh, good point. I'll admit to not having thought about that properly.
>
> I think that's the "if (unlikely(regs->ip == (unsigned
> long)cur->ainsn.insn))" branch in kprobe_fault_handler(), which I'm
> not touching.
>
> For #PF, both without and with my patch, stuff should get fixed up by
> the normal pagefault handler, since the fixup happens after the kprobe
> handler has fiddled with the exception state.
>
> For #GP, we're already past the fixup call, and I think both without
> and with my patch, nothing will catch it - so I think that's a bug,
> but I don't think it's one I'm introducing.
Fair enough. If there is indeed a problem, it'll be easier to fix
sanely with your patch applied :)
^ permalink raw reply [flat|nested] 5+ messages in thread* [v2,3/7] x86: stop calling fixup_exception() from kprobe_fault_handler()
@ 2018-08-27 19:22 Jann Horn
0 siblings, 0 replies; 5+ messages in thread
From: Jann Horn @ 2018-08-27 19:22 UTC (permalink / raw)
To: Andy Lutomirski
Cc: mhiramat, naveen.n.rao, anil.s.keshavamurthy, David S. Miller,
Kees Cook, Thomas Gleixner, Ingo Molnar, the arch/x86 maintainers,
Kernel Hardening, tony.luck, Borislav Petkov, kernel list,
Dmitry Vyukov, linux-edac
On Mon, Aug 27, 2018 at 9:02 PM Andy Lutomirski <luto@kernel.org> wrote:
>
> On Mon, Aug 27, 2018 at 11:56 AM, Jann Horn <jannh@google.com> wrote:
> > This removes the call into exception fixup that was added in
> > commit c28f896634f2 ("[PATCH] kprobes: fix broken fault handling for
> > x86_64").
> >
> > On X86, kprobe_fault_handler() is called from two places:
> > do_general_protection() (for #GP) and kprobes_fault() (for #PF).
> > In both paths, the fixup_exception() call in the kprobe fault handler is
> > redundant.
> >
> > For #GP, fixup_exception() is called immediately before
> > kprobe_fault_handler() is invoked - if someone wanted to fix up our #GP,
> > they've already done so, no need to try again. (This assumes that the
> > kprobe's fault handler isn't going to do something crazy like changing RIP
> > so that it suddenly points to an instruction that does userspace access.)
>
> This needs review by someone who understands kprobes better than I do.
> What happens if someone puts a kprobe on a uaccess instruction and the
> uaccess subsequently faults?
Ugh, good point. I'll admit to not having thought about that properly.
I think that's the "if (unlikely(regs->ip == (unsigned
long)cur->ainsn.insn))" branch in kprobe_fault_handler(), which I'm
not touching.
For #PF, both without and with my patch, stuff should get fixed up by
the normal pagefault handler, since the fixup happens after the kprobe
handler has fiddled with the exception state.
For #GP, we're already past the fixup call, and I think both without
and with my patch, nothing will catch it - so I think that's a bug,
but I don't think it's one I'm introducing.
> > For #PF on a kernel address from kernel space, after the kprobe fault
> > handler has run, we'll go into no_context(), which calls fixup_exception().
> >
> > Signed-off-by: Jann Horn <jannh@google.com>
> > ---
> > arch/x86/kernel/kprobes/core.c | 7 -------
> > 1 file changed, 7 deletions(-)
> >
> > diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> > index 467ac22691b0..7315ac202aad 100644
> > --- a/arch/x86/kernel/kprobes/core.c
> > +++ b/arch/x86/kernel/kprobes/core.c
> > @@ -1021,13 +1021,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
> > if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
> > return 1;
> >
> > - /*
> > - * In case the user-specified fault handler returned
> > - * zero, try to fix up.
> > - */
> > - if (fixup_exception(regs, trapnr))
> > - return 1;
> > -
> > /* fixup routine could not handle it. */
> > }
> >
> > --
> > 2.19.0.rc0.228.g281dcd1b4d0-goog
> >
^ permalink raw reply [flat|nested] 5+ messages in thread* [v2,3/7] x86: stop calling fixup_exception() from kprobe_fault_handler()
@ 2018-08-27 19:02 Andy Lutomirski
0 siblings, 0 replies; 5+ messages in thread
From: Andy Lutomirski @ 2018-08-27 19:02 UTC (permalink / raw)
To: Jann Horn, Masami Hiramatsu, Naveen N. Rao, Anil S Keshavamurthy,
David S. Miller
Cc: Kees Cook, Thomas Gleixner, Ingo Molnar, X86 ML, Andy Lutomirski,
Kernel Hardening, Tony Luck, Borislav Petkov, LKML, Dmitry Vyukov,
linux-edac
On Mon, Aug 27, 2018 at 11:56 AM, Jann Horn <jannh@google.com> wrote:
> This removes the call into exception fixup that was added in
> commit c28f896634f2 ("[PATCH] kprobes: fix broken fault handling for
> x86_64").
>
> On X86, kprobe_fault_handler() is called from two places:
> do_general_protection() (for #GP) and kprobes_fault() (for #PF).
> In both paths, the fixup_exception() call in the kprobe fault handler is
> redundant.
>
> For #GP, fixup_exception() is called immediately before
> kprobe_fault_handler() is invoked - if someone wanted to fix up our #GP,
> they've already done so, no need to try again. (This assumes that the
> kprobe's fault handler isn't going to do something crazy like changing RIP
> so that it suddenly points to an instruction that does userspace access.)
This needs review by someone who understands kprobes better than I do.
What happens if someone puts a kprobe on a uaccess instruction and the
uaccess subsequently faults?
>
> For #PF on a kernel address from kernel space, after the kprobe fault
> handler has run, we'll go into no_context(), which calls fixup_exception().
>
> Signed-off-by: Jann Horn <jannh@google.com>
> ---
> arch/x86/kernel/kprobes/core.c | 7 -------
> 1 file changed, 7 deletions(-)
>
> diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> index 467ac22691b0..7315ac202aad 100644
> --- a/arch/x86/kernel/kprobes/core.c
> +++ b/arch/x86/kernel/kprobes/core.c
> @@ -1021,13 +1021,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
> if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
> return 1;
>
> - /*
> - * In case the user-specified fault handler returned
> - * zero, try to fix up.
> - */
> - if (fixup_exception(regs, trapnr))
> - return 1;
> -
> /* fixup routine could not handle it. */
> }
>
> --
> 2.19.0.rc0.228.g281dcd1b4d0-goog
>
^ permalink raw reply [flat|nested] 5+ messages in thread* [v2,3/7] x86: stop calling fixup_exception() from kprobe_fault_handler()
@ 2018-08-27 18:56 Jann Horn
0 siblings, 0 replies; 5+ messages in thread
From: Jann Horn @ 2018-08-27 18:56 UTC (permalink / raw)
To: Kees Cook, Thomas Gleixner, Ingo Molnar, x86, Andy Lutomirski,
kernel-hardening, Tony Luck, Borislav Petkov, jannh
Cc: linux-kernel, dvyukov, linux-edac
This removes the call into exception fixup that was added in
commit c28f896634f2 ("[PATCH] kprobes: fix broken fault handling for
x86_64").
On X86, kprobe_fault_handler() is called from two places:
do_general_protection() (for #GP) and kprobes_fault() (for #PF).
In both paths, the fixup_exception() call in the kprobe fault handler is
redundant.
For #GP, fixup_exception() is called immediately before
kprobe_fault_handler() is invoked - if someone wanted to fix up our #GP,
they've already done so, no need to try again. (This assumes that the
kprobe's fault handler isn't going to do something crazy like changing RIP
so that it suddenly points to an instruction that does userspace access.)
For #PF on a kernel address from kernel space, after the kprobe fault
handler has run, we'll go into no_context(), which calls fixup_exception().
Signed-off-by: Jann Horn <jannh@google.com>
---
arch/x86/kernel/kprobes/core.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 467ac22691b0..7315ac202aad 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -1021,13 +1021,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
return 1;
- /*
- * In case the user-specified fault handler returned
- * zero, try to fix up.
- */
- if (fixup_exception(regs, trapnr))
- return 1;
-
/* fixup routine could not handle it. */
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-08-28 1:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-28 1:21 [v2,3/7] x86: stop calling fixup_exception() from kprobe_fault_handler() Masami Hiramatsu
-- strict thread matches above, loose matches on Subject: below --
2018-08-27 19:25 Andy Lutomirski
2018-08-27 19:22 Jann Horn
2018-08-27 19:02 Andy Lutomirski
2018-08-27 18:56 Jann Horn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).