* [PATCH -tip] x86/kprobes: Drop removed INT3 handling code
@ 2022-11-25 14:44 Masami Hiramatsu (Google)
2022-11-28 20:49 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Masami Hiramatsu (Google) @ 2022-11-25 14:44 UTC (permalink / raw)
To: x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Peter Zijlstra,
Masami Hiramatsu, linux-kernel, Steven Rostedt, Huacai Chen,
Jinyang He, Tiezhu Yang, Naveen N . Rao
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Drop removed INT3 handling code from kprobe_int3_handler() because this
case (get_kprobe() doesn't return corresponding kprobe AND the INT3 is
removed) must not happen with the kprobe managed INT3, but can happen
with the non-kprobe INT3, which should be handled by other callbacks.
For the kprobe managed INT3, the arch_disarm_kprobe() removes the INT3
and then calls text_poke_sync(). Since this text_poke_sync() uses IPI
to call sync_core() on all online cpus, that ensures that all running
INT3 exception handlers have done.
And, the unregister_kprobe() will remove the kprobe from the hash table
after arch_disarm_kprobe().
Thus, when the kprobe managed INT3 hits, kprobe_int3_handler() should
be able to find corresponding kprobe always by get_kprobe(). If it can
not find any kprobe, this means that is NOT a kprobe managed INT3.
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
arch/x86/kernel/kprobes/core.c | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 66299682b6b7..33390ed4dcf3 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -986,20 +986,6 @@ int kprobe_int3_handler(struct pt_regs *regs)
kprobe_post_process(p, regs, kcb);
return 1;
}
- }
-
- if (*addr != INT3_INSN_OPCODE) {
- /*
- * The breakpoint instruction was removed right
- * after we hit it. Another cpu has removed
- * either a probepoint or a debugger breakpoint
- * at this address. In either case, no further
- * handling of this interrupt is appropriate.
- * Back up over the (now missing) int3 and run
- * the original instruction.
- */
- regs->ip = (unsigned long)addr;
- return 1;
} /* else: not a kprobe fault; let the kernel handle it */
return 0;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH -tip] x86/kprobes: Drop removed INT3 handling code
2022-11-25 14:44 [PATCH -tip] x86/kprobes: Drop removed INT3 handling code Masami Hiramatsu (Google)
@ 2022-11-28 20:49 ` Steven Rostedt
2022-11-29 16:28 ` Masami Hiramatsu
0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2022-11-28 20:49 UTC (permalink / raw)
To: Masami Hiramatsu (Google)
Cc: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Peter Zijlstra, linux-kernel, Huacai Chen, Jinyang He,
Tiezhu Yang, Naveen N . Rao
On Fri, 25 Nov 2022 23:44:47 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> Drop removed INT3 handling code from kprobe_int3_handler() because this
> case (get_kprobe() doesn't return corresponding kprobe AND the INT3 is
> removed) must not happen with the kprobe managed INT3, but can happen
> with the non-kprobe INT3, which should be handled by other callbacks.
>
> For the kprobe managed INT3, the arch_disarm_kprobe() removes the INT3
> and then calls text_poke_sync(). Since this text_poke_sync() uses IPI
> to call sync_core() on all online cpus, that ensures that all running
> INT3 exception handlers have done.
> And, the unregister_kprobe() will remove the kprobe from the hash table
> after arch_disarm_kprobe().
>
> Thus, when the kprobe managed INT3 hits, kprobe_int3_handler() should
> be able to find corresponding kprobe always by get_kprobe(). If it can
> not find any kprobe, this means that is NOT a kprobe managed INT3.
>
I believe this was fixed by:
5c02ece81848d ("x86/kprobes: Fix ordering while text-patching")
That should be mentioned in the commit log.
Anyway, looks good.
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-- Steve
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
> arch/x86/kernel/kprobes/core.c | 14 --------------
> 1 file changed, 14 deletions(-)
>
> diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> index 66299682b6b7..33390ed4dcf3 100644
> --- a/arch/x86/kernel/kprobes/core.c
> +++ b/arch/x86/kernel/kprobes/core.c
> @@ -986,20 +986,6 @@ int kprobe_int3_handler(struct pt_regs *regs)
> kprobe_post_process(p, regs, kcb);
> return 1;
> }
> - }
> -
> - if (*addr != INT3_INSN_OPCODE) {
> - /*
> - * The breakpoint instruction was removed right
> - * after we hit it. Another cpu has removed
> - * either a probepoint or a debugger breakpoint
> - * at this address. In either case, no further
> - * handling of this interrupt is appropriate.
> - * Back up over the (now missing) int3 and run
> - * the original instruction.
> - */
> - regs->ip = (unsigned long)addr;
> - return 1;
> } /* else: not a kprobe fault; let the kernel handle it */
>
> return 0;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -tip] x86/kprobes: Drop removed INT3 handling code
2022-11-28 20:49 ` Steven Rostedt
@ 2022-11-29 16:28 ` Masami Hiramatsu
0 siblings, 0 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2022-11-29 16:28 UTC (permalink / raw)
To: Steven Rostedt
Cc: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Peter Zijlstra, linux-kernel, Huacai Chen, Jinyang He,
Tiezhu Yang, Naveen N . Rao
On Mon, 28 Nov 2022 15:49:05 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Fri, 25 Nov 2022 23:44:47 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
>
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> >
> > Drop removed INT3 handling code from kprobe_int3_handler() because this
> > case (get_kprobe() doesn't return corresponding kprobe AND the INT3 is
> > removed) must not happen with the kprobe managed INT3, but can happen
> > with the non-kprobe INT3, which should be handled by other callbacks.
> >
> > For the kprobe managed INT3, the arch_disarm_kprobe() removes the INT3
> > and then calls text_poke_sync(). Since this text_poke_sync() uses IPI
> > to call sync_core() on all online cpus, that ensures that all running
> > INT3 exception handlers have done.
> > And, the unregister_kprobe() will remove the kprobe from the hash table
> > after arch_disarm_kprobe().
> >
> > Thus, when the kprobe managed INT3 hits, kprobe_int3_handler() should
> > be able to find corresponding kprobe always by get_kprobe(). If it can
> > not find any kprobe, this means that is NOT a kprobe managed INT3.
> >
>
> I believe this was fixed by:
>
> 5c02ece81848d ("x86/kprobes: Fix ordering while text-patching")
>
> That should be mentioned in the commit log.
Thanks for pointing! Yes, it ensures since it add text_poke_sync()
in arch_arm/disarm_kprobe(). So this is the last part of the
commit 5c02ece81848d.
>
> Anyway, looks good.
>
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Thank you!
>
> -- Steve
>
>
>
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > ---
> > arch/x86/kernel/kprobes/core.c | 14 --------------
> > 1 file changed, 14 deletions(-)
> >
> > diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> > index 66299682b6b7..33390ed4dcf3 100644
> > --- a/arch/x86/kernel/kprobes/core.c
> > +++ b/arch/x86/kernel/kprobes/core.c
> > @@ -986,20 +986,6 @@ int kprobe_int3_handler(struct pt_regs *regs)
> > kprobe_post_process(p, regs, kcb);
> > return 1;
> > }
> > - }
> > -
> > - if (*addr != INT3_INSN_OPCODE) {
> > - /*
> > - * The breakpoint instruction was removed right
> > - * after we hit it. Another cpu has removed
> > - * either a probepoint or a debugger breakpoint
> > - * at this address. In either case, no further
> > - * handling of this interrupt is appropriate.
> > - * Back up over the (now missing) int3 and run
> > - * the original instruction.
> > - */
> > - regs->ip = (unsigned long)addr;
> > - return 1;
> > } /* else: not a kprobe fault; let the kernel handle it */
> >
> > return 0;
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-29 16:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-25 14:44 [PATCH -tip] x86/kprobes: Drop removed INT3 handling code Masami Hiramatsu (Google)
2022-11-28 20:49 ` Steven Rostedt
2022-11-29 16:28 ` Masami Hiramatsu
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).