From: sashiko-bot@kernel.org
To: "Ilya Khomyakov" <khomyakovilya@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: mpi3mr: make SAS port PHY masks 64-bit safe
Date: Tue, 04 Aug 2026 14:39:07 +0000 [thread overview]
Message-ID: <20260804143907.9B3AA1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260804140004.4004-1-khomyakovilya@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Incorrect bit iteration over a `u64` variable using `for_each_set_bit` in `mpi3mr_update_mr_sas_port`.
- [High] Out-of-bounds heap write in `mpi3mr_refresh_sas_ports` when a controller firmware reports more than 64 unique PHY connections.
--
--- Patch [1]: [PATCH] scsi: mpi3mr: make SAS port PHY masks 64-bit safe ---
commit f7b3b6c83f03cd4dace1e13e5700d80724e506b0
Author: Ilya Khomyakov <khomyakovilya@gmail.com>
scsi: mpi3mr: make SAS port PHY masks 64-bit safe
This patch fixes 64-bit PHY-mask handling in the Broadcom MPI3 Storage
Controller driver under drivers/scsi/mpi3mr/.
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c
> index 240f67a8e2e3b..d6492dddf7352 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_transport.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c
[ ... ]
> @@ -1765,7 +1805,7 @@ mpi3mr_refresh_sas_ports(struct mpi3mr_ioc *mrioc)
> port_idx = host_port_count;
> h_port[port_idx].sas_address = le64_to_cpu(sasinf->sas_address);
> h_port[port_idx].handle = attached_handle;
> - h_port[port_idx].phy_mask = (1 << i);
> + h_port[port_idx].phy_mask = mpi3mr_sas_phy_bit(i);
[Severity: High]
This isn't a bug introduced by this patch, but can the h_port array overflow
when iterating over the PHYs in mpi3mr_refresh_sas_ports()?
The array is allocated earlier in the function with a fixed size of 64:
h_port = kzalloc_objs(struct host_port, 64);
Since the loop iterates up to mrioc->sas_hba.num_phys times (which is an
8-bit integer allowing up to 255), and host_port_count is incremented for
each unique attached handle without bounds checking, will this write out of
bounds if the firmware reports more than 64 unique PHY connections?
[Severity: High]
This is also a pre-existing issue, but since we are making PHY masks 64-bit
safe, is the bit iteration over the u64 mask in mpi3mr_update_mr_sas_port()
working correctly on 32-bit big-endian architectures?
mpi3mr_update_mr_sas_port() uses for_each_set_bit with a cast to ulong *:
u64 phys_to_be_added, phys_to_be_removed;
...
for_each_set_bit(i, (ulong *) &phys_to_be_added, BITS_PER_TYPE(u64)) {
mr_sas_phy = &mrioc->sas_hba.phy[i];
By casting a local u64 pointer to unsigned long * on 32-bit big-endian
systems, won't the bit halves be swapped? This could result in out-of-bounds
array accesses on mrioc->sas_hba.phy[i] and incorrect topology changes since
bits 0-31 become 32-63 and vice versa.
> h_port[port_idx].iounit_port_id = sas_io_unit_pg0->phy_data[i].io_unit_port;
> h_port[port_idx].lowest_phy = sasinf->phy_num;
> h_port[port_idx].used = 0;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260804140004.4004-1-khomyakovilya@gmail.com?part=1
next prev parent reply other threads:[~2026-08-04 14:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 14:00 [PATCH] scsi: mpi3mr: make SAS port PHY masks 64-bit safe Ilya Khomyakov
2026-08-04 14:39 ` sashiko-bot [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-08-04 14:28 Ilya Khomyakov
2026-08-04 15:29 ` sashiko-bot
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=20260804143907.9B3AA1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=khomyakovilya@gmail.com \
--cc=linux-scsi@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;
as well as URLs for NNTP newsgroup(s).