* [PATCH] uprobes: change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL
@ 2020-07-23 15:44 Oleg Nesterov
2020-07-24 7:41 ` Srikar Dronamraju
2020-07-24 14:07 ` [tip: perf/urgent] uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression tip-bot2 for Oleg Nesterov
0 siblings, 2 replies; 3+ messages in thread
From: Oleg Nesterov @ 2020-07-23 15:44 UTC (permalink / raw)
To: Ingo Molnar, Steven Rostedt
Cc: Aaron Merey, Peter Zijlstra, Srikar Dronamraju, linux-kernel
If a tracee is uprobed and it hits int3 inserted by debugger, handle_swbp()
does send_sig(SIGTRAP, current, 0) which means si_code == SI_USER. This used
to work when this code was written, but then GDB started to validate si_code
and now it simply can't use breakpoints if the tracee has an active uprobe:
# cat test.c
void unused_func(void)
{
}
int main(void)
{
return 0;
}
# gcc -g test.c -o test
# perf probe -x ./test -a unused_func
# perf record -e probe_test:unused_func gdb ./test -ex run
GNU gdb (GDB) 10.0.50.20200714-git
...
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff7ddf909 in dl_main () from /lib64/ld-linux-x86-64.so.2
(gdb)
The tracee hits the internal breakpoint inserted by GDB to monitor shared
library events but GDB misinterprets this SIGTRAP and reports a signal.
Change handle_swbp() to use force_sig(SIGTRAP), this matches do_int3_user()
and fixes the problem.
This is the minimal fix for -stable, arch/x86/kernel/uprobes.c is equally
wrong; it should use send_sigtrap(TRAP_TRACE) instead of send_sig(SIGTRAP),
but this doesn't confuse GDB and needs another x86-specific patch.
Reported-by: Aaron Merey <amerey@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/events/uprobes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index bb0862873dba..5f8b0c52fd2e 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -2199,7 +2199,7 @@ static void handle_swbp(struct pt_regs *regs)
if (!uprobe) {
if (is_swbp > 0) {
/* No matching uprobe; signal SIGTRAP. */
- send_sig(SIGTRAP, current, 0);
+ force_sig(SIGTRAP);
} else {
/*
* Either we raced with uprobe_unregister() or we can't
--
2.25.1.362.g51ebf55
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] uprobes: change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL
2020-07-23 15:44 [PATCH] uprobes: change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL Oleg Nesterov
@ 2020-07-24 7:41 ` Srikar Dronamraju
2020-07-24 14:07 ` [tip: perf/urgent] uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression tip-bot2 for Oleg Nesterov
1 sibling, 0 replies; 3+ messages in thread
From: Srikar Dronamraju @ 2020-07-24 7:41 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Ingo Molnar, Steven Rostedt, Aaron Merey, Peter Zijlstra, linux-kernel
* Oleg Nesterov <oleg@redhat.com> [2020-07-23 17:44:20]:
> If a tracee is uprobed and it hits int3 inserted by debugger, handle_swbp()
> does send_sig(SIGTRAP, current, 0) which means si_code == SI_USER. This used
> to work when this code was written, but then GDB started to validate si_code
> and now it simply can't use breakpoints if the tracee has an active uprobe:
>
>
> The tracee hits the internal breakpoint inserted by GDB to monitor shared
> library events but GDB misinterprets this SIGTRAP and reports a signal.
>
> Change handle_swbp() to use force_sig(SIGTRAP), this matches do_int3_user()
> and fixes the problem.
>
> This is the minimal fix for -stable, arch/x86/kernel/uprobes.c is equally
> wrong; it should use send_sigtrap(TRAP_TRACE) instead of send_sig(SIGTRAP),
> but this doesn't confuse GDB and needs another x86-specific patch.
>
> Reported-by: Aaron Merey <amerey@redhat.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Looks good to me.
Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> ---
> kernel/events/uprobes.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index bb0862873dba..5f8b0c52fd2e 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -2199,7 +2199,7 @@ static void handle_swbp(struct pt_regs *regs)
> if (!uprobe) {
> if (is_swbp > 0) {
> /* No matching uprobe; signal SIGTRAP. */
> - send_sig(SIGTRAP, current, 0);
> + force_sig(SIGTRAP);
> } else {
> /*
> * Either we raced with uprobe_unregister() or we can't
> --
> 2.25.1.362.g51ebf55
>
>
--
Thanks and Regards
Srikar Dronamraju
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: perf/urgent] uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression
2020-07-23 15:44 [PATCH] uprobes: change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL Oleg Nesterov
2020-07-24 7:41 ` Srikar Dronamraju
@ 2020-07-24 14:07 ` tip-bot2 for Oleg Nesterov
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Oleg Nesterov @ 2020-07-24 14:07 UTC (permalink / raw)
To: linux-tip-commits
Cc: Aaron Merey, Oleg Nesterov, Ingo Molnar, Srikar Dronamraju,
stable, x86, LKML
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: fe5ed7ab99c656bd2f5b79b49df0e9ebf2cead8a
Gitweb: https://git.kernel.org/tip/fe5ed7ab99c656bd2f5b79b49df0e9ebf2cead8a
Author: Oleg Nesterov <oleg@redhat.com>
AuthorDate: Thu, 23 Jul 2020 17:44:20 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Fri, 24 Jul 2020 15:38:37 +02:00
uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression
If a tracee is uprobed and it hits int3 inserted by debugger, handle_swbp()
does send_sig(SIGTRAP, current, 0) which means si_code == SI_USER. This used
to work when this code was written, but then GDB started to validate si_code
and now it simply can't use breakpoints if the tracee has an active uprobe:
# cat test.c
void unused_func(void)
{
}
int main(void)
{
return 0;
}
# gcc -g test.c -o test
# perf probe -x ./test -a unused_func
# perf record -e probe_test:unused_func gdb ./test -ex run
GNU gdb (GDB) 10.0.50.20200714-git
...
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff7ddf909 in dl_main () from /lib64/ld-linux-x86-64.so.2
(gdb)
The tracee hits the internal breakpoint inserted by GDB to monitor shared
library events but GDB misinterprets this SIGTRAP and reports a signal.
Change handle_swbp() to use force_sig(SIGTRAP), this matches do_int3_user()
and fixes the problem.
This is the minimal fix for -stable, arch/x86/kernel/uprobes.c is equally
wrong; it should use send_sigtrap(TRAP_TRACE) instead of send_sig(SIGTRAP),
but this doesn't confuse GDB and needs another x86-specific patch.
Reported-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20200723154420.GA32043@redhat.com
---
kernel/events/uprobes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index bb08628..5f8b0c5 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -2199,7 +2199,7 @@ static void handle_swbp(struct pt_regs *regs)
if (!uprobe) {
if (is_swbp > 0) {
/* No matching uprobe; signal SIGTRAP. */
- send_sig(SIGTRAP, current, 0);
+ force_sig(SIGTRAP);
} else {
/*
* Either we raced with uprobe_unregister() or we can't
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-24 14:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 15:44 [PATCH] uprobes: change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL Oleg Nesterov
2020-07-24 7:41 ` Srikar Dronamraju
2020-07-24 14:07 ` [tip: perf/urgent] uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression tip-bot2 for Oleg Nesterov
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).