From: Felix Hoffmann <f3lix.dev@gmx.de>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
linux-perf-users@vger.kernel.org
Cc: Marco Elver <elver@google.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] perf: Hold exec lock until owner-list publication
Date: Fri, 13 Nov 2026 23:12:20 +0100 [thread overview]
Message-ID: <20261113221220.162338-1-f3lix.dev@gmx.de> (raw)
perf_event_open() installs a remove-on-exec event in the target context
while holding the target task's exec_update_lock. It then drops that lock
before linking the event into the opener's perf_event_list.
A concurrent target exec can therefore find the installed event and call
perf_remove_from_owner() before owner_entry has been initialized as a list
node. The resulting list_del() on the zeroed node triggers list corruption
and can panic the kernel.
Keep exec_update_lock held until the event has been published in its
owner's list. This closes the visibility gap while retaining the existing
lock ordering.
Fixes: 2e498d0a74e5 ("perf: Add support for event removal on exec")
Cc: stable@vger.kernel.org
Signed-off-by: Felix Hoffmann <f3lix.dev@gmx.de>
---
Tested on x86-64 with KASAN enabled:
- on the unmodified current kernel, the unprivileged reproducer triggered
list_del() corruption in perf_remove_from_owner() and panicked at round
4,400 as UID 1000
- with this change, the identical reproducer completed 10,000 rounds and
8,395,975 successful perf_event_open() calls without a BUG, warning,
KASAN report or panic
- kernel/events/core.o builds with W=1 and the KASAN-enabled x86-64 kernel
builds successfully
The reproducer and complete console logs are available privately on request.
kernel/events/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f5f2261f1fe6f..f4f292f7b47e2 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -14414,15 +14414,15 @@ SYSCALL_DEFINE5(perf_event_open,
mutex_unlock(&ctx->mutex);
+ mutex_lock(¤t->perf_event_mutex);
+ list_add_tail(&event->owner_entry, ¤t->perf_event_list);
+ mutex_unlock(¤t->perf_event_mutex);
+
if (task) {
up_read(&task->signal->exec_update_lock);
put_task_struct(task);
}
- mutex_lock(¤t->perf_event_mutex);
- list_add_tail(&event->owner_entry, ¤t->perf_event_list);
- mutex_unlock(¤t->perf_event_mutex);
-
/*
* File reference in group guarantees that group_leader has been
* kept alive until we place the new event on the sibling_list.
--
2.43.0
reply other threads:[~2026-11-13 22:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261113221220.162338-1-f3lix.dev@gmx.de \
--to=f3lix.dev@gmx.de \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=elver@google.com \
--cc=irogers@google.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=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
/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®