* [PATCH] scsi: mpt3sas: Fix out-of-bounds cpu_msix_table read on CPU hotplug
@ 2026-11-18 20:13 Louis Sautier
2026-11-18 20:23 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Louis Sautier @ 2026-11-18 20:13 UTC (permalink / raw)
To: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani,
Ranjan Kumar, James E.J. Bottomley, Martin K. Petersen
Cc: MPT-FusionLinux.pdl, linux-scsi, linux-kernel, stable
mpt3sas_base_attach() allocates cpu_msix_table based on the highest CPU
online at probe time, but _base_get_msix_index() indexes it with
raw_smp_processor_id() without a bounds check. Once a CPU with a higher
id comes online, I/O submitted from it causes an out-of-bounds read of
the table. The value read is sent to the firmware as the reply queue
index. When it is not a valid queue, the IOC faults and I/O fails.
On a SAS3224 (FW 16.00.01.00) running v7.4-rc3 with KASAN, booted with
maxcpus=1 and CPUs 1-95 onlined later, read-only fio pinned to each CPU
in turn triggers, on CPU 1:
BUG: KASAN: slab-out-of-bounds in _base_get_msix_index+0x1de/0x230 [mpt3sas]
Read of size 1 at addr ffff88812fdf51c1 by task kworker/1:1H/1528
and, on CPU 16:
mpt3sas_cm0: fault_state(0x1500)!
mpt3sas_cm0: sending diag reset !!
I/O error, dev sda, sector 3873068048 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
mpt3sas_cm0: removing unresponding devices: start
sd 0:0:0:0: [sda] Synchronizing SCSI cache
Allocate the table based on nr_cpu_ids instead, and map every CPU in
each reply queue's affinity mask, including offline ones. Managed IRQ
affinity already spreads the vectors over all possible CPUs, so a CPU
onlined later uses the queue whose affinity mask contains it.
The online-mask restriction and the bounds check added by commit
4a8842de8db4 ("scsi: mpt3sas: fix an out of bound write") are no longer
needed, since the table now has an entry for every possible CPU.
When smp_affinity_enable=0 or a reply queue has no affinity mask, the
fallback path still sets only the entries of the CPUs online at probe
time. A CPU onlined later then reads 0 from the zeroed table, and queue
0 is always a valid queue.
With the change, the same fio test runs without errors, also while
CPUs 1-95 are taken offline and back online in a loop. With maxcpus=12
(12 reply queues), I/O from each of the 96 CPUs completes on the vector
whose affinity mask contains that CPU.
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Louis Sautier <sautier.louis@gmail.com>
---
The table is used when there is a single blk-mq hardware queue, i.e. on
SAS2 and gen 3 chips, and on gen 3.5 chips with host_tagset_enable=0,
smp_affinity_enable=0 or a single non-high-iops reply queue. Gen 3.5
chips also use it for internal commands. It is not used in
msix_load_balance mode.
SAS2 and gen 3.5 cards were not tested.
This patch does not fix the fallback path in
_base_assign_reply_queues(), which walks cpu_online_mask without
cpus_read_lock(). A CPU going offline during probe can make
cpumask_next() return nr_cpu_ids, and the loop then writes the byte
after the end of the table.
drivers/scsi/mpt3sas/mpt3sas_base.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 5c957044eded..b33a3e49608d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -3264,11 +3264,8 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
goto fall_back;
}
- for_each_cpu_and(cpu, mask, cpu_online_mask) {
- if (cpu >= ioc->cpu_msix_table_sz)
- break;
+ for_each_cpu(cpu, mask)
ioc->cpu_msix_table[cpu] = reply_q->msix_index;
- }
}
return;
}
@@ -8409,15 +8406,18 @@ int
mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
{
int r, i, rc;
- int cpu_id, last_cpu_id = 0;
dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__));
/* setup cpu_msix_table */
ioc->cpu_count = num_online_cpus();
- for_each_online_cpu(cpu_id)
- last_cpu_id = cpu_id;
- ioc->cpu_msix_table_sz = last_cpu_id + 1;
+ /*
+ * Allocate an entry for every possible CPU, because
+ * _base_get_msix_index() indexes the table with
+ * raw_smp_processor_id(), which can be a CPU brought online after
+ * the adapter was attached.
+ */
+ ioc->cpu_msix_table_sz = nr_cpu_ids;
ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
ioc->reply_queue_count = 1;
if (!ioc->cpu_msix_table) {
base-commit: 141b164bbe186423e295b139e40e8e2d11cf1341
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] scsi: mpt3sas: Fix out-of-bounds cpu_msix_table read on CPU hotplug
2026-11-18 20:13 [PATCH] scsi: mpt3sas: Fix out-of-bounds cpu_msix_table read on CPU hotplug Louis Sautier
@ 2026-11-18 20:23 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-18 20:23 UTC (permalink / raw)
To: Louis Sautier; +Cc: linux-scsi
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] scsi: mpt3sas: ignored non-EAGAIN error in
mpt3sas_base_attach() [1]
--
commit 68d13dcfec52a6dc8ae0711092e3869b07e277ea
Author: Louis Sautier <sautier.louis@gmail.com>
scsi: mpt3sas: Fix out-of-bounds cpu_msix_table read on CPU hotplug
This commit allocates cpu_msix_table with nr_cpu_ids entries instead of
sizing it from the highest online CPU at probe time, and maps all CPUs in
each reply queue's affinity mask so CPUs onlined after probe do not cause
out-of-bounds reads in _base_get_msix_index().
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 5c957044eded1..b33a3e49608dd 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
[ ... ]
> @@ -8409,15 +8406,18 @@ int
> mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
> {
> int r, i, rc;
> - int cpu_id, last_cpu_id = 0;
>
> dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__));
>
> /* setup cpu_msix_table */
> ioc->cpu_count = num_online_cpus();
> - for_each_online_cpu(cpu_id)
> - last_cpu_id = cpu_id;
> - ioc->cpu_msix_table_sz = last_cpu_id + 1;
> + /*
> + * Allocate an entry for every possible CPU, because
> + * _base_get_msix_index() indexes the table with
> + * raw_smp_processor_id(), which can be a CPU brought online after
> + * the adapter was attached.
> + */
> + ioc->cpu_msix_table_sz = nr_cpu_ids;
> ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
> ioc->reply_queue_count = 1;
> if (!ioc->cpu_msix_table) {
[Severity: High]
This problem wasn't introduced by this patch, but later in
mpt3sas_base_attach() [1], does a failure from the first
_base_make_ioc_operational() call get ignored when it returns an error
other than -EAGAIN?
drivers/scsi/mpt3sas/mpt3sas_base.c:mpt3sas_base_attach() {
...
r = _base_make_ioc_operational(ioc);
if (r == -EAGAIN) {
r = _base_make_ioc_operational(ioc);
if (r)
goto out_free_resources;
}
...
return 0;
}
If _base_make_ioc_operational() fails in _base_static_config_pages() or
_base_event_notification() with an error such as -EFAULT,
mpt3sas_base_attach() falls through and returns 0 instead of jumping to
out_free_resources, leaving _scsih_probe() with a partially initialized
adapter.
[1] https://sashiko.dev/#/bug/linux-864ab92c-c52e-45ab-b16b-b4499e83a698
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118201316.326943-1-sautier.louis@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 20:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 20:13 [PATCH] scsi: mpt3sas: Fix out-of-bounds cpu_msix_table read on CPU hotplug Louis Sautier
2026-11-18 20:23 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox