* [PATCH] perf: Fix mmap replacement ring lifetime race
@ 2026-07-31 12:04 David Lee
2026-08-02 8:37 ` Sven Eckelmann
0 siblings, 1 reply; 2+ messages in thread
From: David Lee @ 2026-07-31 12:04 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung
Cc: David Lee, Kyle Zeng, Dominik 'Disconnect3d' Czarnota,
mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
james.clark, linux-perf-users, linux-kernel
perf_mmap_close() drops the ring-local mmap_count before serializing
with perf_mmap() through event->mmap_mutex. When the last mapping is
being closed, a concurrent mmap can therefore observe a nonzero
event->mmap_count and a zero rb->mmap_count.
In that case perf_mmap_rb() detaches the old ring, installs a replacement,
and resets event->mmap_count to one. The old close then consumes that
replacement count and detaches the new ring. Its pages can consequently
be freed while the replacement VMA still maps their PFNs.
Take event->mmap_mutex before updating either count. This makes the
ring-local and event-global count transitions atomic with respect to
perf_mmap(), so a replacement cannot be installed until the old close has
detached its ring.
Fixes: 59741451b49c ("perf: Identify the 0->1 transition for event::mmap_count")
Bug found and triaged by OpenAI Security Research and
validated by Trail of Bits.
Assisted-by: Codex:gpt-5.6-sol gpt-5.5-cyber
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
Trail of Bits has a reproducer for this bug that triggers a
kernel panic and can share if needed.
kernel/events/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index ba5bd6a78..f93327c76 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7053,11 +7053,19 @@ static void perf_mmap_close(struct vm_area_struct *vma)
mutex_unlock(&rb->aux_mutex);
}
+ /*
+ * Serialize both count updates with perf_mmap() so they cannot
+ * refer to different ring buffer generations.
+ */
+ mutex_lock(&event->mmap_mutex);
+
if (refcount_dec_and_test(&rb->mmap_count))
detach_rest = true;
- if (!refcount_dec_and_mutex_lock(&event->mmap_count, &event->mmap_mutex))
+ if (!refcount_dec_and_test(&event->mmap_count)) {
+ mutex_unlock(&event->mmap_mutex);
goto out_put;
+ }
ring_buffer_attach(event, NULL);
mutex_unlock(&event->mmap_mutex);
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] perf: Fix mmap replacement ring lifetime race
2026-07-31 12:04 [PATCH] perf: Fix mmap replacement ring lifetime race David Lee
@ 2026-08-02 8:37 ` Sven Eckelmann
0 siblings, 0 replies; 2+ messages in thread
From: Sven Eckelmann @ 2026-08-02 8:37 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, David Lee
Cc: Kyle Zeng, Dominik 'Disconnect3d' Czarnota, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter, james.clark,
linux-perf-users, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1038 bytes --]
On Friday, 31 July 2026 14:04:01 CEST David Lee wrote:
> Fixes: 59741451b49c ("perf: Identify the 0->1 transition for event::mmap_count")
> Bug found and triaged by OpenAI Security Research and
> validated by Trail of Bits.
>
> Assisted-by: Codex:gpt-5.6-sol gpt-5.5-cyber
> Signed-off-by: Kyle Zeng <kylebot@openai.com>
1. weird text (advertisement) + newlines in the tags section which shouldn't be there
https://docs.kernel.org/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin
(and all these tag/format related sections below)
2. author didn't sign off the patch (see below)
3. odd unrelated Signed-off-by without any obvious connection to
the patch
- I actually would guess that Kyle Zeng <kylebot@openai.com> is the author
and David Lee removed its authorship (From: ) before sending the patch.
But in its current form, David is claiming to be the author. And even
when it is the case, David must still add the the non-Author SoB at the
end.
Regards,
Sven
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-02 8:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31 12:04 [PATCH] perf: Fix mmap replacement ring lifetime race David Lee
2026-08-02 8:37 ` Sven Eckelmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox