From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Vinay Belgaumkar <vinay.belgaumkar@intel.com>,
intel-xe@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org,
Alexander Kanevskiy <alexander.kanevskiy@intel.com>
Subject: Re: [PATCH v5 1/2] perf: Fix null pointer access in is_include_guest_event()
Date: Wed, 2 Sep 2026 08:54:46 +0800 [thread overview]
Message-ID: <a908eb14-ede0-4002-8880-5e2718be8180@linux.intel.com> (raw)
In-Reply-To: <20260901211915.127704-2-vinay.belgaumkar@intel.com>
On 9/2/2026 5:19 AM, Vinay Belgaumkar wrote:
> A typical module unload occurring event when there is an active perf
> connection leads to freeing of the pmu pointer. The call log is something
> like:
> ..
> __pmu_detach_event
> pmu_detach_event
> pmu_detach_events
> perf_pmu_unregister
> ..
>
> __pmu_detach_event() sets event->pmu to null. When the perf connection
> finally is closed, the following stack trace is observed:
>
> 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
>
> A call to mediated_pmu_unaccount_event() inside _free_event() is the root
> cause of this crash. Adding a check to is_include_guest_event() ensures
> we don't accidentally access a null ptr.
Better mention adding an extra mediated_pmu_unaccount_event() call before
clearing event->pmu to ensure the nr_include_guest_events count is
correctly decreased.
>
> 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)
> v5: Improve commit message and split patch into 2 (Dapeng)
Please remove this version history in the formal patch.
Others look good to me. Thanks.
>
> 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 | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 94ca277e0819..f19d27ac411d 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -6350,6 +6350,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 +12980,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 */
> }
>
next prev parent reply other threads:[~2026-09-02 0:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 21:19 [PATCH v5 0/2] perf: Add some null ptr checks Vinay Belgaumkar
2026-09-01 21:19 ` [PATCH v5 1/2] perf: Fix null pointer access in is_include_guest_event() Vinay Belgaumkar
2026-09-02 0:54 ` Mi, Dapeng [this message]
2026-09-01 21:19 ` [PATCH v5 2/2] perf: Add checks to prevent null ptr access Vinay Belgaumkar
2026-09-01 21:41 ` sashiko-bot
2026-09-02 0:55 ` Mi, Dapeng
2026-09-02 7:05 ` ✓ CI.KUnit: success for perf: Add some null ptr checks Patchwork
2026-09-02 8:53 ` ✓ Xe.CI.BAT: " Patchwork
2026-09-02 17:05 ` ✓ Xe.CI.FULL: " Patchwork
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=a908eb14-ede0-4002-8880-5e2718be8180@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=alexander.kanevskiy@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=vinay.belgaumkar@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