Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH v1 0/2] perf/bpf: Fix BPF program inheritance and overflow races
@ 2026-12-01  7:16 Ian Rogers
  2026-12-01  7:16 ` [PATCH v1 1/2] perf/bpf: Fix BPF program inheritance races, cookie, and leak in perf_event_alloc() Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ian Rogers @ 2026-12-01  7:16 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko
  Cc: Eduard Zingerman, Kumar Kartikeya Dwivedi, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Adrian Hunter, James Clark,
	Song Liu, Yonghong Song, linux-perf-users, bpf, linux-kernel,
	Ian Rogers

This two-patch series fixes pre-existing races, cookie handling, and a
reference leak in how perf_event handles BPF programs attached to
non-tracing and tracing events:

1. perf_event_alloc() / perf_event_set_bpf_handler() /
   perf_event_free_bpf_handler():
   - Skip inheriting parent_event->prog on tracing events (tracepoints,
     kprobes, uprobes), where copying event->prog without attaching to
     tp_event->prog_array caused child teardown to detach the parent's
     program.
   - Protect lockless inheritance of parent_event->prog with
     rcu_tasks_trace + rcu read locks, smp_load_acquire()/
     smp_store_release(), xchg(), synchronize_rcu() for sleepable
     programs, and bpf_prog_inc_not_zero().
   - Preserve parent_event->bpf_cookie across event inheritance.
   - Move perf_event_free_bpf_prog() into __free_event() so
     perf_event_alloc() error paths cannot leak the inherited bpf_prog
     reference.

2. __perf_event_overflow() / bpf_overflow_handler():
   - Avoid dereferencing event->prog->type outside an RCU read-side
     critical section in __perf_event_overflow().
   - Check prog->type == BPF_PROG_TYPE_PERF_EVENT under rcu_read_lock()
     using smp_load_acquire(), returning 1 if event->prog was
     concurrently cleared so samples are not dropped.

These issues were identified via code audit and Sashiko automated
review while developing perf/BPF changes; the fixes, regression tests,
and changelogs were drafted with an AI coding assistant.

Testing:
- Build-tested kernel/events/core.o across x86_64, arm64, riscv,
  loongarch, CONFIG_BPF_SYSCALL=n (W=1 clean), and
  CONFIG_BPF_SYSCALL=y + CONFIG_EVENT_TRACING=y + CONFIG_BPF_EVENTS=n.
- Runtime-tested in x86_64 QEMU/KVM with CONFIG_PROVE_LOCKING=y and
  CONFIG_PROVE_RCU=y using targeted C regression tests covering:
  (1) inherited tracepoint BPF program continuing to fire after an
      inherited child exits,
  (2) bpf_get_attach_cookie_pe() returning the parent's cookie on an
      inherited child event, and
  (3) concurrent sampling overflow and bpf_perf_link_release() detach
      stress loops (40 iterations, zero lockdep/RCU splats).

Both patches are based on torvalds/master (and apply cleanly to
tip/perf/urgent).

Ian Rogers (2):
  perf/bpf: Fix BPF program inheritance races, cookie, and leak in
    perf_event_alloc()
  perf/bpf: Fix racy event->prog dereference in __perf_event_overflow()

 kernel/events/core.c | 84 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 65 insertions(+), 19 deletions(-)


base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-01  7:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  7:16 [PATCH v1 0/2] perf/bpf: Fix BPF program inheritance and overflow races Ian Rogers
2026-12-01  7:16 ` [PATCH v1 1/2] perf/bpf: Fix BPF program inheritance races, cookie, and leak in perf_event_alloc() Ian Rogers
2026-12-01  7:16 ` [PATCH v1 2/2] perf/bpf: Fix racy event->prog dereference in __perf_event_overflow() Ian Rogers
2026-12-01  7:30 ` [PATCH v1 0/2] perf/bpf: Fix BPF program inheritance and overflow races sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox