From: sashiko-bot@kernel.org
To: "Dave Jiang" <dave.jiang@intel.com>
Cc: linux-cxl@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 9/9] perf/cxl: Avoid cpumask_of(-1) when no CPU is assigned
Date: Wed, 29 Jul 2026 15:19:39 +0000 [thread overview]
Message-ID: <20260729151940.382AD1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260729145555.3919550-10-dave.jiang@intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but missing validation in cxl_pmu_event_init() leads to a severe out-of-bounds memory access via event->cpu.
--
--- Patch [9]: [PATCH v2 9/9] perf/cxl: Avoid cpumask_of(-1) when no CPU is assigned ---
commit a8e317fb50ca3d5fbb66719c1a84b3a5f9c785fc
Author: Dave Jiang <dave.jiang@intel.com>
perf/cxl: Avoid cpumask_of(-1) when no CPU is assigned
This commit fixes an out-of-bounds pointer arithmetic issue in cpumask_show()
caused by cpumask_of(-1) when info->on_cpu is transiently -1 during CPU
hotplug. It reads on_cpu once and emits an empty mask if it is negative.
Closes: https://sashiko.dev/#/patchset/20260715191454.459673-1-dave@stgolabs.net?part=1
> diff --git a/drivers/perf/cxl_pmu.c b/drivers/perf/cxl_pmu.c
> --- a/drivers/perf/cxl_pmu.c
> +++ b/drivers/perf/cxl_pmu.c
> @@ -501,8 +501,17 @@ static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr,
> char *buf)
> {
> struct cxl_pmu_info *info = dev_get_drvdata(dev);
> + int cpu = READ_ONCE(info->on_cpu);
>
> - return cpumap_print_to_pagebuf(true, buf, cpumask_of(info->on_cpu));
> + /*
> + * on_cpu is -1 before the first online callback and transiently during
> + * cxl_pmu_offline_cpu(). cpumask_of(-1) computes an out-of-bounds
> + * pointer, so report an empty mask instead.
> + */
[Severity: High]
This problem wasn't introduced by this patch, but since we are handling the
transient -1 state of info->on_cpu here, could the same state cause an
out-of-bounds memory access in cxl_pmu_event_init()?
If perf_event_open() is called concurrently while a CPU hotplug offline
operation (cxl_pmu_offline_cpu()) is temporarily setting info->on_cpu = -1,
the event initialization seems to blindly copy this value:
drivers/perf/cxl_pmu.c:cxl_pmu_event_init() {
...
event->cpu = info->on_cpu;
...
}
The core perf subsystem then appears to dereference this -1 CPU index as an
array offset:
kernel/events/core.c:find_get_context() {
...
cpuctx = per_cpu_ptr(&perf_cpu_context, event->cpu);
ctx = &cpuctx->ctx;
...
}
Does passing -1 here cause an out-of-bounds array read that results in a
wild pointer to cpuctx? It looks like the kernel then immediately attempts
to take a spinlock on this wild pointer, which might lead to memory
corruption. Is additional validation needed in cxl_pmu_event_init() to
prevent this?
> + if (cpu < 0)
> + return sysfs_emit(buf, "\n");
> +
> + return cpumap_print_to_pagebuf(true, buf, cpumask_of(cpu));
> }
> static DEVICE_ATTR_RO(cpumask);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260729145555.3919550-1-dave.jiang@intel.com?part=9
next prev parent reply other threads:[~2026-07-29 15:19 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 14:55 [PATCH v2 0/9] perf/cxlpmu: Misc sashiko raised issues fixes Dave Jiang
2026-07-29 14:55 ` [PATCH v2 1/9] perf/cxl: Program the requested event group on configurable counters Dave Jiang
2026-07-29 15:06 ` sashiko-bot
2026-07-29 22:29 ` Jonathan Cameron
2026-07-30 15:50 ` Dave Jiang
2026-07-29 14:55 ` [PATCH v2 2/9] perf/cxl: Clear stale event fields before reprogramming a counter Dave Jiang
2026-07-29 15:08 ` sashiko-bot
2026-07-29 22:25 ` Jonathan Cameron
2026-07-30 15:45 ` Dave Jiang
2026-07-29 14:55 ` [PATCH v2 3/9] perf/cxl: Fix the counter overflow delta fixup Dave Jiang
2026-07-29 15:13 ` sashiko-bot
2026-07-29 22:21 ` Jonathan Cameron
2026-07-30 16:56 ` Dave Jiang
2026-07-30 17:19 ` Dave Jiang
2026-07-30 19:00 ` Jonathan Cameron
2026-07-29 14:55 ` [PATCH v2 4/9] perf/cxl: Accept an overflow interrupt on MSI message number 0 Dave Jiang
2026-07-29 19:28 ` Jonathan Cameron
2026-07-29 19:59 ` Davidlohr Bueso
2026-07-30 12:18 ` Robin Murphy
2026-07-30 17:57 ` Dave Jiang
2026-07-30 18:57 ` Jonathan Cameron
2026-07-30 21:32 ` Dave Jiang
2026-07-29 14:55 ` [PATCH v2 5/9] perf/cxl: Keep the overflow interrupt pinned to the managed CPU Dave Jiang
2026-07-29 15:23 ` sashiko-bot
2026-07-29 19:25 ` Jonathan Cameron
2026-07-29 20:27 ` Davidlohr Bueso
2026-07-30 11:46 ` Robin Murphy
2026-07-30 18:55 ` Jonathan Cameron
2026-07-30 21:34 ` Dave Jiang
2026-07-30 22:19 ` Dave Jiang
2026-07-29 14:55 ` [PATCH v2 6/9] perf/cxl: Unfreeze counters after handling an overflow interrupt Dave Jiang
2026-07-29 19:24 ` Jonathan Cameron
2026-07-30 12:04 ` Robin Murphy
2026-07-30 18:53 ` Jonathan Cameron
2026-07-30 23:00 ` Dave Jiang
2026-07-29 14:55 ` [PATCH v2 7/9] perf/cxl: Validate the hardware-reported counter width Dave Jiang
2026-07-29 15:11 ` sashiko-bot
2026-07-29 19:21 ` Jonathan Cameron
2026-07-29 14:55 ` [PATCH v2 8/9] perf/cxl: Don't use pmu.dev in IRQ and hotplug callbacks after unregister Dave Jiang
2026-07-29 15:34 ` sashiko-bot
2026-07-29 19:17 ` Jonathan Cameron
2026-07-30 11:38 ` Robin Murphy
2026-07-30 18:51 ` Jonathan Cameron
2026-07-29 14:55 ` [PATCH v2 9/9] perf/cxl: Avoid cpumask_of(-1) when no CPU is assigned Dave Jiang
2026-07-29 15:19 ` sashiko-bot [this message]
2026-07-29 19:14 ` Jonathan Cameron
2026-07-30 9:36 ` Robin Murphy
2026-07-31 0:11 ` Dave Jiang
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=20260729151940.382AD1F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dave.jiang@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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