From: Dapeng Mi <dapeng1.mi@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andi Kleen <ak@linux.intel.com>,
Eranian Stephane <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Dapeng Mi <dapeng1.mi@intel.com>, Zide Chen <zide.chen@intel.com>,
Falcon Thomas <thomas.falcon@intel.com>,
Xudong Hao <xudong.hao@intel.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Hanxiang Xu <xuhx@hust.edu.cn>
Subject: [PATCH 1/2] perf/core: Avoid NULL dereference in mux interval store
Date: Mon, 2 Nov 2026 08:59:04 +0800 [thread overview]
Message-ID: <20261102005905.2017784-1-dapeng1.mi@linux.intel.com> (raw)
perf_pmu_register() currently exposes the PMU device and its attributes
before the per-CPU perf_cpu_pmu_context (cpc) has been allocated and
initialized. That allows a race where user space writes
perf_event_mux_interval_ms before cpc is ready, and
perf_event_mux_interval_ms_store() dereferences it unconditionally.
Fix this by allocating and initializing the per-CPU PMU context before
making the PMU attribute visible, and add a NULL check in
perf_event_mux_interval_ms_store() to avoid dereferencing a missing cpc.
Reported-by: Hanxiang Xu <xuhx@hust.edu.cn>
Closes: https://lore.kernel.org/all/de936c3.1476b.1a162c34cec.Coremail.xuhx@hust.edu.cn/
Fixes: 62b856397927 ("perf: Add sysfs entry to adjust multiplexing interval per PMU")
Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
---
kernel/events/core.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 7cdd02dba4f1..e088c31534bc 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -12831,6 +12831,9 @@ perf_event_mux_interval_ms_store(struct device *dev,
if (timer == pmu->hrtimer_interval_ms)
return count;
+ if (!pmu->cpu_pmu_context)
+ return -ENODEV;
+
mutex_lock(&mux_interval_mutex);
pmu->hrtimer_interval_ms = timer;
@@ -13062,12 +13065,6 @@ int perf_pmu_register(struct pmu *_pmu, const char *name, int type)
pmu->type = pmu_type.id;
atomic_set(&pmu->exclusive_cnt, 0);
- if (pmu_bus_running && !pmu->dev) {
- int ret = pmu_dev_alloc(pmu);
- if (ret)
- return ret;
- }
-
pmu->cpu_pmu_context = alloc_percpu(struct perf_cpu_pmu_context *);
if (!pmu->cpu_pmu_context)
return -ENOMEM;
@@ -13086,6 +13083,12 @@ int perf_pmu_register(struct pmu *_pmu, const char *name, int type)
__perf_mux_hrtimer_init(cpc, cpu);
}
+ if (pmu_bus_running && !pmu->dev) {
+ int ret = pmu_dev_alloc(pmu);
+ if (ret)
+ return ret;
+ }
+
if (!pmu->start_txn) {
if (pmu->pmu_enable) {
/*
--
2.34.1
next reply other threads:[~2026-11-02 1:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 0:59 Dapeng Mi [this message]
2026-11-02 0:59 ` [PATCH 2/2] perf/core: Cancel PMU mux hrtimer before freeing per-CPU context Dapeng Mi
2026-11-02 1:14 ` sashiko-bot
2026-11-02 1:22 ` [PATCH 1/2] perf/core: Avoid NULL dereference in mux interval store sashiko-bot
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=20261102005905.2017784-1-dapeng1.mi@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=dapeng1.mi@intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=thomas.falcon@intel.com \
--cc=xudong.hao@intel.com \
--cc=xuhx@hust.edu.cn \
--cc=zide.chen@intel.com \
/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