linux-stable/arch/arm/kernel
Marco Elver b3c6013e1f signal: Deliver SIGTRAP on perf event asynchronously if blocked
[ Upstream commit 78ed93d72d ]

With SIGTRAP on perf events, we have encountered termination of
processes due to user space attempting to block delivery of SIGTRAP.
Consider this case:

    <set up SIGTRAP on a perf event>
    ...
    sigset_t s;
    sigemptyset(&s);
    sigaddset(&s, SIGTRAP | <and others>);
    sigprocmask(SIG_BLOCK, &s, ...);
    ...
    <perf event triggers>

When the perf event triggers, while SIGTRAP is blocked, force_sig_perf()
will force the signal, but revert back to the default handler, thus
terminating the task.

This makes sense for error conditions, but not so much for explicitly
requested monitoring. However, the expectation is still that signals
generated by perf events are synchronous, which will no longer be the
case if the signal is blocked and delivered later.

To give user space the ability to clearly distinguish synchronous from
asynchronous signals, introduce siginfo_t::si_perf_flags and
TRAP_PERF_FLAG_ASYNC (opted for flags in case more binary information is
required in future).

The resolution to the problem is then to (a) no longer force the signal
(avoiding the terminations), but (b) tell user space via si_perf_flags
if the signal was synchronous or not, so that such signals can be
handled differently (e.g. let user space decide to ignore or consider
the data imprecise).

The alternative of making the kernel ignore SIGTRAP on perf events if
the signal is blocked may work for some usecases, but likely causes
issues in others that then have to revert back to interception of
sigprocmask() (which we want to avoid). [ A concrete example: when using
breakpoint perf events to track data-flow, in a region of code where
signals are blocked, data-flow can no longer be tracked accurately.
When a relevant asynchronous signal is received after unblocking the
signal, the data-flow tracking logic needs to know its state is
imprecise. ]

