From: Jann Horn <jannh@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>,
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>
Cc: Ingo Molnar <mingo@kernel.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Jann Horn <jannh@google.com>
Subject: [PATCH] perf: Fix refcount leak on perf_cgroup_ensure_storage error
Date: Mon, 14 Sep 2026 12:37:17 +0200 [thread overview]
Message-ID: <20260914-perf-cgroup-refleak-v1-1-eac12ba28be6@google.com> (raw)
If perf_cgroup_ensure_storage() fails, perf_cgroup_connect() has already
acquired a reference on the cgroup_subsys_state.
Drop that reference before returning.
This probably doesn't matter in practice - it only makes a difference if
a kmalloc allocation fails, with allocation size depending on the cgroup
nesting depth.
Fixes: c2283c9368d4 ("perf/cgroup: Grow per perf_cpu_context heap storage")
Signed-off-by: Jann Horn <jannh@google.com>
---
I've tested manually that forcing the failure path without this patch
causes the refcount to go up and stay up, while after applying the
patch, the refcount drops back to its original value.
---
kernel/events/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 33210aff3ee6..557c950eae06 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1143,8 +1143,10 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
return PTR_ERR(css);
ret = perf_cgroup_ensure_storage(event, css);
- if (ret)
+ if (ret) {
+ css_put(css);
return ret;
+ }
cgrp = container_of(css, struct perf_cgroup, css);
event->cgrp = cgrp;
---
base-commit: 08df884136f1c1197bab2a27814404fd329d9aac
change-id: 20260912-perf-cgroup-refleak-b9b7e5417683
Best regards,
--
Jann Horn <jannh@google.com>
next reply other threads:[~2026-09-14 10:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 10:37 Jann Horn [this message]
2026-09-15 19:18 ` 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=20260914-perf-cgroup-refleak-v1-1-eac12ba28be6@google.com \
--to=jannh@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.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@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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®