linux-stable/arch/arm
Marco Elver 60768ffced 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:22:48 +02:00
..
boot ARM: dts: exynos: add atmel,24c128 fallback to Samsung EEPROM 2022-06-09 10:22:42 +02:00
common
configs ARM: configs: multi_v5_defconfig: re-enable DRM_PANEL and FB_xxx 2022-04-08 14:23:23 +02:00
crypto lib/crypto: blake2s: avoid indirect calls to compression function for Clang CFI 2022-05-30 09:28:59 +02:00
include arm: use fallback for random_get_entropy() instead of zero 2022-05-30 09:29:14 +02:00
kernel signal: Deliver SIGTRAP on perf event asynchronously if blocked 2022-06-09 10:22:48 +02:00
lib
mach-actions
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91
mach-axxia
mach-bcm
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci ARM: davinci: da850-evm: Avoid NULL pointer dereference 2022-04-20 09:34:20 +02:00
mach-digicolor
mach-dove
mach-ep93xx
mach-exynos pinctrl: samsung: fix missing GPIOLIB on ARM64 Exynos config 2022-05-09 09:14:30 +02:00
mach-footbridge
mach-gemini
mach-highbank
mach-hisi ARM: hisi: Add missing of_node_put after of_find_compatible_node 2022-06-09 10:22:42 +02:00
mach-imx ARM: imx: register reset controller from a platform driver 2021-10-15 09:38:06 +08:00
mach-integrator
mach-iop32x ARM: iop32x: offset IRQ numbers by 1 2022-04-08 14:24:11 +02:00
mach-ixp4xx
mach-keystone
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-milbeaut
mach-mmp ARM: mmp: Fix failure to remove sram device 2022-04-08 14:24:02 +02:00
mach-moxart
mach-mstar ARM: mstar: Select HAVE_ARM_ARCH_TIMER 2022-04-08 14:22:46 +02:00
mach-mv78xx0
mach-mvebu
mach-mxs
mach-nomadik
mach-npcm
mach-nspire
mach-omap1 ARM: OMAP1: clock: Fix UART rate reporting algorithm 2022-06-09 10:22:42 +02:00
mach-omap2 ARM: OMAP2+: Fix refcount leak in omap_gic_of_init 2022-05-09 09:14:32 +02:00
mach-orion5x
mach-oxnas
mach-pxa
mach-qcom
mach-rda
mach-realtek
mach-realview
mach-rockchip
mach-rpc
mach-s3c ARM: 9187/1: JIVE: fix return value of __setup handler 2022-04-08 14:24:13 +02:00
mach-s5pv210
mach-sa1100
mach-shmobile ARM: shmobile: rcar-gen2: Add missing of_node_put() 2022-01-27 11:04:25 +01:00
mach-socfpga ARM: socfpga: fix missing RESET_CONTROLLER 2022-02-16 12:56:19 +01:00
mach-spear
mach-sti
mach-stm32
mach-sunxi
mach-tegra
mach-uniphier
mach-ux500
mach-versatile
mach-vexpress ARM: versatile: Add missing of_node_put in dcscb_init 2022-06-09 10:22:42 +02:00
mach-vt8500
mach-zynq
mm ARM: 9196/1: spectre-bhb: enable for Cortex-A15 2022-05-25 09:57:33 +02:00
net
nwfpe
plat-omap
plat-orion
plat-pxa
plat-versatile
probes ARM: 9170/1: fix panic when kasan and kprobe are enabled 2022-02-01 17:27:07 +01:00
tools
vdso
vfp
xen
Kbuild
Kconfig kmap_local: don't assume kmap PTEs are linear arrays in memory 2021-11-25 09:48:43 +01:00
Kconfig-nommu
Kconfig.assembler
Kconfig.debug ARM: imx: rename DEBUG_IMX21_IMX27_UART to DEBUG_IMX27_UART 2022-01-27 11:04:29 +01:00
Makefile ARM: 9156/1: drop cc-option fallbacks for architecture selection 2021-11-18 19:17:13 +01:00