Fixes: 97ba62b278 ("perf: Add support for SIGTRAP on perf events")
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: Dmitry Vyukov <dvyukov@google.com>
Link: https://lore.kernel.org/r/20220404111204.935357-1-elver@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-09 10:25:41 +02:00
..
.gitignore
arch_timer.c
armksyms.c
asm-offsets.c ARM: smp: Enable THREAD_INFO_IN_TASK 2021-09-27 16:54:02 +02:00
atags.h ARM: 9011/1: centralize phys-to-virt conversion of DT/ATAGS address 2020-10-27 12:10:59 +00:00
atags_compat.c
atags_parse.c ARM: 9011/1: centralize phys-to-virt conversion of DT/ATAGS address 2020-10-27 12:10:59 +00:00
atags_proc.c proc: remove PDE_DATA() completely 2022-01-22 08:33:37 +02:00
bios32.c ARM/PCI: Remove unused fields from struct hw_pci 2020-09-18 22:39:09 +01:00
bugs.c
cpuidle.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
crash_dump.c
debug.S ARM: 9005/1: debug: Select flow control for all debug UARTs 2020-09-15 14:35:28 +01:00
devtree.c ARM: Use of_get_cpu_hwid() 2021-10-20 13:36:30 -05:00
dma-isa.c
dma.c
early_printk.c
efi.c
elf.c
entry-armv.S ARM: 9197/1: spectre-bhb: fix loop8 sequence for Thumb2 2022-05-25 09:59:10 +02:00
entry-common.S ARM: Spectre-BHB workaround 2022-03-05 10:42:07 +00:00
entry-ftrace.S ARM: ftrace: avoid redundant loads or clobbering IP 2022-04-08 13:58:43 +02:00
entry-header.S ARM: smp: Free up the TLS register while running in the kernel 2021-09-27 16:54:02 +02:00
entry-v7m.S printk: Userspace format indexing support 2021-07-19 11:57:48 +02:00
fiq.c
fiqasm.S
ftrace.c ftrace: Cleanup ftrace_dyn_arch_init() 2021-10-08 19:41:39 -04:00
head-common.S ARM: smp: Store current pointer in TPIDRURO register if available 2021-09-27 16:54:02 +02:00
head-inflate-data.c
head-nommu.S ARM: 9160/1: NOMMU: Reload __secondary_data after PROCINFO_INITFUNC 2021-12-17 12:02:16 +00:00
head.S Merge branches 'devel-stable' and 'misc' into for-linus 2021-11-02 09:04:22 +00:00
hibernate.c
hw_breakpoint.c ARM: 9064/1: hw_breakpoint: Do not directly check the event's overflow_handler hook 2021-03-25 10:27:41 +00:00
hyp-stub.S Merge branch 'devel-stable' into for-next 2020-12-21 11:19:26 +00:00
insn.c ARM: 9078/1: Add warn suppress parameter to arm_gen_branch_link() 2021-06-07 12:56:20 +01:00
io.c
irq.c irq: arm: perform irqentry in entry code 2021-10-25 10:05:31 +01:00
isa.c
iwmmxt.h ARM: 9029/1: Make iwmmxt.S support Clang's integrated assembler 2020-12-08 10:14:59 +00:00
iwmmxt.S ARM: 9029/1: Make iwmmxt.S support Clang's integrated assembler 2020-12-08 10:14:59 +00:00
jump_label.c
kgdb.c ARM: Fix kgdb breakpoint for Thumb2 2022-02-21 14:56:53 +00:00
machine_kexec.c ARM: 9060/1: kexec: Remove unused kexec_reinit callback 2021-03-09 10:25:35 +00:00
Makefile ARM: report Spectre v2 status through sysfs 2022-03-05 10:41:22 +00:00
module-plts.c ARM: 9098/1: ftrace: MODULE_PLT: Fix build problem without DYNAMIC_FTRACE 2021-07-05 11:52:26 +01:00
module.c ARM: module: add support for place relative relocations 2020-10-28 16:59:43 +01:00
opcodes.c
paravirt.c x86/paravirt: Switch time pvops functions to use static_call() 2021-03-11 16:17:52 +01:00
patch.c
perf_callchain.c perf: Drop dead and useless guest "support" from arm, csky, nds32 and riscv 2021-11-17 14:49:07 +01:00
perf_event_v6.c
perf_event_v7.c arm_pmu: Fix write counter incorrect in ARMv7 big-endian mode 2021-06-01 14:17:01 +01:00
perf_event_xscale.c
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
phys2virt.S ARM: p2v: reduce p2v alignment requirement to 2 MiB 2020-10-28 16:59:43 +01:00
pj4-cp0.c
process.c ARM development for 5.16: 2021-11-02 11:33:15 -07:00
psci_smp.c
ptrace.c ARM development updates for 5.15: 2021-09-09 13:25:49 -07:00
reboot.c ARM: 9096/1: Remove arm_pm_restart() 2021-06-13 18:16:48 +01:00
reboot.h
relocate_kernel.S ARM: kexec: fix oops after TLB are invalidated 2021-02-05 10:23:29 +00:00
return_address.c ARM: Recover kretprobe modified return address in stacktrace 2021-10-22 12:16:53 -04:00
setup.c memblock: make memblock_find_in_range method private 2021-09-03 09:58:17 -07:00
signal.c signal: Deliver SIGTRAP on perf event asynchronously if blocked 2022-06-09 10:25:41 +02:00
signal.h
sigreturn_codes.S
sleep.S ARM: sleep.S: use PC-relative insn sequence for sleep_save_sp/mpidr_hash 2020-10-28 17:05:40 +01:00
smccc-call.S ARM: 9075/1: kernel: Fix interrupted SMC calls 2021-04-18 19:15:14 +01:00
smp.c ARM: 9158/1: leave it to core code to manage thread_info::cpu 2021-12-17 11:34:31 +00:00
smp_scu.c
smp_tlb.c
smp_twd.c
spectre.c ARM: fix build error when BPF_SYSCALL is disabled 2022-03-08 12:53:05 -08:00
stacktrace.c ARM: 9191/1: arm/stacktrace, kasan: Silence KASAN warnings in unwind_frame() 2022-05-25 09:59:01 +02:00
suspend.c ARM: 9066/1: ftrace: pause/unpause function graph tracer in cpu_suspend() 2021-03-25 10:27:42 +00:00
swp_emulate.c uaccess: fix type mismatch warnings from access_ok() 2022-04-08 13:58:44 +02:00
sys_arm.c
sys_oabi-compat.c ARM: 9110/1: oabi-compat: fix oabi epoll sparse warning 2021-08-20 11:39:27 +01:00
tcm.c
thumbee.c
time.c ARM: rpc: use legacy_timer_tick 2020-10-30 21:57:05 +01:00
topology.c ARM, sched/topology: Revert back to default scheduler topology 2020-08-19 10:49:47 +02:00
traps.c uaccess: fix type mismatch warnings from access_ok() 2022-04-08 13:58:44 +02:00
unwind.c ARM: 9026/1: unwind: remove old check for GCC <= 4.2 2020-12-08 10:13:59 +00:00
v7m.c
vdso.c mm: forbid splitting special mappings 2020-12-15 12:13:41 -08:00
vmlinux-xip.lds.S Merge branches 'devel-stable' and 'misc' into for-linus 2021-11-02 09:04:22 +00:00
vmlinux.lds.S ARM: 9140/1: allow compile-testing without machine record 2021-10-25 13:12:34 +01:00
xscale-cp0.c