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
Subject: Re: [PATCH v5 2/2] perf: Add checks to prevent null ptr access
Date: Wed, 2 Sep 2026 08:55:30 +0800 [thread overview]
Message-ID: <6afe83f1-ad57-4b87-aa18-f08bb7376d64@linux.intel.com> (raw)
In-Reply-To: <20260901211915.127704-3-vinay.belgaumkar@intel.com>
LGTM. Thanks.
On 9/2/2026 5:19 AM, Vinay Belgaumkar wrote:
> Sashiko recommended some additional checks to prevent null pointer
> access. Check for revoked states inside perf_event_read_local(), as
> the pmu event may have already been freed at this point. Add a null
> check inside __perf_event_read_cpu() as well before accessing the pmu
> ptr.
>
> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
> Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
> ---
> kernel/events/core.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index f19d27ac411d..bb90034a2054 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;
> +
> 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);
>
> if (cpumask && cpumask_test_cpu(local_cpu, cpumask))
> return local_cpu;
> @@ -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;
> + }
> +
> /*
> * Get the event CPU numbers, and adjust them to local if the event is
> * a per-package event that can be read locally
next prev parent reply other threads:[~2026-09-02 0:55 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
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 [this message]
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=6afe83f1-ad57-4b87-aa18-f08bb7376d64@linux.intel.com \
--to=dapeng1.mi@linux.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 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.