From: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org,
Vinay Belgaumkar <vinay.belgaumkar@intel.com>,
Alexander Kanevskiy <alexander.kanevskiy@intel.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>
Subject: [PATCH v4] perf: Fix null pointer access in is_include_guest_event()
Date: Mon, 31 Aug 2026 16:50:30 -0700 [thread overview]
Message-ID: <20260831235030.6737-1-vinay.belgaumkar@intel.com> (raw)
A kernel panic is observed when an application has a perf connection open
and the driver managing the pmu event unbinds. The issue occurs when
perf_pmu_unregister() is called while there is an active perf session. The
null pointer error is seen when the event is freed through __free_event()
and mediated_pmu_unaccount_event is called. There is a missing null check
inside is_include_guest_event(). Also call mediated_pmu_unaccount_event()
inside __pmu_detach_event() similar to __free_event().
Signature of the failure:
Oops: general protection fault, kernel NULL pointer dereference
...
RIP: 0010:_free_event+0x3e/0x370
...
Call Trace:
...
perf_event_release_kernel+0x260/0x2d0
perf_release+0x12/0x20
While here, also add a null check inside perf_event_read_local() which can
cause a similar crash. Sashiko pointed out a possible race between when we
check for revoked state here and then actually access event-pmu inside
__perf_event_read_cpu(). So, add another null check there.
v2: Add another check to prevent null access (sashiko)
v3: Use READ_ONCE for checking pmu state (sashiko)
v4: READ_ONCE for the pmu check as well (sashiko)
Fixes: eff95e170275 ("perf: Add APIs to create/release mediated guest vPMUs")
Cc: Alexander Kanevskiy <alexander.kanevskiy@intel.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Assisted-by: Claude:Claude-Sonnet-5
Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
---
kernel/events/core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 94ca277e0819..4f8c5191ef2c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4794,6 +4794,9 @@ static int __perf_event_read_cpu(struct perf_event *event, int event_cpu)
if ((unsigned)event_cpu >= nr_cpu_ids)
return event_cpu;
+ if (!READ_ONCE(event->pmu))
+ return -ENODEV;
+
if (event->group_caps & PERF_EV_CAP_READ_SCOPE) {
const struct cpumask *cpumask = perf_scope_cpu_topology_cpumask(event->pmu->scope, event_cpu);
@@ -4917,6 +4920,11 @@ int perf_event_read_local(struct perf_event *event, u64 *value,
goto out;
}
+ if (READ_ONCE(event->state) <= PERF_EVENT_STATE_REVOKED) {
+ ret = -ENODEV;
+ goto out;
+ }
+
/*
* Get the event CPU numbers, and adjust them to local if the event is
* a per-package event that can be read locally
@@ -6350,6 +6358,9 @@ static DEFINE_MUTEX(perf_mediated_pmu_mutex);
/* !exclude_guest event of PMU with PERF_PMU_CAP_MEDIATED_VPMU */
static inline bool is_include_guest_event(struct perf_event *event)
{
+ if (!event->pmu)
+ return false;
+
if ((event->pmu->capabilities & PERF_PMU_CAP_MEDIATED_VPMU) &&
!event->attr.exclude_guest)
return true;
@@ -12977,6 +12988,7 @@ static void __pmu_detach_event(struct pmu *pmu, struct perf_event *event,
exclusive_event_destroy(event);
module_put(pmu->module);
+ mediated_pmu_unaccount_event(event);
event->pmu = NULL; /* force fault instead of UAF */
}
--
2.38.1
next reply other threads:[~2026-08-31 23:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 23:50 Vinay Belgaumkar [this message]
2026-09-01 0:04 ` ✓ CI.KUnit: success for perf: Fix null pointer access in is_include_guest_event() (rev4) Patchwork
2026-09-01 0:09 ` [PATCH v4] perf: Fix null pointer access in is_include_guest_event() sashiko-bot
2026-09-01 0:58 ` ✓ Xe.CI.BAT: success for perf: Fix null pointer access in is_include_guest_event() (rev4) Patchwork
2026-09-01 1:44 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-09-01 1:54 ` [PATCH v4] perf: Fix null pointer access in is_include_guest_event() Mi, Dapeng
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=20260831235030.6737-1-vinay.belgaumkar@intel.com \
--to=vinay.belgaumkar@intel.com \
--cc=alexander.kanevskiy@intel.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.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