mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	 Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 Andrii Nakryiko <andrii@kernel.org>
Cc: Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	 Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,  Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	 linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
	 linux-kernel@vger.kernel.org, Ian Rogers <irogers@google.com>
Subject: [PATCH v1 0/2] perf/bpf: Fix BPF program inheritance and overflow races
Date: Mon, 30 Nov 2026 23:16:51 -0800	[thread overview]
Message-ID: <20261201071653.827828-1-irogers@google.com> (raw)

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


             reply	other threads:[~2026-12-01  7:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  7:16 Ian Rogers [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201071653.827828-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=memxor@gmail.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®