From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Linus Torvalds <torvalds@linuxfoundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Kees Cook <kees@kernel.org>
Subject: [patch 0/6] perf: Convert mmap() related reference counts to refcount_t
Date: Wed, 6 Aug 2025 22:12:52 +0200 (CEST) [thread overview]
Message-ID: <20250806195624.880096284@linutronix.de> (raw)
The recently fixed reference count leaks could have been detected by using
refcount_t and refcount_t would have mitigated the potential overflow at
least.
It turned out that converting the code as is does not work as the
allocation code ends up doing a refcount_inc() for the first allocation,
which causes refcount_t sanity checks to emit a UAF warning.
The reason is that the code is sharing functionality at the wrong level and
ends up being overly complicated for no reason. That's what inevitable led
to the refcount leak problems.
Address this by splitting the ringbuffer and the AUX buffer mapping and
allocation parts out into seperate functions, which handle the reference
counts in a sane way.
That not only simplifies the code and makes it halfways comprehensible, but
also allows to convert the mmap() related reference counts to refcount_t.
It survives lightweight testing with perf and passes the perf/mmap
selftest.
The series applies on top of Linus tree and is also available from git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git perf/refcounts
Thanks,
tglx
---
include/linux/perf_event.h | 2
kernel/events/core.c | 361 ++++++++++++++++++++++----------------------
kernel/events/internal.h | 4
kernel/events/ring_buffer.c | 2
4 files changed, 185 insertions(+), 184 deletions(-)
next reply other threads:[~2025-08-06 20:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 20:12 Thomas Gleixner [this message]
2025-08-06 20:12 ` [patch 1/6] perf/core: Remove redundant condition for AUX buffer size Thomas Gleixner
2025-08-07 13:30 ` Lorenzo Stoakes
2025-08-06 20:12 ` [patch 2/6] perf/core: Split out mlock limit handling Thomas Gleixner
2025-08-07 14:14 ` Lorenzo Stoakes
2025-08-06 20:12 ` [patch 3/6] perf/core: Split out VM accounting Thomas Gleixner
2025-08-07 14:25 ` Lorenzo Stoakes
2025-08-06 20:12 ` [patch 4/6] perf/core: Split out ringbuffer allocation Thomas Gleixner
2025-08-07 15:38 ` Lorenzo Stoakes
2025-08-11 6:26 ` Thomas Gleixner
2025-08-06 20:13 ` [patch 5/6] perf/core: Split the ringbuffer mmap() and allocation code out Thomas Gleixner
2025-08-06 20:13 ` [patch 6/6] perf/core: Convert mmap() refcounts to refcount_t Thomas Gleixner
2025-08-07 15:39 ` [patch 0/6] perf: Convert mmap() related reference counts " Lorenzo Stoakes
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=20250806195624.880096284@linutronix.de \
--to=tglx@linutronix.de \
--cc=acme@redhat.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linuxfoundation.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®