linux/arch/arm
Marco Elver 78ed93d72d signal: Deliver SIGTRAP on perf event asynchronously if blocked
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
2022-04-22 12:14:05 +02:00
..
boot ARM fixes for 5.18-rc1: 2022-04-03 10:17:48 -07:00
common
configs ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
crypto This push fixes the following issues: 2022-03-31 11:17:39 -07:00
include Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2022-04-01 19:57:03 -07:00
kernel signal: Deliver SIGTRAP on perf event asynchronously if blocked 2022-04-22 12:14:05 +02:00
lib asm-generic updates for 5.18 2022-03-23 18:03:08 -07:00
mach-actions
mach-airoha ARM: Add basic support for Airoha EN7523 SoC 2022-03-01 09:02:01 +01:00
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91 ARM: at91: Kconfig: select PM_OPP 2022-02-25 12:36:26 +01:00
mach-axxia
mach-bcm ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci
mach-digicolor
mach-dove
mach-ep93xx
mach-exynos ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-footbridge ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-gemini
mach-highbank
mach-hisi
mach-imx
mach-integrator ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-iop32x ARM development updates for 5.18: 2022-03-23 17:35:57 -07: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-02-25 16:38:34 +01:00
mach-moxart
mach-mstar ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-mv78xx0
mach-mvebu
mach-mxs
mach-nomadik
mach-npcm
mach-nspire ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-omap1
mach-omap2 ARM: OMAP2+: Fix regression for smc calls for vmap stack 2022-03-31 22:41:27 +02:00
mach-orion5x ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-oxnas
mach-pxa ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-qcom
mach-rda
mach-realtek
mach-realview
mach-rockchip
mach-rpc
mach-s3c ARM fixes for 5.18-rc1: 2022-04-03 10:17:48 -07:00
mach-s5pv210
mach-sa1100
mach-shmobile ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-socfpga
mach-spear ARM: spear: fix typos in comments 2022-03-19 22:33:59 +01:00
mach-sti
mach-stm32
mach-sunxi
mach-tegra
mach-uniphier
mach-ux500 ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-versatile
mach-vexpress
mach-vt8500
mach-zynq
mm Merge branches 'fixes' and 'misc' into for-linus 2022-04-01 16:12:31 +01:00
net bpf, arm: Fix various typos in comments 2022-03-21 16:20:26 +01:00
nwfpe
plat-omap
plat-orion
plat-pxa
plat-versatile
probes ARM development updates for 5.18: 2022-03-23 17:35:57 -07:00
tools arch: syscalls: simplify uapi/kapi directory creation 2022-03-31 12:03:46 +09:00
vdso ARM: 9181/1: vdso: remove -nostdlib compiler flag 2022-02-28 13:59:45 +00:00
vfp
xen
Kbuild
Kconfig dma-mapping updates for Linux 5.18 2022-03-29 08:50:14 -07:00
Kconfig-nommu
Kconfig.assembler
Kconfig.debug ARM development updates for 5.18: 2022-03-23 17:35:57 -07:00
Makefile ARM: DT updates for 5.18 2022-03-23 18:37:22 -07:00