linux/arch/x86/events
Sandipan Das 47915e855f perf/x86/amd/brs: Fix kernel address leakage
A user-only branch stack can contain branches that originate from
the kernel. As a result, kernel addresses are exposed to user space
even when PERF_SAMPLE_BRANCH_USER is requested. On AMD processors
supporting X86_FEATURE_BRS (Zen 3 only), perf can still report entries
such as SYSRET/interrupt returns for which the branch-from addresses
are in the kernel.

E.g.

  $ perf record -j any,u -c 4000 -e branch-brs -o - -- \
        perf bench syscall basic --loop 1000 | \
        perf script -i - -F brstack|tr ' ' '\n'| \
        grep -E '0x[89a-f][0-9a-f]{15}'

  ...
  0xffffffff810001c4/0x72e2e32955eb/-/-/-/0//-
  0xffffffff810001c4/0x72e2d94a9821/-/-/-/0//-
  0xffffffff810001c4/0x72e2d94ffa1b/-/-/-/0//-
  ...

BRS provides no hardware branch filtering, so privilege level
filtering is performed entirely in software. However, amd_brs_match_plm()
only validates the branch-to address against the requested privilege
levels. For branches from the kernel to user space, the branch-from
address is left unchecked and is leaked. Extend the software filter to
also validate the branch-from address, so that any branch record whose
branch-from address is in the kernel is dropped when
PERF_SAMPLE_BRANCH_USER is requested.

Fixes: 8910075d61 ("perf/x86/amd: Enable branch sampling priv level filtering")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Sandipan Das <sandipan.das@amd.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://patch.msgid.link/f05931c4f89a146c364bd5dc6b8170b1ac611c65.1783701239.git.sandipan.das@amd.com
Closes: https://lore.kernel.org/all/20260710110235.F3FD81F000E9@smtp.kernel.org/
2026-07-11 12:19:28 +02:00
..
amd perf/x86/amd/brs: Fix kernel address leakage 2026-07-11 12:19:28 +02:00
intel x86/cpu updates for v7.2: 2026-06-15 15:25:17 +05:30
zhaoxin x86/cpu updates for v7.2: 2026-06-15 15:25:17 +05:30
core.c Interrupt core code changes: 2026-06-15 13:19:41 +05:30
Kconfig perf/x86/Kconfig: Fix indentation in the Kconfig file 2022-05-25 15:54:26 +02:00
Makefile perf/x86: Move branch classifier 2022-08-27 00:05:44 +02:00
msr.c perf/x86/msr: Make SMI and PPERF on by default 2026-04-03 14:23:43 +02:00
perf_event_flags.h perf/amd/ibs: Avoid calling perf_allow_kernel() from the IBS NMI handler 2026-02-27 16:40:23 +01:00
perf_event.h perf/x86/intel: Update event constraints and cache_extra_regsfor NVL 2026-05-19 13:49:04 +02:00
probe.c x86/msr: Add explicit includes of <asm/msr.h> 2025-05-02 10:23:47 +02:00
probe.h
rapl.c Convert 'alloc_flex' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
utils.c x86/msr: Add explicit includes of <asm/msr.h> 2025-05-02 10:23:47 +02:00