From: Sandipan Das <sandipan.das@amd.com>
To: Jayapal Ashwin Nair <jayapalashwin.nair@amd.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: 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>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Borislav Petkov <bp@alien8.de>,
Ravi Bangoria <ravi.bangoria@amd.com>,
Ananth Narayan <ananth.narayan@amd.com>,
Thomas Gleixner <tglx@kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] perf/x86/rapl: Fix use-after-free on rapl_pmus_core on AMD/Hygon
Date: Wed, 14 Oct 2026 10:46:56 +0530 [thread overview]
Message-ID: <4410d7c1-d8ae-40d4-a3ea-8561a79dd6c8@amd.com> (raw)
In-Reply-To: <20261013095051.24777-1-jayapalashwin.nair@amd.com>
On 13-10-2026 15:20, Jayapal Ashwin Nair wrote:
> The global rapl_pmus_core pointer can be used after it has been freed in
> two ways:
>
> 1) init_rapl_pmus() stores the newly allocated rapl_pmus in
> *rapl_pmus_ptr before calling init_rapl_pmu(). If init_rapl_pmu()
> fails, rapl_pmus is freed but *rapl_pmus_ptr is not cleared, leaving
> rapl_pmus_core pointing to freed memory. rapl_pmu_init() then jumps
> to core_init_failed, where rapl_advertise() dereferences it.
>
> 2) If perf_pmu_register() fails for the power_core PMU,
> cleanup_rapl_pmus() frees rapl_pmus_core, but the pointer is not
> cleared. rapl_advertise() then dereferences the stale pointer in the
> same way as in 1).
>
> In both cases, rmmod can result in use-after-free and a double free.
>
> Fix this by setting rapl_pmus_core to NULL on both failure paths.
>
> Fixes: b4943b8bfc41 ("perf/x86/rapl: Add core energy counter support for AMD CPUs")
> Signed-off-by: Jayapal Ashwin Nair <jayapalashwin.nair@amd.com>
> ---
> arch/x86/events/rapl.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
> index 8ed03c32f560..b67986c58146 100644
> --- a/arch/x86/events/rapl.c
> +++ b/arch/x86/events/rapl.c
> @@ -763,8 +763,10 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_
> rapl_pmus->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE;
>
> ret = init_rapl_pmu(rapl_pmus);
> - if (ret)
> + if (ret) {
> + *rapl_pmus_ptr = NULL;
> kfree(rapl_pmus);
> + }
>
> return ret;
> }
> @@ -939,6 +941,7 @@ static int __init rapl_pmu_init(void)
> if (ret) {
> pr_warn("power-core PMU registration failed (%d)\n", ret);
> cleanup_rapl_pmus(rapl_pmus_core);
> + rapl_pmus_core = NULL;
> }
> }
>
Reviewed-by: Sandipan Das <sandipan.das@amd.com>
prev parent reply other threads:[~2026-10-14 5:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 9:50 Jayapal Ashwin Nair
2026-10-14 5:16 ` Sandipan Das [this message]
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=4410d7c1-d8ae-40d4-a3ea-8561a79dd6c8@amd.com \
--to=sandipan.das@amd.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ananth.narayan@amd.com \
--cc=bp@alien8.de \
--cc=dapeng1.mi@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jayapalashwin.nair@amd.com \
--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=ravi.bangoria@amd.com \
--cc=tglx@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®