1 From fe5ed7ab99c656bd2f5b79b49df0e9ebf2cead8a Mon Sep 17 00:00:00 2001
2 From: Oleg Nesterov <oleg@redhat.com>
3 Date: Thu, 23 Jul 2020 17:44:20 +0200
4 Subject: uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression
6 From: Oleg Nesterov <oleg@redhat.com>
8 commit fe5ed7ab99c656bd2f5b79b49df0e9ebf2cead8a upstream.
10 If a tracee is uprobed and it hits int3 inserted by debugger, handle_swbp()
11 does send_sig(SIGTRAP, current, 0) which means si_code == SI_USER. This used
12 to work when this code was written, but then GDB started to validate si_code
13 and now it simply can't use breakpoints if the tracee has an active uprobe:
16 void unused_func(void)
24 # gcc -g test.c -o test
25 # perf probe -x ./test -a unused_func
26 # perf record -e probe_test:unused_func gdb ./test -ex run
27 GNU gdb (GDB) 10.0.50.20200714-git
29 Program received signal SIGTRAP, Trace/breakpoint trap.
30 0x00007ffff7ddf909 in dl_main () from /lib64/ld-linux-x86-64.so.2
33 The tracee hits the internal breakpoint inserted by GDB to monitor shared
34 library events but GDB misinterprets this SIGTRAP and reports a signal.
36 Change handle_swbp() to use force_sig(SIGTRAP), this matches do_int3_user()
37 and fixes the problem.
39 This is the minimal fix for -stable, arch/x86/kernel/uprobes.c is equally
40 wrong; it should use send_sigtrap(TRAP_TRACE) instead of send_sig(SIGTRAP),
41 but this doesn't confuse GDB and needs another x86-specific patch.
43 Reported-by: Aaron Merey <amerey@redhat.com>
44 Signed-off-by: Oleg Nesterov <oleg@redhat.com>
45 Signed-off-by: Ingo Molnar <mingo@kernel.org>
46 Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
47 Cc: stable@vger.kernel.org
48 Link: https://lore.kernel.org/r/20200723154420.GA32043@redhat.com
49 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
52 kernel/events/uprobes.c | 2 +-
53 1 file changed, 1 insertion(+), 1 deletion(-)
55 --- a/kernel/events/uprobes.c
56 +++ b/kernel/events/uprobes.c
57 @@ -2205,7 +2205,7 @@ static void handle_swbp(struct pt_regs *
60 /* No matching uprobe; signal SIGTRAP. */
61 - send_sig(SIGTRAP, current, 0);
65 * Either we raced with uprobe_unregister() or we can't