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 v6 2/2] perf: Add checks to prevent null ptr access
Date: Wed, 02 Sep 2026 14:41:30 +0000	[thread overview]
Message-ID: <20260902144130.9FF131F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902141824.733112-3-vinay.belgaumkar@intel.com>

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

Pre-existing issues:
- [High] The lockless checks for revoked state and NULL PMU pointers are insufficient to prevent a Use-After-Free of the PMU structure or a NULL pointer dereference during concurrent unregistration.
--

commit 4a985bf8ccfd6853c89a279d4b7181e83c33bcef
Author: Vinay Belgaumkar <vinay.belgaumkar@intel.com>

perf: Add checks to prevent null ptr access

This commit adds a check for revoked states in perf_event_read_local() and
a null pointer check for the PMU in __perf_event_read_cpu().

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 7777e82aad5e7..059f82f0cadd4 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -4788,14 +4788,19 @@ static inline const struct cpumask *perf_scope_cpu_topology_cpumask(unsigned int
>  
>  static int __perf_event_read_cpu(struct perf_event *event, int event_cpu)
>  {
> +	struct pmu *pmu = READ_ONCE(event->pmu);
>  	int local_cpu = smp_processor_id();
>  	u16 local_pkg, event_pkg;
>  
>  	if ((unsigned)event_cpu >= nr_cpu_ids)
>  		return event_cpu;
>  
> +	if (!pmu)
> +		return -ENODEV;
> +

[Severity: High]
This is a pre-existing issue, but does this lockless check provide a false
sense of security against concurrent PMU unregistration? A concurrent
perf_pmu_unregister() can set event->pmu = NULL and free the PMU memory. Since
this check relies on a cached pointer without holding locks that serialize
against unregistration (e.g., ctx->lock), the PMU can be freed immediately
after this check passes.

>  	if (event->group_caps & PERF_EV_CAP_READ_SCOPE) {
> -		const struct cpumask *cpumask = perf_scope_cpu_topology_cpumask(event->pmu->scope, event_cpu);
> +		const struct cpumask *cpumask = perf_scope_cpu_topology_cpumask(pmu->scope,
> +										event_cpu);

[Severity: High]
This is a pre-existing issue, but can this lead to a Use-After-Free when
accessing pmu->scope? If the PMU is unregistered and freed by another CPU
after we cache it but before we dereference it here, pmu->scope will read from
freed memory.

[ ... ]

> @@ -4917,6 +4922,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;
> +	}
> +

[Severity: High]
This is a pre-existing issue, but is this check vulnerable to a TOCTOU race?
The event state can change immediately after this check if the event context is
inactive or belongs to a different CPU, allowing a concurrent unregistration to
detach the event and free the PMU while perf_event_read_local() continues
executing. This leaves the subsequent call to event->pmu->read(event)
unprotected, potentially resulting in a NULL pointer dereference or
Use-After-Free.

>  	/*
>  	 * Get the event CPU numbers, and adjust them to local if the event is
>  	 * a per-package event that can be read locally

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

  reply	other threads:[~2026-09-02 14:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 14:18 [PATCH v6 0/2] perf: Add some null ptr checks Vinay Belgaumkar
2026-09-02 14:18 ` [PATCH v6 1/2] perf: Fix null pointer access in is_include_guest_event() Vinay Belgaumkar
2026-09-02 14:35   ` sashiko-bot
2026-09-02 14:18 ` [PATCH v6 2/2] perf: Add checks to prevent null ptr access Vinay Belgaumkar
2026-09-02 14:41   ` sashiko-bot [this message]
2026-09-02 15:42 ` ✓ CI.KUnit: success for perf: Add some null ptr checks (rev2) Patchwork
2026-09-02 16:37 ` ✓ Xe.CI.BAT: " 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=20260902144130.9FF131F000E9@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.