From: sashiko-bot@kernel.org
To: "Shivasharan S" <shivasharan.srikanteshwara@broadcom.com>,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 26/37] scsi: mpt3sas: Enforce minimum reply frame size and validate chain segment size
Date: Wed, 18 Nov 2026 10:46:06 +0000 [thread overview]
Message-ID: <sashiko-outbox-220742@kernel.org> (raw)
In-Reply-To: <1794995806-5835-27-git-send-email-shivasharan.srikanteshwara@broadcom.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] scsi: mpt3sas: NextChainOffset check in
_base_allocate_memory_pools() misses MPI 2.0
- [Low] scsi: mpt3sas: commit message names MPI2DefaultReply_t instead
of Mpi2SCSIIOReply_t
--
commit b46a865c83daa42dd070e27d812f6e7261e3209a
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
scsi: mpt3sas: Enforce minimum reply frame size and validate chain segment size
This commit enforces a minimum firmware-reported reply frame size and
validates the chain segment size and SGE count per chain segment in
_base_allocate_memory_pools().
> In _base_allocate_memory_pools(), reject a firmware-reported ReplyFrameSize
> smaller than MPI2DefaultReply_t and validate IOCMaxChainSegmentSize to avoid
> integer overflow and out-of-bounds access during SGL construction.
[Severity: Low]
This isn't a bug, but the commit message says ReplyFrameSize is checked
against MPI2DefaultReply_t, whereas the code checks against
sizeof(Mpi2SCSIIOReply_t).
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index dce8378f9347e..2f993dad91757 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
[ ... ]
> @@ -6422,6 +6450,13 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
> /* now do the same for a chain buffer */
> max_sge_elements = ioc->chain_segment_sz - sge_size;
> ioc->max_sges_in_chain_message = max_sge_elements/sge_size;
> + /* the SGE count is stored in the u8 NextChainOffset field */
> + if (ioc->max_sges_in_chain_message > U8_MAX) {
> + ioc_err(ioc,
> + "too many SGEs per chain segment (%u), cannot safely attach\n",
> + ioc->max_sges_in_chain_message);
> + return -EINVAL;
> + }
[Severity: Medium]
Can NextChainOffset still overflow on MPI 2.0 controllers even with this
check?
Storing the SGE count in NextChainOffset only applies to MPI 2.5/2.6 IEEE
SGLs in _base_build_sg_scmd_ieee(). For MPI 2.0 controllers,
ioc->chain_segment_sz is set to ioc->request_sz, and _base_build_sg_scmd()
computes NextChainOffset in 4-byte DWORDs rather than SGEs:
drivers/scsi/mpt3sas/mpt3sas_base.c:_base_build_sg_scmd() {
...
chain_offset = (sges_left == sges_in_segment) ?
0 : (sges_in_segment * ioc->sge_size)/4;
chain_length = sges_in_segment * ioc->sge_size;
if (chain_offset) {
chain_offset = chain_offset <<
MPI2_SGE_CHAIN_OFFSET_SHIFT;
chain_length += ioc->sge_size;
}
ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
chain_length, chain_dma);
...
}
With 12-byte 64-bit SGEs (or 8-byte 32-bit SGEs), a
max_sges_in_chain_message between 86 and 255 passes the U8_MAX check, but
chain_offset exceeds 255 and shifts into the SGE Flags byte at bits 24..31,
corrupting the chain SGE descriptor.
In addition, mpi_request->ChainOffset in the main request frame is a u8
computed from ioc->request_sz in both _base_build_sg_scmd() (in DWORDs) and
_base_build_sg_scmd_ieee() (in SGEs), which is not bounded by the
chain_segment_sz check when ioc->request_sz is large.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=26
next prev parent reply other threads:[~2026-11-18 10:46 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
2026-11-18 9:56 ` [PATCH v2 01/37] scsi: mpt3sas: Validate firmware-reported IOCRequestFrameSize Shivasharan S
2026-11-18 10:28 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 02/37] scsi: mpt3sas: Validate RAID configuration page length Shivasharan S
2026-11-18 10:22 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 03/37] scsi: mpt3sas: Pin Scsi_Host while an ioctl is using its ioc Shivasharan S
2026-11-18 10:41 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 04/37] scsi: mpt3sas: Fix locking and bounds checks on host_trace_buffer sysfs files Shivasharan S
2026-11-18 10:37 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 05/37] scsi: mpt3sas: Fix unlocked use of raid_device in enable_sdev_max_qd_store Shivasharan S
2026-11-18 10:36 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 06/37] scsi: mpt3sas: Fix invalid kfree() of fw_event_work event_data Shivasharan S
2026-11-18 10:30 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 07/37] scsi: mpt3sas: Validate SMP request/response length in bsg handler Shivasharan S
2026-11-18 10:29 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 08/37] scsi: mpt3sas: Validate firmware/user supplied device handles against MaxDevHandle Shivasharan S
2026-11-18 10:33 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 09/37] scsi: mpt3sas: Clamp topology/IR event entry counts to EventDataLength Shivasharan S
2026-11-18 9:56 ` [PATCH v2 10/37] scsi: mpt3sas: NULL ioc->reply_post after freeing it Shivasharan S
2026-11-18 10:27 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 11/37] scsi: mpt3sas: Fix port_table memory leak in _scsih_sas_port_refresh Shivasharan S
2026-11-18 10:22 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 12/37] scsi: mpt3sas: Fix leak and dangling pointer for io_uring_poll_queues Shivasharan S
2026-11-18 10:32 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 13/37] scsi: mpt3sas: Validate max_data_size in MPT3EVENTREPORT ioctl Shivasharan S
2026-11-18 10:20 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 14/37] scsi: mpt3sas: Fix buffer overflow in _scsih_scsi_ioc_info Shivasharan S
2026-11-18 10:21 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 15/37] scsi: mpt3sas: Fix Scsi_Host leak on invalid/tampered device probe Shivasharan S
2026-11-18 10:26 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 16/37] scsi: mpt3sas: Fix page fault from stale ioc->chip after PCI error recovery Shivasharan S
2026-11-18 11:01 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 17/37] scsi: mpt3sas: Clamp ValidEntries in driver trigger page update helpers Shivasharan S
2026-11-18 10:29 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 18/37] scsi: mpt3sas: Clamp firmware reply copies to the allocated reply buffer Shivasharan S
2026-11-18 10:29 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 19/37] scsi: mpt3sas: Reject implausibly small MaxReplyDescriptorPostQueueDepth Shivasharan S
2026-11-18 10:33 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 20/37] scsi: mpt3sas: Validate CurrentHostPageSize before using it as a shift amount Shivasharan S
2026-11-18 10:33 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 21/37] scsi: mpt3sas: Clamp sense_length before copying into transfer_packet->sense Shivasharan S
2026-11-18 10:35 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 22/37] scsi: mpt3sas: Clamp num_luns in _scsih_wait_for_target_to_become_ready Shivasharan S
2026-11-18 10:32 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 23/37] scsi: mpt3sas: Validate phy_number in mpt3sas_transport_update_links Shivasharan S
2026-11-18 10:42 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 24/37] scsi: mpt3sas: Require CAP_SYS_RAWIO for mpt2ctl/mpt3ctl ioctls Shivasharan S
2026-11-18 9:56 ` [PATCH v2 25/37] scsi: mpt3sas: Fix SGE offset boundary check in _ctl_do_mpt_command Shivasharan S
2026-11-18 10:39 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 26/37] scsi: mpt3sas: Enforce minimum reply frame size and validate chain segment size Shivasharan S
2026-11-18 10:46 ` sashiko-bot [this message]
2026-11-18 9:56 ` [PATCH v2 27/37] scsi: mpt3sas: Replace panic() with error return in hard_reset_handler Shivasharan S
2026-11-18 9:56 ` [PATCH v2 28/37] scsi: mpt3sas: Replace panic() calls with error returns in _config_request Shivasharan S
2026-11-18 9:56 ` [PATCH v2 29/37] scsi: mpt3sas: Bound event-log copy size against reply frame size Shivasharan S
2026-11-18 10:39 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 30/37] scsi: mpt3sas: Add _ctl_diag_buffer_reset() helper to clear diag buffer state Shivasharan S
2026-11-18 9:56 ` [PATCH v2 31/37] scsi: mpt3sas: Restrict ioc_dump debugfs and replace raw ioc dump with text Shivasharan S
2026-11-18 10:38 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 32/37] scsi: mpt3sas: Fix out-of-bounds bit operation in _scsih_check_topo_delete_events Shivasharan S
2026-11-18 10:38 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 33/37] scsi: mpt3sas: Bound SMP passthrough buffer reads to actual buffer size Shivasharan S
2026-11-18 10:40 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 34/37] scsi: mpt3sas: Release sas_device reference on error in mpt3sas_transport_port_add Shivasharan S
2026-11-18 10:51 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 35/37] scsi: mpt3sas: NULL the event_log pointer after freeing it Shivasharan S
2026-11-18 9:56 ` [PATCH v2 36/37] scsi: mpt3sas: Bound NVMe passthrough transfer size against PRP buffer capacity Shivasharan S
2026-11-18 10:47 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 37/37] scsi: mpt3sas: Update driver version to 59.100.00.00 Shivasharan S
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=sashiko-outbox-220742@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shivasharan.srikanteshwara@broadcom.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox