All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vinay Belgaumkar" <vinay.belgaumkar@intel.com>
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2] perf: Fix null pointer access in is_include_guest_event()
Date: Fri, 28 Aug 2026 21:52:25 +0000	[thread overview]
Message-ID: <20260828215225.F15951F00A3F@smtp.kernel.org> (raw)
In-Reply-To: <20260828212803.3963976-1-vinay.belgaumkar@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] The patch silently alters the behavior of perf_event_read_local() by explicitly returning -EINVAL for revoked or dead events.

Pre-existing issues:
- [High] TOCTOU race in `perf_event_read_local()` allows NULL pointer dereference or Use-After-Free of `event->pmu` despite the newly added state check.
--

commit 3c330c9904a35189d22ecaa756a6d8b5458cfb9c
Author: Vinay Belgaumkar <vinay.belgaumkar@intel.com>

perf: Fix null pointer access in is_include_guest_event()

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().

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index a6c8e38a31104..9809fc10c4f51 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -4917,6 +4917,11 @@ int perf_event_read_local(struct perf_event *event, u64 *value,
>  		goto out;
>  	}
>  
> +	if (event->state <= PERF_EVENT_STATE_REVOKED) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +

[Severity: Medium]
Does this explicitly change the return value for revoked or dead events to
-EINVAL? The commit message describes fixing a null pointer access in
is_include_guest_event(), but does not mention altering the behavior of
perf_event_read_local() for revoked events. Could this be documented in the
commit message?

[Severity: High]
This is a pre-existing issue, but does this lockless state check leave a
time-of-check to time-of-use race window that can still lead to a null
pointer dereference of event->pmu?

If CPU A calls perf_event_read_local(), disables interrupts, and locklessly
checks event->state, it can pass if the event state is
PERF_EVENT_STATE_INACTIVE.

Concurrently, if CPU B calls perf_pmu_unregister() which leads to
__pmu_detach_event(), it will not send an IPI to synchronize with CPU A
since the event is inactive. CPU B then sets event->state to
PERF_EVENT_STATE_REVOKED and clears event->pmu to NULL.

When CPU A continues and calls __perf_event_read_cpu(event, event->cpu),
if the event has PERF_EV_CAP_READ_SCOPE, it will dereference
event->pmu->scope, which was just set to NULL by CPU B, causing a panic.

Can this sequence be synchronized safely?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260828212803.3963976-1-vinay.belgaumkar@intel.com?part=1

  parent reply	other threads:[~2026-08-28 21:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 21:28 [PATCH v2] perf: Fix null pointer access in is_include_guest_event() Vinay Belgaumkar
2026-08-28 21:41 ` ✓ CI.KUnit: success for perf: Fix null pointer access in is_include_guest_event() (rev2) Patchwork
2026-08-28 21:52 ` sashiko-bot [this message]
2026-08-28 22:19 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-28 23:45 ` ✓ 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=20260828215225.F15951F00A3F@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.