linux-stable/arch/sparc/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
..
syscalls mm/mempolicy: wire up syscall set_mempolicy_home_node 2022-01-15 16:30:30 +02:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Makefile sparc: share process creation helpers between sparc and sparc64 2020-06-23 10:49:56 +02:00
adi_64.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 482 2019-06-19 17:09:52 +02:00
apc.c
asm-offsets.c
audit.c audit: add support for the openat2 syscall 2021-10-01 16:52:48 -04:00
auxio_32.c
auxio_64.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
btext.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
central.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
cherrs.S
chmc.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
compat_audit.c audit: add support for the openat2 syscall 2021-10-01 16:52:48 -04:00
cpu.c mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
cpumap.c sparc64: Replace zero-length array with flexible-array 2020-05-07 18:49:04 -07:00
cpumap.h
devices.c
ds.c sparc/vio: make remove callback return void 2021-05-14 13:45:58 +02:00
dtlb_miss.S
dtlb_prot.S
ebus.c
entry.S Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc 2021-02-23 15:09:53 -08:00
entry.h
etrap_32.S
etrap_64.S
fpu_traps.S
ftrace.c ftrace: Cleanup ftrace_dyn_arch_init() 2021-10-08 19:41:39 -04:00
getsetcc.S
head_32.S sparc32: get rid of fake_swapper_regs 2021-01-03 20:10:55 -05:00
head_64.S sparc64: get rid of fake_swapper_regs 2021-01-03 20:10:54 -05:00
helpers.S treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
hvapi.c
hvcalls.S
hvtramp.S
idprom.c
iommu-common.c dma-mapping: introduce dma_get_seg_boundary_nr_pages() 2020-09-03 18:12:15 +02:00
iommu.c sparc/iommu: don't set failed sg dma_address to DMA_MAPPING_ERROR 2021-08-09 17:13:06 +02:00
iommu_common.h sparc: remove the mapping_error dma_map_ops method 2018-12-06 06:56:40 -08:00
ioport.c sparc32: use DMA_DIRECT_REMAP 2021-10-21 13:03:27 +02:00
irq.h
irq_32.c
irq_64.c softirq: Move do_softirq_own_stack() to generic asm header 2021-02-10 23:34:16 +01:00
itlb_miss.S
ivec.S
jump_label.c jump_label: move 'asm goto' support test to Kconfig 2019-01-06 09:46:51 +09:00
kernel.h sparc: share process creation helpers between sparc and sparc64 2020-06-23 10:49:56 +02:00
kgdb_32.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
kgdb_64.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
kprobes.c kprobes: treewide: Make it harder to refer kretprobe_trampoline directly 2021-09-30 21:24:06 -04:00
kstack.h
ktlb.S mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
ldc.c
led.c proc: make the proc_create[_data]() stubs static inlines 2022-01-20 08:52:52 +02:00
leon_kernel.c sparc: Remove unused leon_trans_init 2018-11-18 13:35:22 -08:00
leon_pci.c
leon_pci_grpci1.c
leon_pci_grpci2.c
leon_pmc.c sched/idle: Fix arch_cpu_idle() vs tracing 2020-11-24 16:47:35 +01:00
leon_smp.c mm: remove unneeded includes of <asm/pgalloc.h> 2020-08-07 11:33:26 -07:00
mdesc.c sparc: avoid stringop-overread errors 2021-09-15 13:42:33 -07:00
misctrap.S
module.c
nmi.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
of_device_32.c sparc: Use DT node full_name instead of name for resources 2018-11-18 13:35:22 -08:00
of_device_64.c sparc: Use DT node full_name instead of name for resources 2018-11-18 13:35:22 -08:00
of_device_common.c sparc32: use per-device dma_ops 2020-04-02 18:11:55 -07:00
of_device_common.h
pci.c PCI: Rename pcibios_add_device() to pcibios_device_add() 2021-09-21 15:26:09 -05:00
pci_common.c
pci_fire.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
pci_impl.h
pci_msi.c genirq/msi, treewide: Use a named struct for PCI/MSI attributes 2021-12-09 11:52:21 +01:00
pci_psycho.c
pci_sabre.c sparc: Use of_node_name_eq for node name comparisons 2018-11-18 13:35:21 -08:00
pci_schizo.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
pci_sun4v.c sparc/iommu: don't set failed sg dma_address to DMA_MAPPING_ERROR 2021-08-09 17:13:06 +02:00
pci_sun4v.h
pci_sun4v_asm.S
pcic.c
pcr.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
perf_event.c sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD 2019-06-02 22:16:33 -07:00
pmc.c
power.c sparc: Convert to using %pOFn instead of device_node.name 2018-11-18 13:35:20 -08:00
process.c sparc: switch to kernel_clone() 2020-08-20 13:12:58 +02:00
process_32.c sched: Add wrapper for get_wchan() to keep task blocked 2021-10-15 11:25:14 +02:00
process_64.c sched: Add wrapper for get_wchan() to keep task blocked 2021-10-15 11:25:14 +02:00
prom.h
prom_32.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
prom_64.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
prom_common.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
prom_irqtrans.c sparc: Use device_type helpers to access the node type 2018-11-18 13:35:21 -08:00
psycho_common.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
psycho_common.h
ptrace_32.c sparc: switch to ->regset_get() 2020-07-27 14:31:08 -04:00
ptrace_64.c sparc: switch to ->regset_get() 2020-07-27 14:31:08 -04:00
reboot.c sparc: Use device_type helpers to access the node type 2018-11-18 13:35:21 -08:00
rtrap_32.S sparc32: Preserve clone syscall flags argument for restarts due to signals 2021-02-18 16:15:11 -08:00
rtrap_64.S sched/rt, sparc: Use CONFIG_PREEMPTION 2019-12-08 14:37:35 +01:00
sbus.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
setup_32.c sparc32: get rid of fake_swapper_regs 2021-01-03 20:10:55 -05:00
setup_64.c sparc64: get rid of fake_swapper_regs 2021-01-03 20:10:54 -05:00
signal32.c signal: Deliver SIGTRAP on perf event asynchronously if blocked 2022-06-09 10:25:41 +02:00
signal_32.c uaccess: fix type mismatch warnings from access_ok() 2022-04-08 13:58:44 +02:00
signal_64.c signal: Deliver SIGTRAP on perf event asynchronously if blocked 2022-06-09 10:25:41 +02:00
sigutil.h
sigutil_32.c Remove 'type' argument from access_ok() function 2019-01-03 18:57:57 -08:00
sigutil_64.c
smp_32.c sched/core: Initialize the idle task with preemption disabled 2021-05-12 13:01:45 +02:00
smp_64.c mm: percpu: add generic pcpu_populate_pte() function 2022-01-20 08:52:52 +02:00
sparc_ksyms.c
spiterrs.S
sstate.c kernel.h: split out panic and oops helpers 2021-07-01 11:06:04 -07:00
stacktrace.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
starfire.c
sun4d_irq.c sparc: Use of_node_name_eq for node name comparisons 2018-11-18 13:35:21 -08:00
sun4d_smp.c
sun4m_irq.c mm: remove unneeded includes of <asm/pgalloc.h> 2020-08-07 11:33:26 -07:00
sun4m_smp.c
sun4v_ivec.S
sun4v_mcd.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 482 2019-06-19 17:09:52 +02:00
sun4v_tlb_miss.S
sys32.S net: remove compat_sys_{get,set}sockopt 2020-07-19 18:16:40 -07:00
sys_sparc32.c sparc: remove unused header file nfs_fs.h 2020-06-02 18:41:48 -07:00
sys_sparc_32.c signal/sparc: si_trapno is only used with SIGILL ILL_ILLTRP 2021-07-23 13:08:57 -05:00
sys_sparc_64.c signal/sparc: si_trapno is only used with SIGILL ILL_ILLTRP 2021-07-23 13:08:57 -05:00
syscalls.S sparc64: enable HAVE_COPY_THREAD_TLS 2020-06-23 10:49:54 +02:00
sysfs.c
systbls.h
systbls_32.S sparc: syscalls: switch to generic syscalltbl.sh 2021-05-02 00:43:34 +09:00
systbls_64.S sparc: syscalls: switch to generic syscalltbl.sh 2021-05-02 00:43:34 +09:00
time_32.c
time_64.c cpufreq: Call transition notifier only once for each policy 2019-05-10 12:20:36 +02:00
trampoline_32.S
trampoline_64.S mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
traps_32.c exit: Add and use make_task_dead. 2021-12-13 12:04:45 -06:00
traps_64.c exit: Add and use make_task_dead. 2021-12-13 12:04:45 -06:00
tsb.S
ttable_32.S
ttable_64.S
una_asm_32.S
una_asm_64.S
unaligned_32.c signal/sparc: si_trapno is only used with SIGILL ILL_ILLTRP 2021-07-23 13:08:57 -05:00
unaligned_64.c
uprobes.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 13 2019-05-21 11:28:45 +02:00
urtt_fill.S
utrap.S
vdso.c locking/seqlock, headers: Untangle the spaghetti monster 2020-08-06 16:13:13 +02:00
vio.c bus: Make remove callback return void 2021-07-21 11:53:42 +02:00
viohs.c sparc64: viohs: Use struct_size() helper 2020-06-22 15:43:16 -07:00
visemul.c
vmlinux.lds.S vmlinux.lds.h: Split ELF_DETAILS from STABS_DEBUG 2020-09-01 09:50:35 +02:00
windows.c signal: Replace force_fatal_sig with force_exit_sig when in doubt 2021-11-19 09:15:58 -06:00
winfixup.S
wof.S
wuf.S