* [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs
@ 2026-11-18 9:56 Shivasharan S
2026-11-18 9:56 ` [PATCH v2 01/37] scsi: mpt3sas: Validate firmware-reported IOCRequestFrameSize Shivasharan S
` (36 more replies)
0 siblings, 37 replies; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
This series hardens the mpt3sas driver against malformed firmware
data and invalid ioctl/passthrough input, and fixes a number of
locking, reference-count, memory-leak and use-after-free bugs in
the driver.
Changes in v2:
--------------
- Addressed the issues reported by the Sashiko review and the kernel
test robot's build warning.
Patch 1:
- Handle U16 wrap and request_sz smaller than request frame plus two
SGEs.
Patch 2:
- Reject pages larger than U16_MAX; zero the buffer with kzalloc().
Patch 3:
- Add ioc->shost check and also set ioc->shost before the ioc is added
to mpt3sas_ioc_list.
Patch 4 (host_trace_buffer):
- Dropped the ctl_cmds.mutex locking from
mpt3sas_process_trigger_data() to avoid the possible deadlock with
the controller reset path; locking there will be handled in a
separate patch.
- Reset ring_buffer_sz/offset when the trace buffer is (re)posted.
- Take ctl_cmds.mutex in host_trace_buffer_enable_show().
Patch 7 (SMP length):
- Reject request/response lengths <= 4 (previously < 4), which would
have produced a zero-length SGE.
Patch 8 (device handles):
- Return 0 instead of -1 from _scsih_add_device() for an out-of-range
handle.
Patch 9 (topology/IR events):
- Clamp EventDataLength to the max reply frame size;
- Reject events shorter than their header; the per-event entry counts
are clamped to the remaining data.
Patch 14:
- Fix -Wformat-truncation warning reported by the kernel test robot.
Patch 16:
- Added ioc->chip checks to _config_request(), make_ioc_ready,
hard_reset_handler and the IR/NVMe shutdown helpers.
Patch 17:
- Fix signed count check for ValidEntries.
Patch 19:
- Reject hba_queue_depth values that would underflow scsiio_depth.
Patch 20:
- Fix signed overflow and bound page size to 2^12..2^16.
Patch 23:
- Validate against sas_node->num_phys rather than nr_phys_allocated.
Patch 26:
- Increase min reply_sz to sizeof(Mpi2SCSIIOReply_t) and reject
chain segments with more than U8_MAX SGEs.
Patch 28:
- Check return value of _config_request() and return without issuing
WRITE_NVRAM request.
Patch 36:
- Do the sg_tablesize * page_size multiplication in 64 bits.
v1: https://lore.kernel.org/linux-scsi/1793925772-1303-1-git-send-email-shivasharan.srikanteshwara@broadcom.com/
Shivasharan S (37):
scsi: mpt3sas: Validate firmware-reported IOCRequestFrameSize
scsi: mpt3sas: Validate RAID configuration page length
scsi: mpt3sas: Pin Scsi_Host while an ioctl is using its ioc
scsi: mpt3sas: Fix locking and bounds checks on host_trace_buffer
sysfs files
scsi: mpt3sas: Fix unlocked use of raid_device in
enable_sdev_max_qd_store
scsi: mpt3sas: Fix invalid kfree() of fw_event_work event_data
scsi: mpt3sas: Validate SMP request/response length in bsg handler
scsi: mpt3sas: Validate firmware/user supplied device handles against
MaxDevHandle
scsi: mpt3sas: Clamp topology/IR event entry counts to EventDataLength
scsi: mpt3sas: NULL ioc->reply_post after freeing it
scsi: mpt3sas: Fix port_table memory leak in _scsih_sas_port_refresh
scsi: mpt3sas: Fix leak and dangling pointer for io_uring_poll_queues
scsi: mpt3sas: Validate max_data_size in MPT3EVENTREPORT ioctl
scsi: mpt3sas: Fix buffer overflow in _scsih_scsi_ioc_info
scsi: mpt3sas: Fix Scsi_Host leak on invalid/tampered device probe
scsi: mpt3sas: Fix page fault from stale ioc->chip after PCI error
recovery
scsi: mpt3sas: Clamp ValidEntries in driver trigger page update
helpers
scsi: mpt3sas: Clamp firmware reply copies to the allocated reply
buffer
scsi: mpt3sas: Reject implausibly small
MaxReplyDescriptorPostQueueDepth
scsi: mpt3sas: Validate CurrentHostPageSize before using it as a shift
amount
scsi: mpt3sas: Clamp sense_length before copying into
transfer_packet->sense
scsi: mpt3sas: Clamp num_luns in
_scsih_wait_for_target_to_become_ready
scsi: mpt3sas: Validate phy_number in mpt3sas_transport_update_links
scsi: mpt3sas: Require CAP_SYS_RAWIO for mpt2ctl/mpt3ctl ioctls
scsi: mpt3sas: Fix SGE offset boundary check in _ctl_do_mpt_command
scsi: mpt3sas: Enforce minimum reply frame size and validate chain
segment size
scsi: mpt3sas: Replace panic() with error return in hard_reset_handler
scsi: mpt3sas: Replace panic() calls with error returns in
_config_request
scsi: mpt3sas: Bound event-log copy size against reply frame size
scsi: mpt3sas: Add _ctl_diag_buffer_reset() helper to clear diag
buffer state
scsi: mpt3sas: Restrict ioc_dump debugfs and replace raw ioc dump with
text
scsi: mpt3sas: Fix out-of-bounds bit operation in
_scsih_check_topo_delete_events
scsi: mpt3sas: Bound SMP passthrough buffer reads to actual buffer
size
scsi: mpt3sas: Release sas_device reference on error in
mpt3sas_transport_port_add
scsi: mpt3sas: NULL the event_log pointer after freeing it
scsi: mpt3sas: Bound NVMe passthrough transfer size against PRP buffer
capacity
scsi: mpt3sas: Update driver version to 59.100.00.00
drivers/scsi/mpt3sas/mpt3sas_base.c | 142 +++++++++++++---
drivers/scsi/mpt3sas/mpt3sas_base.h | 16 +-
drivers/scsi/mpt3sas/mpt3sas_config.c | 95 ++++++++---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 201 ++++++++++++++++++----
drivers/scsi/mpt3sas/mpt3sas_debugfs.c | 49 +++++-
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 203 +++++++++++++++++++----
drivers/scsi/mpt3sas/mpt3sas_transport.c | 16 +-
7 files changed, 608 insertions(+), 114 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 68+ messages in thread
* [PATCH v2 01/37] scsi: mpt3sas: Validate firmware-reported IOCRequestFrameSize
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 ` 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
` (35 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Reject an IOCFacts-reported request frame size smaller than
Mpi25SCSIIORequest_t, which would otherwise corrupt adjacent memory.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 1af25a22611a..aea300f55051 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -6296,7 +6296,7 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
u16 max_sge_elements;
u16 chains_needed_per_io;
u32 sz, total_sz, reply_post_free_sz, reply_post_free_array_sz;
- u32 retry_sz;
+ u32 retry_sz, req_sz;
u32 rdpq_sz = 0, sense_sz = 0;
u16 max_request_credit, nvme_blocks_needed;
unsigned short sg_tablesize;
@@ -6371,8 +6371,15 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
*/
ioc->hba_queue_depth = max_request_credit + ioc->hi_priority_depth;
- /* request frame size */
- ioc->request_sz = facts->IOCRequestFrameSize * 4;
+ req_sz = (u32)facts->IOCRequestFrameSize * 4;
+ if (req_sz < offsetof(Mpi25SCSIIORequest_t, SGL) +
+ 2 * sizeof(MPI25_SGE_IO_UNION) || req_sz > U16_MAX) {
+ ioc_err(ioc,
+ "IOCFacts reported invalid RequestFrameSize (%u bytes)\n",
+ req_sz);
+ return -EINVAL;
+ }
+ ioc->request_sz = req_sz;
/* reply frame size */
ioc->reply_sz = facts->ReplyFrameSize * 4;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 02/37] scsi: mpt3sas: Validate RAID configuration page length
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 9:56 ` 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
` (34 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Check the RAID config page length and NumElements against the
allocated buffer before use, to avoid an out-of-bounds read.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_config.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c
index b0d5ef893600..eb51ce3610c8 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_config.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_config.c
@@ -2655,6 +2655,7 @@ mpt3sas_config_get_volume_handle(struct MPT3SAS_ADAPTER *ioc, u16 pd_handle,
int config_num;
u16 element_type;
u16 phys_disk_dev_handle;
+ int max_num_elements;
*volume_handle = 0;
memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
@@ -2672,7 +2673,15 @@ mpt3sas_config_get_volume_handle(struct MPT3SAS_ADAPTER *ioc, u16 pd_handle,
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
config_page_sz = (le16_to_cpu(mpi_reply.ExtPageLength) * 4);
- config_page = kmalloc(config_page_sz, GFP_KERNEL);
+ /* _config_request() takes a u16 size, so larger pages can't be handled */
+ if (config_page_sz < offsetof(Mpi2RaidConfigurationPage0_t,
+ ConfigElement) || config_page_sz > U16_MAX) {
+ ioc_err(ioc, "%s: RAID configuration page length (%d) is invalid\n",
+ __func__, config_page_sz);
+ r = -EIO;
+ goto out;
+ }
+ config_page = kzalloc(config_page_sz, GFP_KERNEL);
if (!config_page) {
r = -1;
goto out;
@@ -2692,7 +2701,11 @@ mpt3sas_config_get_volume_handle(struct MPT3SAS_ADAPTER *ioc, u16 pd_handle,
MPI2_IOCSTATUS_MASK;
if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
goto out;
- for (i = 0; i < config_page->NumElements; i++) {
+ max_num_elements = (config_page_sz -
+ offsetof(Mpi2RaidConfigurationPage0_t, ConfigElement)) /
+ sizeof(config_page->ConfigElement[0]);
+ for (i = 0; i < config_page->NumElements &&
+ i < max_num_elements; i++) {
element_type = le16_to_cpu(config_page->
ConfigElement[i].ElementFlags) &
MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 03/37] scsi: mpt3sas: Pin Scsi_Host while an ioctl is using its ioc
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 9:56 ` [PATCH v2 02/37] scsi: mpt3sas: Validate RAID configuration page length Shivasharan S
@ 2026-11-18 9:56 ` 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
` (33 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Take a Scsi_Host reference in _ctl_verify_adapter() and release it
once the ioctl is done, so the adapter can't be torn down while an
ioctl is in flight.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 6 ++++++
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 3 ++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 8bb947004885..f4eeef572f6e 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -447,6 +447,11 @@ _ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp,
continue;
}
out:
+ if (!ioc->shost || !scsi_host_get(ioc->shost)) {
+ spin_unlock(&gioc_lock);
+ *iocpp = NULL;
+ return -1;
+ }
spin_unlock(&gioc_lock);
*iocpp = ioc;
return ioc_number;
@@ -2847,6 +2852,7 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
mutex_unlock(&ioc->ctl_cmds.mutex);
out_unlock_pciaccess:
mutex_unlock(&ioc->pci_access_mutex);
+ scsi_host_put(ioc->shost);
return ret;
}
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 085d4672db85..f78fc0faad61 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -13494,11 +13494,12 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
return -ENODEV;
}
+ /* shost must be valid before the ioc becomes visible to ioctls */
+ ioc->shost = shost;
INIT_LIST_HEAD(&ioc->list);
spin_lock(&gioc_lock);
list_add_tail(&ioc->list, &mpt3sas_ioc_list);
spin_unlock(&gioc_lock);
- ioc->shost = shost;
ioc->pdev = pdev;
ioc->scsi_io_cb_idx = scsi_io_cb_idx;
ioc->tm_cb_idx = tm_cb_idx;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 04/37] scsi: mpt3sas: Fix locking and bounds checks on host_trace_buffer sysfs files
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (2 preceding siblings ...)
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 9:56 ` 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
` (32 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Serialize the host_trace_buffer* sysfs handlers on ctl_cmds.mutex and
clamp the reported/used buffer size to the actual allocation size.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 69 ++++++++++++++++++++++++------
1 file changed, 57 insertions(+), 12 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index f4eeef572f6e..ef28da96dc26 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -1772,6 +1772,11 @@ _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc,
/* Reset ioc variables used for additional query commands */
ioc->reset_from_user = 0;
memset(&ioc->htb_rel, 0, sizeof(struct htb_rel_query));
+ /* a (re)posted trace buffer starts a fresh capture */
+ if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
+ ioc->ring_buffer_sz = 0;
+ ioc->ring_buffer_offset = 0;
+ }
ioc->diag_buffer_status[buffer_type] &=
MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED;
memcpy(ioc->product_specific[buffer_type],
@@ -1791,6 +1796,10 @@ _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc,
if (request_data == NULL) {
ioc->diag_buffer_sz[buffer_type] = 0;
ioc->diag_buffer_dma[buffer_type] = 0;
+ if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
+ ioc->ring_buffer_sz = 0;
+ ioc->ring_buffer_offset = 0;
+ }
request_data = dma_alloc_coherent(&ioc->pdev->dev,
request_data_sz, &request_data_dma, GFP_KERNEL);
if (request_data == NULL) {
@@ -3628,9 +3637,12 @@ host_trace_buffer_size_show(struct device *cdev,
u32 size = 0;
struct DIAG_BUFFER_START *request_data;
+ mutex_lock(&ioc->ctl_cmds.mutex);
+
if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
__func__);
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return 0;
}
@@ -3638,6 +3650,7 @@ host_trace_buffer_size_show(struct device *cdev,
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
__func__);
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return 0;
}
@@ -3649,7 +3662,11 @@ host_trace_buffer_size_show(struct device *cdev,
le32_to_cpu(request_data->Reserved3) == 0x4742444c)
size = le32_to_cpu(request_data->Size);
+ /* Never trust firmware size beyond what was actually allocated */
+ size = min_t(u32, size,
+ ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE]);
ioc->ring_buffer_sz = size;
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return snprintf(buf, PAGE_SIZE, "%d\n", size);
}
static DEVICE_ATTR_RO(host_trace_buffer_size);
@@ -3674,10 +3691,15 @@ host_trace_buffer_show(struct device *cdev, struct device_attribute *attr,
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
void *request_data;
u32 size;
+ u32 offset;
+ u32 buffer_sz;
+
+ mutex_lock(&ioc->ctl_cmds.mutex);
if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
__func__);
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return 0;
}
@@ -3685,16 +3707,24 @@ host_trace_buffer_show(struct device *cdev, struct device_attribute *attr,
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
__func__);
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return 0;
}
- if (ioc->ring_buffer_offset > ioc->ring_buffer_sz)
+ offset = ioc->ring_buffer_offset;
+ /* Never read beyond the actual allocated diag buffer */
+ buffer_sz = min_t(u32, ioc->ring_buffer_sz,
+ ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE]);
+ if (offset > buffer_sz) {
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return 0;
+ }
- size = ioc->ring_buffer_sz - ioc->ring_buffer_offset;
+ size = buffer_sz - offset;
size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size;
- request_data = ioc->diag_buffer[0] + ioc->ring_buffer_offset;
+ request_data = ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE] + offset;
memcpy(buf, request_data, size);
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return size;
}
@@ -3704,12 +3734,14 @@ host_trace_buffer_store(struct device *cdev, struct device_attribute *attr,
{
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- int val = 0;
+ unsigned int val;
- if (sscanf(buf, "%d", &val) != 1)
+ if (kstrtouint(buf, 0, &val))
return -EINVAL;
+ mutex_lock(&ioc->ctl_cmds.mutex);
ioc->ring_buffer_offset = val;
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return strlen(buf);
}
static DEVICE_ATTR_RW(host_trace_buffer);
@@ -3733,16 +3765,24 @@ host_trace_buffer_enable_show(struct device *cdev,
{
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
+ const char *state;
+
+ /* serialize with post/release so a transient state is not reported */
+ if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
+ return -ERESTARTSYS;
if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) ||
((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0))
- return snprintf(buf, PAGE_SIZE, "off\n");
+ state = "off";
else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_RELEASED))
- return snprintf(buf, PAGE_SIZE, "release\n");
+ state = "release";
else
- return snprintf(buf, PAGE_SIZE, "post\n");
+ state = "post";
+
+ mutex_unlock(&ioc->ctl_cmds.mutex);
+ return snprintf(buf, PAGE_SIZE, "%s\n", state);
}
static ssize_t
@@ -3755,13 +3795,17 @@ host_trace_buffer_enable_store(struct device *cdev,
struct mpt3_diag_register diag_register;
u8 issue_reset = 0;
+ if (sscanf(buf, "%9s", str) != 1)
+ return -EINVAL;
+
+ mutex_lock(&ioc->ctl_cmds.mutex);
+
/* don't allow post/release occurr while recovery is active */
if (ioc->shost_recovery || ioc->remove_host ||
- ioc->pci_error_recovery || ioc->is_driver_loading)
+ ioc->pci_error_recovery || ioc->is_driver_loading) {
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return -EBUSY;
-
- if (sscanf(buf, "%9s", str) != 1)
- return -EINVAL;
+ }
if (!strcmp(str, "post")) {
/* exit out if host buffers are already posted */
@@ -3832,6 +3876,7 @@ host_trace_buffer_enable_store(struct device *cdev,
}
out:
+ mutex_unlock(&ioc->ctl_cmds.mutex);
return strlen(buf);
}
static DEVICE_ATTR_RW(host_trace_buffer_enable);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 05/37] scsi: mpt3sas: Fix unlocked use of raid_device in enable_sdev_max_qd_store
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (3 preceding siblings ...)
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 9:56 ` 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
` (31 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Take ioc->raid_device_lock around the raid_device lookup and check
for NULL before dereferencing it.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index ef28da96dc26..d8b1e60af940 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -4263,13 +4263,28 @@ enable_sdev_max_qd_store(struct device *cdev,
if (sas_target_priv_data->flags &
MPT_TARGET_FLAGS_VOLUME) {
+ unsigned long flags;
+ u8 volume_type;
+ u32 device_info;
+
+ spin_lock_irqsave(&ioc->raid_device_lock,
+ flags);
raid_device =
mpt3sas_raid_device_find_by_handle(ioc,
sas_target_priv_data->handle);
+ if (!raid_device) {
+ spin_unlock_irqrestore(
+ &ioc->raid_device_lock, flags);
+ continue;
+ }
+ volume_type = raid_device->volume_type;
+ device_info = raid_device->device_info;
+ spin_unlock_irqrestore(&ioc->raid_device_lock,
+ flags);
- switch (raid_device->volume_type) {
+ switch (volume_type) {
case MPI2_RAID_VOL_TYPE_RAID0:
- if (raid_device->device_info &
+ if (device_info &
MPI2_SAS_DEVICE_INFO_SSP_TARGET)
qdepth =
MPT3SAS_SAS_QUEUE_DEPTH;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 06/37] scsi: mpt3sas: Fix invalid kfree() of fw_event_work event_data
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (4 preceding siblings ...)
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 9:56 ` 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
` (30 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Drop an errant kfree() of fw_event->event_data, a flexible array
member of fw_event_work rather than its own allocation.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index f78fc0faad61..4bc2f7ce4aa2 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -12270,7 +12270,6 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
if (!fw_event->retries) {
ioc_err(ioc, "failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__);
- kfree(fw_event->event_data);
fw_event_work_put(fw_event);
return 1;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 07/37] scsi: mpt3sas: Validate SMP request/response length in bsg handler
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (5 preceding siblings ...)
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 9:56 ` 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
` (29 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Reject SMP requests whose mapped request or response buffer is
smaller than 4 bytes, avoiding a length underflow when building the
SGE.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_transport.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c
index e74a526efa8d..b03422fe86fb 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
@@ -2095,6 +2095,13 @@ _transport_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
if (rc)
goto unmap_out;
+ if (dma_len_out <= 4 || dma_len_in <= 4) {
+ ioc_err(ioc, "%s: SMP request or response too small\n",
+ __func__);
+ rc = -EINVAL;
+ goto unmap_in;
+ }
+
rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
if (rc)
goto unmap_in;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 08/37] scsi: mpt3sas: Validate firmware/user supplied device handles against MaxDevHandle
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (6 preceding siblings ...)
2026-11-18 9:56 ` [PATCH v2 07/37] scsi: mpt3sas: Validate SMP request/response length in bsg handler Shivasharan S
@ 2026-11-18 9:56 ` 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
` (28 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Firmware-supplied (and ioctl-supplied) device handles are used to index
driver bitmaps and look up devices without being checked against
ioc->facts.MaxDevHandle. Add the check in the event, discovery, post-reset
scan (including the physical disk handle) and TM/control completion paths.
MaxDevHandle is an exclusive upper bound, so also change the passthrough
handle check in _ctl_do_mpt_command() from > to >= so handles at the
boundary are rejected.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 2 +-
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 75 ++++++++++++++++++++++++++--
2 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index d8b1e60af940..a0d915678c02 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -787,7 +787,7 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
mpi_request->Function == MPI2_FUNCTION_NVME_ENCAPSULATED) {
device_handle = le16_to_cpu(mpi_request->FunctionDependent1);
- if (!device_handle || (device_handle >
+ if (!device_handle || (device_handle >=
ioc->facts.MaxDevHandle)) {
ret = -EINVAL;
mpt3sas_base_free_smid(ioc, smid);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 4bc2f7ce4aa2..184ed88fab55 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4399,6 +4399,12 @@ _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
u8 tr_method = 0;
struct hba_port *port = NULL;
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ return;
+ }
+
if (ioc->pci_error_recovery) {
dewtprintk(ioc,
ioc_info(ioc, "%s: host in pci error recovery: handle(0x%04x)\n",
@@ -4659,17 +4665,25 @@ _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
{
Mpi2SasIoUnitControlReply_t *mpi_reply =
mpt3sas_base_get_reply_virt_addr(ioc, reply);
+ u16 dev_handle;
if (likely(mpi_reply)) {
+ dev_handle = le16_to_cpu(mpi_reply->DevHandle);
dewtprintk(ioc,
ioc_info(ioc, "sc_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
- le16_to_cpu(mpi_reply->DevHandle), smid,
+ dev_handle, smid,
le16_to_cpu(mpi_reply->IOCStatus),
le32_to_cpu(mpi_reply->IOCLogInfo)));
if (le16_to_cpu(mpi_reply->IOCStatus) ==
MPI2_IOCSTATUS_SUCCESS) {
- clear_bit(le16_to_cpu(mpi_reply->DevHandle),
- ioc->device_remove_in_progress);
+ if (dev_handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc,
+ "handle(0x%04x) out of bounds in %s\n",
+ dev_handle, __func__);
+ } else {
+ clear_bit(dev_handle,
+ ioc->device_remove_in_progress);
+ }
}
} else {
ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
@@ -5220,6 +5234,11 @@ _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
continue;
handle = le16_to_cpu(element->PhysDiskDevHandle);
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ continue;
+ }
volume_handle = le16_to_cpu(element->VolDevHandle);
clear_bit(handle, ioc->pd_handles);
if (!volume_handle)
@@ -8397,6 +8416,13 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
u8 connector_name[5];
u8 port_id;
+ if (handle >= ioc->facts.MaxDevHandle) {
+ /* not retryable: drop the device instead of looping forever */
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ return 0;
+ }
+
if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
ioc_err(ioc, "failure at %s:%d/%s()!\n",
@@ -9184,6 +9210,12 @@ _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
struct MPT3SAS_TARGET *sas_target_priv_data;
u32 device_info;
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ return;
+ }
+
if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
&pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle)))
return;
@@ -10450,6 +10482,12 @@ _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
u64 sas_address;
u16 parent_handle;
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ return;
+ }
+
set_bit(handle, ioc->pd_handles);
sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
@@ -10741,6 +10779,11 @@ _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
return;
handle = le16_to_cpu(event_data->PhysDiskDevHandle);
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ return;
+ }
state = le32_to_cpu(event_data->NewValue);
if (!ioc->hide_ir_msg)
@@ -11104,6 +11147,11 @@ _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
break;
handle = le16_to_cpu(sas_device_pg0.DevHandle);
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ continue;
+ }
device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
if (!(_scsih_is_end_device(device_info)))
continue;
@@ -11224,6 +11272,11 @@ _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc)
break;
}
handle = le16_to_cpu(pcie_device_pg0.DevHandle);
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ continue;
+ }
device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
if (!(_scsih_is_nvme_pciescsi_device(device_info)))
continue;
@@ -11324,6 +11377,11 @@ _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
break;
handle = le16_to_cpu(volume_pg1.DevHandle);
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ continue;
+ }
if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
&volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
@@ -11350,6 +11408,11 @@ _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
break;
phys_disk_num = pd_pg0.PhysDiskNum;
handle = le16_to_cpu(pd_pg0.DevHandle);
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
+ handle, __func__);
+ continue;
+ }
set_bit(handle, ioc->pd_handles);
}
}
@@ -11685,6 +11748,12 @@ _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
}
phys_disk_num = pd_pg0.PhysDiskNum;
handle = le16_to_cpu(pd_pg0.DevHandle);
+ if (handle >= ioc->facts.MaxDevHandle) {
+ ioc_err(ioc,
+ "handle(0x%04x) out of bounds at %s:%d/%s()!\n",
+ handle, __FILE__, __LINE__, __func__);
+ continue;
+ }
sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
if (sas_device) {
sas_device_put(sas_device);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 09/37] scsi: mpt3sas: Clamp topology/IR event entry counts to EventDataLength
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (7 preceding siblings ...)
2026-11-18 9:56 ` [PATCH v2 08/37] scsi: mpt3sas: Validate firmware/user supplied device handles against MaxDevHandle Shivasharan S
@ 2026-11-18 9:56 ` Shivasharan S
2026-11-18 9:56 ` [PATCH v2 10/37] scsi: mpt3sas: NULL ioc->reply_post after freeing it Shivasharan S
` (27 subsequent siblings)
36 siblings, 0 replies; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Clamp NumEntries/NumElements in SAS/PCIe topology and IR config
change events to what EventDataLength actually covers.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 72 +++++++++++++++++++++++++---
1 file changed, 65 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 184ed88fab55..b6ab2c755e56 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -12170,7 +12170,7 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
struct fw_event_work *fw_event;
Mpi2EventNotificationReply_t *mpi_reply;
u16 event;
- u16 sz;
+ u32 sz, max_dwords;
Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
/* events turned off due to host reset */
@@ -12190,6 +12190,28 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
mpt3sas_trigger_event(ioc, event, 0);
+ /*
+ * Ensure EventDataLength does not exceed the maximum allocated reply size
+ */
+ max_dwords = 0;
+ if (ioc->reply_sz > offsetof(Mpi2EventNotificationReply_t, EventData))
+ max_dwords = (ioc->reply_sz -
+ offsetof(Mpi2EventNotificationReply_t, EventData)) / 4;
+ if (le16_to_cpu(mpi_reply->EventDataLength) > max_dwords)
+ mpi_reply->EventDataLength = cpu_to_le16(max_dwords);
+ sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
+
+ /*
+ * reject events too short to contain the header.
+ */
+ if ((event == MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST &&
+ sz < offsetof(Mpi2EventDataSasTopologyChangeList_t, PHY)) ||
+ (event == MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST &&
+ sz < offsetof(Mpi26EventDataPCIeTopologyChangeList_t, PortEntry)) ||
+ (event == MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST &&
+ sz < offsetof(Mpi2EventDataIrConfigChangeList_t, ConfigElement)))
+ return 1;
+
switch (event) {
/* handle these */
case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
@@ -12211,9 +12233,20 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
}
case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
- _scsih_check_topo_delete_events(ioc,
+ {
+ Mpi2EventDataSasTopologyChangeList_t *topo_data =
(Mpi2EventDataSasTopologyChangeList_t *)
- mpi_reply->EventData);
+ mpi_reply->EventData;
+ u32 data_len = sz;
+ size_t hdr_size =
+ offsetof(Mpi2EventDataSasTopologyChangeList_t, PHY);
+ u16 max_entries;
+
+ max_entries = (data_len - hdr_size) /
+ sizeof(Mpi2EventSasTopoPhyEntry_t);
+ if (topo_data->NumEntries > max_entries)
+ topo_data->NumEntries = max_entries;
+ _scsih_check_topo_delete_events(ioc, topo_data);
/*
* No need to add the topology change list
* event to fw event work queue when
@@ -12225,18 +12258,43 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
if (ioc->shost_recovery)
return 1;
break;
+ }
case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
- _scsih_check_pcie_topo_remove_events(ioc,
+ {
+ Mpi26EventDataPCIeTopologyChangeList_t *pcie_topo_data =
(Mpi26EventDataPCIeTopologyChangeList_t *)
- mpi_reply->EventData);
+ mpi_reply->EventData;
+ u32 data_len = sz;
+ size_t hdr_size =
+ offsetof(Mpi26EventDataPCIeTopologyChangeList_t, PortEntry);
+ u16 max_entries;
+
+ max_entries = (data_len - hdr_size) /
+ sizeof(MPI26_EVENT_PCIE_TOPO_PORT_ENTRY);
+ if (pcie_topo_data->NumEntries > max_entries)
+ pcie_topo_data->NumEntries = max_entries;
+ _scsih_check_pcie_topo_remove_events(ioc, pcie_topo_data);
if (ioc->shost_recovery)
return 1;
break;
+ }
case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
- _scsih_check_ir_config_unhide_events(ioc,
+ {
+ Mpi2EventDataIrConfigChangeList_t *ir_config_data =
(Mpi2EventDataIrConfigChangeList_t *)
- mpi_reply->EventData);
+ mpi_reply->EventData;
+ u32 data_len = sz;
+ size_t hdr_size =
+ offsetof(Mpi2EventDataIrConfigChangeList_t, ConfigElement);
+ u16 max_elements;
+
+ max_elements = (data_len - hdr_size) /
+ sizeof(MPI2_EVENT_IR_CONFIG_ELEMENT);
+ if (ir_config_data->NumElements > max_elements)
+ ir_config_data->NumElements = max_elements;
+ _scsih_check_ir_config_unhide_events(ioc, ir_config_data);
break;
+ }
case MPI2_EVENT_IR_VOLUME:
_scsih_check_volume_delete_events(ioc,
(Mpi2EventDataIrVolume_t *)
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 10/37] scsi: mpt3sas: NULL ioc->reply_post after freeing it
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (8 preceding siblings ...)
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 ` 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
` (26 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Match the pattern used for other pool pointers in
_base_release_memory_pools() so a repeat call can't reuse it.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index aea300f55051..5a51844608aa 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -5869,6 +5869,7 @@ _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc)
}
dma_pool_destroy(ioc->reply_post_free_array_dma_pool);
kfree(ioc->reply_post);
+ ioc->reply_post = NULL;
}
if (ioc->pcie_sgl_dma_pool) {
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 11/37] scsi: mpt3sas: Fix port_table memory leak in _scsih_sas_port_refresh
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (9 preceding siblings ...)
2026-11-18 9:56 ` [PATCH v2 10/37] scsi: mpt3sas: NULL ioc->reply_post after freeing it Shivasharan S
@ 2026-11-18 9:56 ` 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
` (25 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Free port_table on every exit path, including the early return when
no ports are found.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index b6ab2c755e56..746b3f2f241c 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -6783,7 +6783,7 @@ _scsih_sas_port_refresh(struct MPT3SAS_ADAPTER *ioc)
port_count = _scsih_get_port_table_after_reset(ioc, port_table);
if (!port_count)
- return;
+ goto out;
drsprintk(ioc, ioc_info(ioc, "New Port table\n"));
for (j = 0; j < port_count; j++)
@@ -6846,6 +6846,8 @@ _scsih_sas_port_refresh(struct MPT3SAS_ADAPTER *ioc)
}
port_table_entry = NULL;
+out:
+ kfree(port_table);
}
/**
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 12/37] scsi: mpt3sas: Fix leak and dangling pointer for io_uring_poll_queues
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (10 preceding siblings ...)
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 9:56 ` 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
` (24 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Free ioc->io_uring_poll_queues on the legacy-IRQ fallback path and
NULL it after freeing.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 5a51844608aa..bd169e3f18fa 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -3362,6 +3362,7 @@ mpt3sas_base_disable_msix(struct MPT3SAS_ADAPTER *ioc)
pci_free_irq_vectors(ioc->pdev);
ioc->msix_enable = 0;
kfree(ioc->io_uring_poll_queues);
+ ioc->io_uring_poll_queues = NULL;
}
/**
@@ -3541,6 +3542,8 @@ _base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
/* failback to io_apic interrupt routing */
try_ioapic:
+ kfree(ioc->io_uring_poll_queues);
+ ioc->io_uring_poll_queues = NULL;
ioc->high_iops_queues = 0;
ioc_info(ioc, "High IOPs queues : disabled\n");
ioc->reply_queue_count = 1;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 13/37] scsi: mpt3sas: Validate max_data_size in MPT3EVENTREPORT ioctl
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (11 preceding siblings ...)
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 9:56 ` 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
` (23 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Reject a max_data_size smaller than the ioctl header size before
using it in size arithmetic.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index a0d915678c02..5db233d21f01 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -1367,6 +1367,9 @@ _ctl_eventreport(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
__func__));
+ if (karg.hdr.max_data_size < sizeof(struct mpt3_ioctl_header))
+ return -EINVAL;
+
number_bytes = karg.hdr.max_data_size -
sizeof(struct mpt3_ioctl_header);
max_events = number_bytes/sizeof(struct MPT3_IOCTL_EVENTS);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 14/37] scsi: mpt3sas: Fix buffer overflow in _scsih_scsi_ioc_info
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (12 preceding siblings ...)
2026-11-18 9:56 ` [PATCH v2 13/37] scsi: mpt3sas: Validate max_data_size in MPT3EVENTREPORT ioctl Shivasharan S
@ 2026-11-18 9:56 ` 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
` (22 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Build the SCSIState description string with a bounds-checked
snprintf() instead of a chain of unbounded strcat()s.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.h | 2 +-
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 23 ++++++++++++-----------
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 47255bf9cdda..3c5d6803e56e 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -136,7 +136,7 @@
#define MPT3SAS_HOST_PAGE_SIZE_4K 12
#define MPT3SAS_NVME_QUEUE_DEPTH 128
#define MPT_NAME_LENGTH 32 /* generic length of strings */
-#define MPT_STRING_LENGTH 64
+#define MPT_STRING_LENGTH 80
#define MPI_FRAME_START_OFFSET 256
#define REPLY_FREE_POOL_SIZE 512 /*(32 maxcredix *4)*(4 times)*/
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 746b3f2f241c..656241678899 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -5777,19 +5777,20 @@ _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
break;
}
- desc_scsi_state[0] = '\0';
if (!scsi_state)
desc_scsi_state = " ";
- if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
- strcat(desc_scsi_state, "response info ");
- if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
- strcat(desc_scsi_state, "state terminated ");
- if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
- strcat(desc_scsi_state, "no status ");
- if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
- strcat(desc_scsi_state, "autosense failed ");
- if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
- strcat(desc_scsi_state, "autosense valid ");
+ else
+ snprintf(desc_scsi_state, MPT_STRING_LENGTH, "%s%s%s%s%s",
+ (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) ?
+ "response info " : "",
+ (scsi_state & MPI2_SCSI_STATE_TERMINATED) ?
+ "state terminated " : "",
+ (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) ?
+ "no status " : "",
+ (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) ?
+ "autosense failed " : "",
+ (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) ?
+ "autosense valid " : "");
scsi_print_command(scmd);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 15/37] scsi: mpt3sas: Fix Scsi_Host leak on invalid/tampered device probe
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (13 preceding siblings ...)
2026-11-18 9:56 ` [PATCH v2 14/37] scsi: mpt3sas: Fix buffer overflow in _scsih_scsi_ioc_info Shivasharan S
@ 2026-11-18 9:56 ` 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
` (21 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Release the Scsi_Host before returning on the invalid/tampered
device-ID paths in _scsih_probe().
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 656241678899..0b219fe87a0b 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -13569,6 +13569,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
"HBA with DeviceId 0x%04x, sub VendorId 0x%04x, sub DeviceId 0x%04x is Invalid",
pdev->device, pdev->subsystem_vendor,
pdev->subsystem_device);
+ scsi_host_put(shost);
return 1;
case MPI26_MFGPAGE_DEVID_INVALID1_3816:
case MPI26_MFGPAGE_DEVID_INVALID1_3916:
@@ -13576,6 +13577,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
"HBA with DeviceId 0x%04x, sub VendorId 0x%04x, sub DeviceId 0x%04x is Tampered",
pdev->device, pdev->subsystem_vendor,
pdev->subsystem_device);
+ scsi_host_put(shost);
return 1;
case MPI26_MFGPAGE_DEVID_CFG_SEC_3816:
case MPI26_MFGPAGE_DEVID_CFG_SEC_3916:
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 16/37] scsi: mpt3sas: Fix page fault from stale ioc->chip after PCI error recovery
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (14 preceding siblings ...)
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 9:56 ` 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
` (20 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
NULL ioc->chip after unmapping it and guard mask/unmask_interrupts()
against a NULL chip pointer.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 27 +++++++++++++++++++++++++--
drivers/scsi/mpt3sas/mpt3sas_config.c | 4 ++++
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 8 ++++++++
3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index bd169e3f18fa..995228da8f77 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -1645,6 +1645,8 @@ mpt3sas_base_mask_interrupts(struct MPT3SAS_ADAPTER *ioc)
u32 him_register;
ioc->mask_interrupts = 1;
+ if (!ioc->chip)
+ return;
him_register = ioc->base_readl(&ioc->chip->HostInterruptMask);
him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
writel(him_register, &ioc->chip->HostInterruptMask);
@@ -1662,6 +1664,8 @@ mpt3sas_base_unmask_interrupts(struct MPT3SAS_ADAPTER *ioc)
{
u32 him_register;
+ if (!ioc->chip)
+ return;
him_register = ioc->base_readl(&ioc->chip->HostInterruptMask);
him_register &= ~MPI2_HIM_RIM;
writel(him_register, &ioc->chip->HostInterruptMask);
@@ -3579,6 +3583,7 @@ mpt3sas_base_unmap_resources(struct MPT3SAS_ADAPTER *ioc)
if (ioc->chip_phys) {
iounmap(ioc->chip);
+ ioc->chip = NULL;
ioc->chip_phys = 0;
}
@@ -3682,9 +3687,11 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc)
} else if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
if (memap_sz)
continue;
+ memap_sz = pci_resource_len(pdev, i);
+ if (!memap_sz)
+ continue;
ioc->chip_phys = pci_resource_start(pdev, i);
chip_phys = ioc->chip_phys;
- memap_sz = pci_resource_len(pdev, i);
ioc->chip = ioremap(ioc->chip_phys, memap_sz);
}
}
@@ -6740,6 +6747,15 @@ mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER *ioc, int cooked)
{
u32 s, sc;
+ /*
+ * Registers are unmapped (e.g. after PCI error recovery/suspend).
+ * Return a state value that matches no real IOC state, so callers
+ * neither treat the IOC as FAULT (and try a register-based diag
+ * reset) nor as READY/OPERATIONAL.
+ */
+ if (!ioc->chip)
+ return MPI2_IOC_STATE_MASK;
+
s = ioc->base_readl_ext_retry(&ioc->chip->Doorbell);
sc = s & MPI2_IOC_STATE_MASK;
return cooked ? sc : s;
@@ -8137,7 +8153,7 @@ mpt3sas_base_make_ioc_ready(struct MPT3SAS_ADAPTER *ioc, enum reset_type type)
dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__));
- if (ioc->pci_error_recovery)
+ if (ioc->pci_error_recovery || !ioc->chip)
return 0;
ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
@@ -8970,6 +8986,13 @@ mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER *ioc,
goto out_unlocked;
}
+ if (!ioc->chip) {
+ ioc_err(ioc, "%s: controller registers are not mapped\n",
+ __func__);
+ r = -ENODEV;
+ goto out_unlocked;
+ }
+
if (mpt3sas_fwfault_debug)
mpt3sas_halt_firmware(ioc);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c
index eb51ce3610c8..2609b298af0b 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_config.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_config.c
@@ -304,6 +304,10 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
struct config_request mem;
u32 ioc_status = UINT_MAX;
+ /* registers are unmapped (e.g. after PCI error recovery/suspend) */
+ if (!ioc->chip)
+ return -ENODEV;
+
mutex_lock(&ioc->config_cmds.mutex);
if (ioc->config_cmds.status != MPT3_CMD_NOT_USED) {
ioc_err(ioc, "%s: config_cmd in use\n", __func__);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 0b219fe87a0b..2355080f5f97 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -12497,6 +12497,10 @@ _scsih_nvme_shutdown(struct MPT3SAS_ADAPTER *ioc)
Mpi26IoUnitControlReply_t *mpi_reply;
u16 smid;
+ /* controller registers unmapped, can't post requests */
+ if (!ioc->chip)
+ return;
+
/* are there any NVMe devices ? */
if (list_empty(&ioc->pcie_device_list))
return;
@@ -12565,6 +12569,10 @@ _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
Mpi2RaidActionReply_t *mpi_reply;
u16 smid;
+ /* controller registers unmapped, can't post requests */
+ if (!ioc->chip)
+ return;
+
/* is IR firmware build loaded ? */
if (!ioc->ir_firmware)
return;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 17/37] scsi: mpt3sas: Clamp ValidEntries in driver trigger page update helpers
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (15 preceding siblings ...)
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 9:56 ` 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
` (19 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Clamp ValidEntries to NUM_VALID_ENTRIES in the pg2/pg3/pg4 trigger
update helpers before it's used as a copy count.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_config.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c
index 2609b298af0b..ff58a5329074 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_config.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_config.c
@@ -2281,7 +2281,7 @@ mpt3sas_config_update_driver_trigger_pg2(struct MPT3SAS_ADAPTER *ioc,
}
if (set) {
- count = event_tg->ValidEntries;
+ count = min_t(u32, event_tg->ValidEntries, NUM_VALID_ENTRIES);
tg_pg2.NumMPIEventTrigger = cpu_to_le16(count);
for (i = 0; i < count; i++) {
tg_pg2.MPIEventTriggers[i].MPIEventCode =
@@ -2440,7 +2440,7 @@ mpt3sas_config_update_driver_trigger_pg3(struct MPT3SAS_ADAPTER *ioc,
}
if (set) {
- count = scsi_tg->ValidEntries;
+ count = min_t(u32, scsi_tg->ValidEntries, NUM_VALID_ENTRIES);
tg_pg3.NumSCSISenseTrigger = cpu_to_le16(count);
for (i = 0; i < count; i++) {
tg_pg3.SCSISenseTriggers[i].ASCQ =
@@ -2598,7 +2598,7 @@ mpt3sas_config_update_driver_trigger_pg4(struct MPT3SAS_ADAPTER *ioc,
}
if (set) {
- count = mpi_tg->ValidEntries;
+ count = min_t(u32, mpi_tg->ValidEntries, NUM_VALID_ENTRIES);
tg_pg4.NumIOCStatusLogInfoTrigger = cpu_to_le16(count);
for (i = 0; i < count; i++) {
tg_pg4.IOCStatusLoginfoTriggers[i].IOCStatus =
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 18/37] scsi: mpt3sas: Clamp firmware reply copies to the allocated reply buffer
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (16 preceding siblings ...)
2026-11-18 9:56 ` [PATCH v2 17/37] scsi: mpt3sas: Clamp ValidEntries in driver trigger page update helpers Shivasharan S
@ 2026-11-18 9:56 ` 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
` (18 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Clamp MsgLength-based memcpy()s of firmware replies to ioc->reply_sz
across the driver's completion handlers.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 6 ++++--
drivers/scsi/mpt3sas/mpt3sas_config.c | 2 +-
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 3 ++-
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 5 +++--
drivers/scsi/mpt3sas/mpt3sas_transport.c | 2 +-
5 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 995228da8f77..dca07b97dfb4 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -1459,7 +1459,8 @@ mpt3sas_base_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
ioc->base_cmds.status |= MPT3_CMD_COMPLETE;
if (mpi_reply) {
ioc->base_cmds.status |= MPT3_CMD_REPLY_VALID;
- memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
+ memcpy(ioc->base_cmds.reply, mpi_reply,
+ min_t(u32, mpi_reply->MsgLength * 4, ioc->reply_sz));
}
ioc->base_cmds.status &= ~MPT3_CMD_PENDING;
@@ -7689,7 +7690,8 @@ mpt3sas_port_enable_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
ioc->port_enable_cmds.status &= ~MPT3_CMD_PENDING;
ioc->port_enable_cmds.status |= MPT3_CMD_COMPLETE;
ioc->port_enable_cmds.status |= MPT3_CMD_REPLY_VALID;
- memcpy(ioc->port_enable_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
+ memcpy(ioc->port_enable_cmds.reply, mpi_reply,
+ min_t(u32, mpi_reply->MsgLength * 4, ioc->reply_sz));
ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
ioc->port_enable_failed = 1;
diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c
index ff58a5329074..88dba4598d70 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_config.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_config.c
@@ -263,7 +263,7 @@ mpt3sas_config_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
if (mpi_reply) {
ioc->config_cmds.status |= MPT3_CMD_REPLY_VALID;
memcpy(ioc->config_cmds.reply, mpi_reply,
- mpi_reply->MsgLength*4);
+ min_t(u32, mpi_reply->MsgLength * 4, ioc->reply_sz));
}
ioc->config_cmds.status &= ~MPT3_CMD_PENDING;
if (ioc->logging_level & MPT_DEBUG_CONFIG)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 5db233d21f01..7c5db14645ca 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -274,7 +274,8 @@ mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
ioc->ctl_cmds.status |= MPT3_CMD_COMPLETE;
mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
if (mpi_reply) {
- memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
+ memcpy(ioc->ctl_cmds.reply, mpi_reply,
+ min_t(u32, mpi_reply->MsgLength * 4, ioc->reply_sz));
ioc->ctl_cmds.status |= MPT3_CMD_REPLY_VALID;
/* get sense data */
if (mpi_reply->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 2355080f5f97..a25e2aed266b 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -2941,7 +2941,8 @@ _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
if (mpi_reply) {
- memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
+ memcpy(ioc->tm_cmds.reply, mpi_reply,
+ min_t(u32, mpi_reply->MsgLength * 4, ioc->reply_sz));
ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
}
ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
@@ -7433,7 +7434,7 @@ _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
if (mpi_reply) {
memcpy(ioc->scsih_cmds.reply, mpi_reply,
- mpi_reply->MsgLength*4);
+ min_t(u32, mpi_reply->MsgLength * 4, ioc->reply_sz));
ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
}
ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c
index b03422fe86fb..e88205b69067 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
@@ -305,7 +305,7 @@ mpt3sas_transport_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
ioc->transport_cmds.status |= MPT3_CMD_COMPLETE;
if (mpi_reply) {
memcpy(ioc->transport_cmds.reply, mpi_reply,
- mpi_reply->MsgLength*4);
+ min_t(u32, mpi_reply->MsgLength * 4, ioc->reply_sz));
ioc->transport_cmds.status |= MPT3_CMD_REPLY_VALID;
}
ioc->transport_cmds.status &= ~MPT3_CMD_PENDING;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 19/37] scsi: mpt3sas: Reject implausibly small MaxReplyDescriptorPostQueueDepth
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (17 preceding siblings ...)
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 9:56 ` 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
` (17 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Avoid an unsigned underflow in the hba_queue_depth calculation when
firmware reports a too-small queue depth.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 18 ++++++++++++++++++
drivers/scsi/mpt3sas/mpt3sas_base.h | 9 +++++++++
2 files changed, 27 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index dca07b97dfb4..07af8542fbc7 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -6453,6 +6453,13 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
(ioc->reply_post_queue_depth % 16);
}
+ if (facts->MaxReplyDescriptorPostQueueDepth <
+ MPT3SAS_MIN_REPLY_POST_QUEUE_DEPTH) {
+ ioc_err(ioc, "MaxReplyDescriptorPostQueueDepth is too small (%u)\n",
+ facts->MaxReplyDescriptorPostQueueDepth);
+ return -EINVAL;
+ }
+
if (ioc->reply_post_queue_depth >
facts->MaxReplyDescriptorPostQueueDepth) {
ioc->reply_post_queue_depth =
@@ -6463,6 +6470,17 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64;
}
+ /*
+ * Ensure that scsiio_depth and can_queue cannot underflow
+ * after the clamp above.
+ */
+ if (ioc->hba_queue_depth <= ioc->hi_priority_depth +
+ ioc->internal_depth + INTERNAL_SCSIIO_CMDS_COUNT) {
+ ioc_err(ioc, "hba_queue_depth(%u) is too small for the reserved command depths\n",
+ ioc->hba_queue_depth);
+ return -EINVAL;
+ }
+
ioc_info(ioc,
"scatter gather: sge_in_main_msg(%d), sge_per_chain(%d), "
"sge_per_io(%d), chains_per_io(%d)\n",
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 3c5d6803e56e..43586baf049c 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -145,6 +145,15 @@
#define MPT_MAX_HBA_NUM_PHYS 32
#define INTERNAL_CMDS_COUNT 10 /* reserved cmds */
+
+/*
+ * Minimum reply post queue depth for hba_queue_depth to stay non-negative.
+ * Values 66-79 floor to 64 after 16-alignment, making ((64-64)/2)-1 = -1
+ * which wraps to 65535 as u16. The smallest value whose aligned floor exceeds
+ * 64 is 80 (80 % 16 == 0, giving ((80-64)/2)-1 == 7).
+ */
+#define MPT3SAS_MIN_REPLY_POST_QUEUE_DEPTH 80
+
/* reserved for issuing internally framed scsi io cmds */
#define INTERNAL_SCSIIO_CMDS_COUNT 3
#define INTERNAL_SCSIIO_FOR_DISCOVERY 2
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 20/37] scsi: mpt3sas: Validate CurrentHostPageSize before using it as a shift amount
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (18 preceding siblings ...)
2026-11-18 9:56 ` [PATCH v2 19/37] scsi: mpt3sas: Reject implausibly small MaxReplyDescriptorPostQueueDepth Shivasharan S
@ 2026-11-18 9:56 ` 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
` (16 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Reject an out-of-range CurrentHostPageSize instead of using it
directly as a shift amount.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 14 +++++++++++---
drivers/scsi/mpt3sas/mpt3sas_base.h | 1 +
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 07af8542fbc7..0b4b8aad2162 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -7553,12 +7553,20 @@ _base_get_ioc_facts(struct MPT3SAS_ADAPTER *ioc)
facts->CurrentHostPageSize = mpi_reply.CurrentHostPageSize;
/*
- * Get the Page Size from IOC Facts. If it's 0, default to 4k.
+ * Get the Page Size from IOC Facts. If it's 0, or outside the range
+ * of page sizes (4k..64k) the driver can safely handle, default to 4k.
*/
- ioc->page_size = 1 << facts->CurrentHostPageSize;
+ if (facts->CurrentHostPageSize != 0 &&
+ (facts->CurrentHostPageSize < MPT3SAS_HOST_PAGE_SIZE_4K ||
+ facts->CurrentHostPageSize > MPT3SAS_HOST_PAGE_SIZE_64K)) {
+ ioc_warn(ioc, "CurrentHostPageSize(%d) is invalid: Setting default host page size to 4k\n",
+ facts->CurrentHostPageSize);
+ facts->CurrentHostPageSize = MPT3SAS_HOST_PAGE_SIZE_4K;
+ }
+ ioc->page_size = 1U << facts->CurrentHostPageSize;
if (ioc->page_size == 1) {
ioc_info(ioc, "CurrentHostPageSize is 0: Setting default host page size to 4k\n");
- ioc->page_size = 1 << MPT3SAS_HOST_PAGE_SIZE_4K;
+ ioc->page_size = 1U << MPT3SAS_HOST_PAGE_SIZE_4K;
}
dinitprintk(ioc,
ioc_info(ioc, "CurrentHostPageSize(%d)\n",
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 43586baf049c..6fb511530637 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -134,6 +134,7 @@
#define MPT3SAS_RAID_MAX_SECTORS 8192
#define MPT3SAS_HOST_PAGE_SIZE_4K 12
+#define MPT3SAS_HOST_PAGE_SIZE_64K 16
#define MPT3SAS_NVME_QUEUE_DEPTH 128
#define MPT_NAME_LENGTH 32 /* generic length of strings */
#define MPT_STRING_LENGTH 80
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 21/37] scsi: mpt3sas: Clamp sense_length before copying into transfer_packet->sense
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (19 preceding siblings ...)
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 9:56 ` 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
` (15 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Clamp the firmware-reported SenseCount to sizeof(sense) before the
copy.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index a25e2aed266b..8bafb8ea70a8 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -7579,7 +7579,8 @@ _scsi_send_scsi_io(struct MPT3SAS_ADAPTER *ioc, struct _scsi_io_transfer
transfer_packet->valid_reply = 1;
mpi_reply = ioc->scsih_cmds.reply;
transfer_packet->sense_length =
- le32_to_cpu(mpi_reply->SenseCount);
+ min_t(u32, le32_to_cpu(mpi_reply->SenseCount),
+ sizeof(transfer_packet->sense));
if (transfer_packet->sense_length)
memcpy(transfer_packet->sense, priv_sense,
transfer_packet->sense_length);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 22/37] scsi: mpt3sas: Clamp num_luns in _scsih_wait_for_target_to_become_ready
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (20 preceding siblings ...)
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 9:56 ` 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
` (14 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Clamp num_luns to the lun_data allocation size before using it as a
loop bound.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 8bafb8ea70a8..64de88183f8d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -8187,6 +8187,8 @@ _scsih_wait_for_target_to_become_ready(struct MPT3SAS_ADAPTER *ioc, u16 handle,
(data[2] << 8) | (data[3] << 0));
num_luns = (length / sizeof(struct scsi_lun));
+ /* Clamp to last valid index: loop uses inclusive bound lun_data[num_luns] */
+ num_luns = min_t(u32, num_luns, MPT3_MAX_LUNS - 1);
lunp = &lun_data[1];
lun = (num_luns) ? mpt_scsilun_to_int(&lun_data[1]) : 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 23/37] scsi: mpt3sas: Validate phy_number in mpt3sas_transport_update_links
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (21 preceding siblings ...)
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 9:56 ` 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
` (13 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Check phy_number against sas_node->num_phys before indexing the phy
array.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_transport.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c
index e88205b69067..5f087d0b4d7a 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
@@ -1176,6 +1176,11 @@ mpt3sas_transport_update_links(struct MPT3SAS_ADAPTER *ioc,
return;
}
+ if (phy_number >= sas_node->num_phys) {
+ spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
+ return;
+ }
+
mpt3sas_phy = &sas_node->phy[phy_number];
mpt3sas_phy->attached_handle = handle;
spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 24/37] scsi: mpt3sas: Require CAP_SYS_RAWIO for mpt2ctl/mpt3ctl ioctls
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (22 preceding siblings ...)
2026-11-18 9:56 ` [PATCH v2 23/37] scsi: mpt3sas: Validate phy_number in mpt3sas_transport_update_links Shivasharan S
@ 2026-11-18 9:56 ` 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
` (12 subsequent siblings)
36 siblings, 0 replies; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Gate the ioctl entry point on CAP_SYS_RAWIO rather than relying only
on device node permissions.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 7c5db14645ca..f97967235367 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -56,6 +56,7 @@
#include <linux/io.h>
#include <linux/uaccess.h>
+#include <linux/capability.h>
#include "mpt3sas_base.h"
#include "mpt3sas_ctl.h"
@@ -2739,6 +2740,9 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
enum block_state state;
long ret = -ENOIOCTLCMD;
+ if (!capable(CAP_SYS_RAWIO))
+ return -EPERM;
+
/* get IOCTL header */
if (copy_from_user(&ioctl_header, (char __user *)arg,
sizeof(struct mpt3_ioctl_header))) {
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 25/37] scsi: mpt3sas: Fix SGE offset boundary check in _ctl_do_mpt_command
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (23 preceding siblings ...)
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 ` 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
` (11 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Ensure data_sge_offset leaves room for two SGE entries within the request
frame by checking that data_sge_offset * 4 does not exceed request_sz - 32.
Reorder the overflow guard before the multiplication to prevent wraparound.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index f97967235367..d3166e048991 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -714,6 +714,7 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
unsigned long timeout;
u8 issue_reset;
u32 sz, sz_arg;
+ u32 sge_cnt;
void *psge;
void *data_out = NULL;
dma_addr_t data_out_dma = 0;
@@ -746,8 +747,9 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
}
/* Check for overflow and wraparound */
- if (karg.data_sge_offset * 4 > ioc->request_sz ||
- karg.data_sge_offset > (UINT_MAX / 4)) {
+ if (karg.data_sge_offset > (UINT_MAX / 4) ||
+ karg.data_sge_offset * 4 >
+ ioc->request_sz - max_t(u32, ioc->sge_size, ioc->sge_size_ieee)) {
ret = -EINVAL;
goto out;
}
@@ -782,6 +784,23 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
data_out_sz = karg.data_out_size;
data_in_sz = karg.data_in_size;
+ /*
+ * SGEs follow the request header and must stay inside the frame.
+ * MCTP, mem-move and bidirectional data need two, others need one.
+ */
+ sge_cnt = (data_out_sz && data_in_sz) ? 2 : 1;
+ if (mpi_request->Function == MPI2_FUNCTION_MCTP_PASSTHROUGH ||
+ (mpi_request->Function == MPI2_FUNCTION_TOOLBOX &&
+ ((Mpi2ToolboxCleanRequest_t *)mpi_request)->Tool ==
+ MPI2_TOOLBOX_MEMORY_MOVE_TOOL))
+ sge_cnt = 2;
+ if (karg.data_sge_offset * 4 + sge_cnt *
+ max_t(u32, ioc->sge_size, ioc->sge_size_ieee) > ioc->request_sz) {
+ mpt3sas_base_free_smid(ioc, smid);
+ ret = -EINVAL;
+ goto out;
+ }
+
if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT ||
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 26/37] scsi: mpt3sas: Enforce minimum reply frame size and validate chain segment size
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (24 preceding siblings ...)
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 9:56 ` Shivasharan S
2026-11-18 10:46 ` sashiko-bot
2026-11-18 9:56 ` [PATCH v2 27/37] scsi: mpt3sas: Replace panic() with error return in hard_reset_handler Shivasharan S
` (10 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
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.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 49 ++++++++++++++++++++++++-----
1 file changed, 42 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 0b4b8aad2162..7e5f5576fc5e 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -6396,21 +6396,49 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
/* reply frame size */
ioc->reply_sz = facts->ReplyFrameSize * 4;
+ /*
+ * Enforce minimum reply frame size: the driver casts reply buffers to
+ * the largest reply type (SCSI IO reply), so it must fit.
+ */
+ if (ioc->reply_sz < sizeof(Mpi2SCSIIOReply_t)) {
+ ioc_err(ioc,
+ "Firmware reported an invalid ReplyFrameSize (%d bytes). Cannot safely attach.\n",
+ ioc->reply_sz);
+ return -EINVAL;
+ }
+
+ /* calculate the max scatter element size */
+ sge_size = max_t(u16, ioc->sge_size, ioc->sge_size_ieee);
+
/* chain segment size */
if (ioc->hba_mpi_version_belonged != MPI2_VERSION) {
- if (facts->IOCMaxChainSegmentSize)
- ioc->chain_segment_sz =
- facts->IOCMaxChainSegmentSize *
+ if (facts->IOCMaxChainSegmentSize) {
+ /* compute in 32 bits so the product cannot wrap the u16 field */
+ u32 chain_sz = (u32)facts->IOCMaxChainSegmentSize *
MAX_CHAIN_ELEMT_SZ;
- else
- /* set to 128 bytes size if IOCMaxChainSegmentSize is zero */
+
+ /* reject values that wrap or leave < 2 SGEs per chain */
+ if (chain_sz < 2 * sge_size || chain_sz > 0xFFFF) {
+ ioc_err(ioc,
+ "IOCMaxChainSegmentSize (%u) is out of range, cannot safely attach\n",
+ facts->IOCMaxChainSegmentSize);
+ return -EINVAL;
+ }
+ ioc->chain_segment_sz = chain_sz;
+ } else
+ /* set to 128 bytes size if IOCMaxChainSegmentSize is zero */
ioc->chain_segment_sz = DEFAULT_NUM_FWCHAIN_ELEMTS *
MAX_CHAIN_ELEMT_SZ;
} else
ioc->chain_segment_sz = ioc->request_sz;
- /* calculate the max scatter element size */
- sge_size = max_t(u16, ioc->sge_size, ioc->sge_size_ieee);
+ /* every branch above must yield a usable chain segment size */
+ if (ioc->chain_segment_sz < 2 * sge_size) {
+ ioc_err(ioc,
+ "invalid chain segment size (%u), cannot safely attach\n",
+ ioc->chain_segment_sz);
+ return -EINVAL;
+ }
retry_allocation:
total_sz = 0;
@@ -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;
+ }
/*
* MPT3SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 27/37] scsi: mpt3sas: Replace panic() with error return in hard_reset_handler
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (25 preceding siblings ...)
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 9:56 ` Shivasharan S
2026-11-18 9:56 ` [PATCH v2 28/37] scsi: mpt3sas: Replace panic() calls with error returns in _config_request Shivasharan S
` (9 subsequent siblings)
36 siblings, 0 replies; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
When rdpq_array_capable is cleared after a firmware flash, replace the
panic() call with an ioc_err() log and a graceful -EFAULT return.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 7e5f5576fc5e..c973b6b02733 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -9108,10 +9108,13 @@ mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER *ioc,
" image and it requires system reboot\n");
goto out;
}
- if (ioc->rdpq_array_enable && !ioc->rdpq_array_capable)
- panic("%s: Issue occurred with flashing controller firmware."
- "Please reboot the system and ensure that the correct"
- " firmware version is running\n", ioc->name);
+ if (ioc->rdpq_array_enable && !ioc->rdpq_array_capable) {
+ ioc_err(ioc,
+ "%s: Issue occurred with flashing controller firmware. Please reboot the system and ensure that the correct firmware version is running\n",
+ __func__);
+ r = -EFAULT;
+ goto out;
+ }
r = _base_make_ioc_operational(ioc);
if (!r)
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 28/37] scsi: mpt3sas: Replace panic() calls with error returns in _config_request
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (26 preceding siblings ...)
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 ` Shivasharan S
2026-11-18 9:56 ` [PATCH v2 29/37] scsi: mpt3sas: Bound event-log copy size against reply frame size Shivasharan S
` (8 subsequent siblings)
36 siblings, 0 replies; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Replace the four panic() calls triggered by firmware page-type mismatches
with ioc_err() messages and -EIO returns via goto free_mem.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_config.c | 66 ++++++++++++++++++---------
1 file changed, 45 insertions(+), 21 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c
index 88dba4598d70..83757358015d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_config.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_config.c
@@ -420,10 +420,13 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
smid, "config_request", NULL);
_debug_dump_mf(mpi_request, ioc->request_sz/4);
_debug_dump_reply(mpi_reply, ioc->reply_sz/4);
- panic("%s: %s: Firmware BUG: mpi_reply mismatch: Requested PageType(0x%02x) Reply PageType(0x%02x)\n",
- ioc->name, __func__,
- mpi_request->Header.PageType & 0xF,
- mpi_reply->Header.PageType & 0xF);
+ ioc_err(ioc,
+ "%s: Firmware BUG: mpi_reply mismatch: Requested PageType(0x%02x) Reply PageType(0x%02x)\n",
+ __func__,
+ mpi_request->Header.PageType & 0xF,
+ mpi_reply->Header.PageType & 0xF);
+ r = -EIO;
+ goto free_mem;
}
if (((mpi_request->Header.PageType & 0xF) ==
@@ -434,10 +437,13 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
smid, "config_request", NULL);
_debug_dump_mf(mpi_request, ioc->request_sz/4);
_debug_dump_reply(mpi_reply, ioc->reply_sz/4);
- panic("%s: %s: Firmware BUG: mpi_reply mismatch: Requested ExtPageType(0x%02x) Reply ExtPageType(0x%02x)\n",
- ioc->name, __func__,
- mpi_request->ExtPageType,
- mpi_reply->ExtPageType);
+ ioc_err(ioc,
+ "%s: Firmware BUG: mpi_reply mismatch: Requested ExtPageType(0x%02x) Reply ExtPageType(0x%02x)\n",
+ __func__,
+ mpi_request->ExtPageType,
+ mpi_reply->ExtPageType);
+ r = -EIO;
+ goto free_mem;
}
ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
& MPI2_IOCSTATUS_MASK;
@@ -463,10 +469,13 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
_debug_dump_reply(mpi_reply, ioc->reply_sz/4);
_debug_dump_config(p, min_t(u16, mem.sz,
config_page_sz)/4);
- panic("%s: %s: Firmware BUG: config page mismatch: Requested PageType(0x%02x) Reply PageType(0x%02x)\n",
- ioc->name, __func__,
- mpi_request->Header.PageType & 0xF,
- p[3] & 0xF);
+ ioc_err(ioc,
+ "%s: Firmware BUG: config page mismatch: Requested PageType(0x%02x) Reply PageType(0x%02x)\n",
+ __func__,
+ mpi_request->Header.PageType & 0xF,
+ p[3] & 0xF);
+ r = -EIO;
+ goto free_mem;
}
if (((mpi_request->Header.PageType & 0xF) ==
@@ -479,9 +488,12 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
_debug_dump_reply(mpi_reply, ioc->reply_sz/4);
_debug_dump_config(p, min_t(u16, mem.sz,
config_page_sz)/4);
- panic("%s: %s: Firmware BUG: config page mismatch: Requested ExtPageType(0x%02x) Reply ExtPageType(0x%02x)\n",
- ioc->name, __func__,
- mpi_request->ExtPageType, p[6]);
+ ioc_err(ioc,
+ "%s: Firmware BUG: config page mismatch: Requested ExtPageType(0x%02x) Reply ExtPageType(0x%02x)\n",
+ __func__,
+ mpi_request->ExtPageType, p[6]);
+ r = -EIO;
+ goto free_mem;
}
}
memcpy(config_page, mem.page, min_t(u16, mem.sz,
@@ -1496,8 +1508,10 @@ mpt3sas_config_set_sas_iounit_pg1(struct MPT3SAS_ADAPTER *ioc,
goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
- _config_request(ioc, &mpi_request, mpi_reply,
+ r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
+ if (r)
+ goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
@@ -1946,9 +1960,11 @@ _config_set_driver_trigger_pg0(struct MPT3SAS_ADAPTER *ioc,
goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
- _config_request(ioc, &mpi_request, mpi_reply,
+ r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
sizeof(*config_page));
+ if (r)
+ goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
@@ -2080,9 +2096,11 @@ _config_set_driver_trigger_pg1(struct MPT3SAS_ADAPTER *ioc,
goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
- _config_request(ioc, &mpi_request, mpi_reply,
+ r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
sizeof(*config_page));
+ if (r)
+ goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
@@ -2231,9 +2249,11 @@ _config_set_driver_trigger_pg2(struct MPT3SAS_ADAPTER *ioc,
goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
- _config_request(ioc, &mpi_request, mpi_reply,
+ r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
sizeof(*config_page));
+ if (r)
+ goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
@@ -2391,9 +2411,11 @@ _config_set_driver_trigger_pg3(struct MPT3SAS_ADAPTER *ioc,
goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
- _config_request(ioc, &mpi_request, mpi_reply,
+ r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
sizeof(*config_page));
+ if (r)
+ goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
@@ -2548,9 +2570,11 @@ _config_set_driver_trigger_pg4(struct MPT3SAS_ADAPTER *ioc,
goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
- _config_request(ioc, &mpi_request, mpi_reply,
+ r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
sizeof(*config_page));
+ if (r)
+ goto out;
mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
r = _config_request(ioc, &mpi_request, mpi_reply,
MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 29/37] scsi: mpt3sas: Bound event-log copy size against reply frame size
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (27 preceding siblings ...)
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 ` 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
` (7 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Cap the event data copy in mpt3sas_ctl_add_to_event_log() against the
space available in the reply frame, not just MPT3_EVENT_DATA_SIZE. Treat
frames too small to hold the Mpi2EventNotificationReply_t header as having
nothing to copy to avoid underflow in the size calculation.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index d3166e048991..d15ef29ed077 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -366,8 +366,19 @@ mpt3sas_ctl_add_to_event_log(struct MPT3SAS_ADAPTER *ioc,
event_log[i].event = event;
event_log[i].context = ioc->event_context++;
+ /*
+ * Bound the copy by the reply frame ctl owns, not just the
+ * log entry size, in case the scsih-side clamp was skipped.
+ * Skip the copy when the frame is too small to hold the
+ * header, since computing a size from it would wrap.
+ */
event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4;
- sz = min_t(u32, event_data_sz, MPT3_EVENT_DATA_SIZE);
+ if (ioc->reply_sz > offsetof(Mpi2EventNotificationReply_t, EventData))
+ sz = min_t(u32, event_data_sz,
+ min_t(u32, (u32)MPT3_EVENT_DATA_SIZE,
+ ioc->reply_sz - offsetof(Mpi2EventNotificationReply_t, EventData)));
+ else
+ sz = 0;
memset(event_log[i].data, 0, MPT3_EVENT_DATA_SIZE);
memcpy(event_log[i].data, mpi_reply->EventData, sz);
send_aen = 1;
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 30/37] scsi: mpt3sas: Add _ctl_diag_buffer_reset() helper to clear diag buffer state
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (28 preceding siblings ...)
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 9:56 ` 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
` (6 subsequent siblings)
36 siblings, 0 replies; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Consolidate open-coded diag buffer teardown sequences across
_ctl_diag_register_2(), _ctl_diag_unregister(), and
_ctl_host_trace_buffer_enable_store() into a single helper that clears
the pointer, size, DMA address, status, and unique ID together.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 32 +++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index d15ef29ed077..e1c3ac432501 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -1651,6 +1651,28 @@ _ctl_diag_get_bufftype(struct MPT3SAS_ADAPTER *ioc, u32 unique_id)
return MPT3_DIAG_UID_NOT_FOUND;
}
+/**
+ * _ctl_diag_buffer_reset - clear every field describing a diag buffer
+ * @ioc: per adapter object
+ * @buffer_type: diag buffer type
+ *
+ * Call this wherever a diag buffer's DMA memory is freed, so its size and
+ * DMA address never outlive the pointer that describes them.
+ */
+static void
+_ctl_diag_buffer_reset(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type)
+{
+ ioc->diag_buffer[buffer_type] = NULL;
+ ioc->diag_buffer_sz[buffer_type] = 0;
+ ioc->diag_buffer_dma[buffer_type] = 0;
+ ioc->diag_buffer_status[buffer_type] = 0;
+ ioc->unique_id[buffer_type] = 0;
+ if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
+ ioc->ring_buffer_sz = 0;
+ ioc->ring_buffer_offset = 0;
+ }
+}
+
/**
* _ctl_diag_register_2 - wrapper for registering diag buffer support
* @ioc: per adapter object
@@ -1909,9 +1931,7 @@ _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc,
if (rc && request_data) {
dma_free_coherent(&ioc->pdev->dev, request_data_sz,
request_data, request_data_dma);
- ioc->diag_buffer[buffer_type] = NULL;
- ioc->diag_buffer_status[buffer_type] &=
- ~MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED;
+ _ctl_diag_buffer_reset(ioc, buffer_type);
}
ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
@@ -2132,8 +2152,7 @@ _ctl_diag_unregister(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
request_data_dma = ioc->diag_buffer_dma[buffer_type];
dma_free_coherent(&ioc->pdev->dev, request_data_sz,
request_data, request_data_dma);
- ioc->diag_buffer[buffer_type] = NULL;
- ioc->diag_buffer_status[buffer_type] = 0;
+ _ctl_diag_buffer_reset(ioc, buffer_type);
}
return 0;
}
@@ -3875,8 +3894,7 @@ host_trace_buffer_enable_store(struct device *cdev,
ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE],
ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE],
ioc->diag_buffer_dma[MPI2_DIAG_BUF_TYPE_TRACE]);
- ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE] =
- NULL;
+ _ctl_diag_buffer_reset(ioc, MPI2_DIAG_BUF_TYPE_TRACE);
}
diag_register.requested_buffer_size = (1024 * 1024);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 31/37] scsi: mpt3sas: Restrict ioc_dump debugfs and replace raw ioc dump with text
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (29 preceding siblings ...)
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 ` 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
` (5 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
The ioc_dump debugfs file previously exposed raw MPT3SAS_ADAPTER bytes,
leaking kernel addresses, and was world-readable.
Create the file with mode 0400 instead of 0444, replace the raw dump
with a small human-readable text summary of key adapter properties, and
fix the memory leak in the release path.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_debugfs.c | 49 +++++++++++++++++++++++---
1 file changed, 45 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_debugfs.c b/drivers/scsi/mpt3sas/mpt3sas_debugfs.c
index 183391f6b8d1..432e120ac81d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_debugfs.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_debugfs.c
@@ -49,22 +49,62 @@ _debugfs_iocdump_read(struct file *filp, char __user *ubuf, size_t cnt,
return simple_read_from_buffer(ubuf, cnt, ppos, debug->buf, debug->len);
}
+/* Buffer size for the text dump */
+#define MPT3SAS_IOCDUMP_BUF_SZ 1024
+
/*
- * _debugfs_iocdump_open : open the ioc_dump debugfs attribute file
+ * _debugfs_iocdump_open: open the ioc_dump debugfs attribute file.
+ * Populates the debugfs buffer with a summary of key adapter properties.
*/
static int
_debugfs_iocdump_open(struct inode *inode, struct file *file)
{
struct MPT3SAS_ADAPTER *ioc = inode->i_private;
struct mpt3sas_debugfs_buffer *debug;
+ char *buf;
+ size_t len = 0;
debug = kzalloc_obj(struct mpt3sas_debugfs_buffer);
if (!debug)
return -ENOMEM;
- debug->buf = (void *)ioc;
- debug->len = sizeof(struct MPT3SAS_ADAPTER);
+ buf = kzalloc(MPT3SAS_IOCDUMP_BUF_SZ, GFP_KERNEL);
+ if (!buf) {
+ kfree(debug);
+ return -ENOMEM;
+ }
+
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "name: %s\n", ioc->name);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "fw_version: %02d.%02d.%02d.%02d\n",
+ (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
+ (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
+ (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
+ ioc->facts.FWVersion.Word & 0x000000FF);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "request_sz: %d\n", ioc->request_sz);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "reply_sz: %d\n", ioc->reply_sz);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "chain_segment_sz: %d\n", ioc->chain_segment_sz);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "hba_queue_depth: %d\n", ioc->hba_queue_depth);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "scsiio_depth: %d\n", ioc->scsiio_depth);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "max_dev_handle: %d\n", ioc->facts.MaxDevHandle);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "shost_recovery: %d\n", ioc->shost_recovery);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "pci_error_recovery: %d\n", ioc->pci_error_recovery);
+ len += scnprintf(buf + len, MPT3SAS_IOCDUMP_BUF_SZ - len,
+ "remove_host: %d\n", ioc->remove_host);
+
+ debug->buf = buf;
+ debug->len = len;
file->private_data = debug;
+
return 0;
}
@@ -82,6 +122,7 @@ _debugfs_iocdump_release(struct inode *inode, struct file *file)
return 0;
file->private_data = NULL;
+ kfree(debug->buf);
kfree(debug);
return 0;
}
@@ -132,7 +173,7 @@ mpt3sas_setup_debugfs(struct MPT3SAS_ADAPTER *ioc)
}
snprintf(name, sizeof(name), "ioc_dump");
- ioc->ioc_dump = debugfs_create_file(name, 0444,
+ ioc->ioc_dump = debugfs_create_file(name, 0400,
ioc->debugfs_root, ioc, &mpt3sas_debugfs_iocdump_fops);
if (!ioc->ioc_dump) {
dev_err(&ioc->pdev->dev,
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 32/37] scsi: mpt3sas: Fix out-of-bounds bit operation in _scsih_check_topo_delete_events
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (30 preceding siblings ...)
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 9:56 ` 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
` (4 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
When find_first_bit() returns a value >= MaxDevHandle (no bit set), the
loop called test_and_clear_bit() with the out-of-range index. Break out
immediately when the returned position is >= MaxDevHandle.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 64de88183f8d..b697250bed61 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -5016,8 +5016,9 @@ _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
do {
handle = find_first_bit(ioc->blocking_handles,
ioc->facts.MaxDevHandle);
- if (handle < ioc->facts.MaxDevHandle)
- _scsih_block_io_device(ioc, handle);
+ if (handle >= ioc->facts.MaxDevHandle)
+ break;
+ _scsih_block_io_device(ioc, handle);
} while (test_and_clear_bit(handle, ioc->blocking_handles));
} else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
_scsih_block_io_to_children_attached_directly(ioc, event_data);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 33/37] scsi: mpt3sas: Bound SMP passthrough buffer reads to actual buffer size
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (31 preceding siblings ...)
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 9:56 ` 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
` (3 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
The SMP passthrough handler reads bytes at offsets 1 and 10 of the data
buffer to detect link-reset commands without checking the buffer length.
Guard each read against the actual buffer size to prevent out-of-bounds
access on undersized non-inline buffers.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index e1c3ac432501..e8c5dee499fd 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -996,13 +996,15 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
Mpi2SmpPassthroughRequest_t *smp_request =
(Mpi2SmpPassthroughRequest_t *)mpi_request;
u8 *data;
+ bool inline_data;
if (!ioc->multipath_on_hba) {
/* ioc determines which port to use */
smp_request->PhysicalPort = 0xFF;
}
- if (smp_request->PassthroughFlags &
- MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
+ inline_data = smp_request->PassthroughFlags &
+ MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE;
+ if (inline_data)
data = (u8 *)&smp_request->SGL;
else {
if (unlikely(data_out == NULL)) {
@@ -1015,7 +1017,10 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
data = data_out;
}
- if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
+ /* Bound the read below to the caller-supplied buffer size. */
+ if ((inline_data || data_out_sz > 1) && data[1] == 0x91 &&
+ (inline_data || data_out_sz > 10) &&
+ (data[10] == 1 || data[10] == 2)) {
ioc->ioc_link_reset_in_progress = 1;
ioc->ignore_loginfos = 1;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 34/37] scsi: mpt3sas: Release sas_device reference on error in mpt3sas_transport_port_add
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (32 preceding siblings ...)
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 9:56 ` 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
` (2 subsequent siblings)
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
The reference taken by mpt3sas_get_sdev_by_addr() is never released on
error paths that branch to out_fail. Add sas_device_put() there to
prevent a reference count leak.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_transport.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c
index 5f087d0b4d7a..facdec0240db 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
@@ -866,6 +866,8 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,
sas_port_delete(port);
out_fail:
+ if (sas_device)
+ sas_device_put(sas_device);
list_for_each_entry_safe(mpt3sas_phy, next, &mpt3sas_port->phy_list,
port_siblings)
list_del(&mpt3sas_phy->port_siblings);
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 35/37] scsi: mpt3sas: NULL the event_log pointer after freeing it
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (33 preceding siblings ...)
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 9:56 ` 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 9:56 ` [PATCH v2 37/37] scsi: mpt3sas: Update driver version to 59.100.00.00 Shivasharan S
36 siblings, 0 replies; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Set ioc->event_log = NULL immediately after kfree() in
mpt3sas_ctl_release() to prevent use-after-free if a concurrent path
dereferences the pointer during adapter teardown.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index e8c5dee499fd..c3d337c203ef 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -4628,6 +4628,7 @@ mpt3sas_ctl_release(struct MPT3SAS_ADAPTER *ioc)
}
kfree(ioc->event_log);
+ ioc->event_log = NULL;
}
/**
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 36/37] scsi: mpt3sas: Bound NVMe passthrough transfer size against PRP buffer capacity
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (34 preceding siblings ...)
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 ` 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
36 siblings, 1 reply; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
The NVMe ioctl passthrough path builds a PRP list into a fixed per-command
buffer sized as sg_tablesize * page_size. Reject requests where either
data_in_size or data_out_size exceeds that limit to prevent overrunning
the buffer and corrupting adjacent DMA allocations.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index c3d337c203ef..b147640a139e 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -899,6 +899,21 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
ret = -EINVAL;
goto out;
}
+ /*
+ * Reject an oversized transfer, since building the PRP list
+ * would overrun this command's fixed buffer, corrupting
+ * others sharing it.
+ */
+ if (data_out_sz > ((u64)ioc->shost->sg_tablesize * ioc->page_size) ||
+ data_in_sz > ((u64)ioc->shost->sg_tablesize * ioc->page_size)) {
+ dtmprintk(ioc, ioc_info(ioc,
+ "%s: data_in_size/data_out_size exceeds NVMe PRP buffer capacity\n",
+ __func__));
+ mpt3sas_base_free_smid(ioc, smid);
+ ret = -EINVAL;
+ goto out;
+ }
+
/*
* Get the Physical Address of the sense buffer.
* Use Error Response buffer address field to hold the sense
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* [PATCH v2 37/37] scsi: mpt3sas: Update driver version to 59.100.00.00
2026-11-18 9:56 [PATCH v2 00/37] scsi: mpt3sas: Validate firmware/user input and fix error-path bugs Shivasharan S
` (35 preceding siblings ...)
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 9:56 ` Shivasharan S
36 siblings, 0 replies; 68+ messages in thread
From: Shivasharan S @ 2026-11-18 9:56 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: sathya.prakash, ranjan.kumar, chandrakanth.patil, sweeti.vandure,
thenzl, mgandhi, loberman, Shivasharan S
Updated driver version to 59.100.00.00.
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
---
drivers/scsi/mpt3sas/mpt3sas_base.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 6fb511530637..763e1e901917 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -77,8 +77,8 @@
#define MPT3SAS_DRIVER_NAME "mpt3sas"
#define MPT3SAS_AUTHOR "Avago Technologies <MPT-FusionLinux.pdl@avagotech.com>"
#define MPT3SAS_DESCRIPTION "LSI MPT Fusion SAS 3.0 Device Driver"
-#define MPT3SAS_DRIVER_VERSION "54.100.00.00"
-#define MPT3SAS_MAJOR_VERSION 54
+#define MPT3SAS_DRIVER_VERSION "59.100.00.00"
+#define MPT3SAS_MAJOR_VERSION 59
#define MPT3SAS_MINOR_VERSION 100
#define MPT3SAS_BUILD_VERSION 00
#define MPT3SAS_RELEASE_VERSION 00
--
2.53.0
^ permalink raw reply related [flat|nested] 68+ messages in thread
* Re: [PATCH v2 13/37] scsi: mpt3sas: Validate max_data_size in MPT3EVENTREPORT ioctl
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:20 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for _ctl_eventreport()
underflow fix
--
commit f69a1ab648280769c7af16f9e89c971b1187d329
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Validate max_data_size in MPT3EVENTREPORT ioctl
>
> Reject a max_data_size smaller than the ioctl header size before
> using it in size arithmetic.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes an unsigned underflow in _ctl_eventreport() present since the
driver was introduced. Should this include:
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=13
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 14/37] scsi: mpt3sas: Fix buffer overflow in _scsih_scsi_ioc_info
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:21 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for _scsih_scsi_ioc_info()
fix
--
commit fa67a5252633dddcb65a2dd6aaf05d7ae84cb968
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix buffer overflow in _scsih_scsi_ioc_info
>
> Build the SCSIState description string with a bounds-checked
> snprintf() instead of a chain of unbounded strcat()s.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Both the 64-byte MPT_STRING_LENGTH definition and the unbounded strcat()
chain in _scsih_scsi_ioc_info() were introduced when the driver was added.
Should this include:
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=14
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 11/37] scsi: mpt3sas: Fix port_table memory leak in _scsih_sas_port_refresh
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:22 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for
_scsih_sas_port_refresh() leak fix
--
commit 4df946a26df1e07b82fd4552694bd9266dd6fd85
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix port_table memory leak in _scsih_sas_port_refresh
>
> Free port_table on every exit path, including the early return when
> no ports are found.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes a memory leak in _scsih_sas_port_refresh(). Should this
include:
Fixes: a5e99fda0172 ("scsi: mpt3sas: Update hba_port objects after host reset")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=11
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 02/37] scsi: mpt3sas: Validate RAID configuration page length
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:22 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer in
mpt3sas_config_get_volume_handle()
--
commit 1a9b4a845a58146159a3e5de43ee7711eceec2d6
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Validate RAID configuration page length
>
> Check the RAID config page length and NumElements against the
> allocated buffer before use, to avoid an out-of-bounds read.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Since this fixes an out-of-bounds read in
mpt3sas_config_get_volume_handle(), should this include a Fixes tag?
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=2
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 15/37] scsi: mpt3sas: Fix Scsi_Host leak on invalid/tampered device probe
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:26 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for Scsi_Host leak in
_scsih_probe()
--
commit a9a92c92deebc92ce6b586ab0b53ab5f9760eb6d
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix Scsi_Host leak on invalid/tampered device probe
>
> Release the Scsi_Host before returning on the invalid/tampered
> device-ID paths in _scsih_probe().
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Those early-return paths after scsi_host_alloc() in _scsih_probe() were
added by commit f38c43a0e900 ("scsi: mpt3sas: Detect tampered Aero and Sea
adapters"). Should this include:
Fixes: f38c43a0e900 ("scsi: mpt3sas: Detect tampered Aero and Sea adapters")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=15
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 10/37] scsi: mpt3sas: NULL ioc->reply_post after freeing it
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:27 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for commit 9b05c91ae7fb
--
commit 956a2d8532f74a3ece3dfc96d7c47ac51d5013d8
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: NULL ioc->reply_post after freeing it
>
> Match the pattern used for other pool pointers in
> _base_release_memory_pools() so a repeat call can't reuse it.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
When _base_allocate_memory_pools() calls _base_release_memory_pools() on
a retry path and then fails, mpt3sas_base_attach() calls
_base_release_memory_pools() a second time and would otherwise
dereference and double free ioc->reply_post. Should this include:
Fixes: 9b05c91ae7fb ("mpt3sas: Added Reply Descriptor Post Queue (RDPQ) Array support")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=10
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 01/37] scsi: mpt3sas: Validate firmware-reported IOCRequestFrameSize
2026-11-18 9:56 ` [PATCH v2 01/37] scsi: mpt3sas: Validate firmware-reported IOCRequestFrameSize Shivasharan S
@ 2026-11-18 10:28 ` sashiko-bot
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:28 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes: trailer for IOCRequestFrameSize
validation fix
--
commit b463953eb9cc498a90d368572f626fa18df586e7
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Validate firmware-reported IOCRequestFrameSize
>
> Reject an IOCFacts-reported request frame size smaller than
> Mpi25SCSIIORequest_t, which would otherwise corrupt adjacent memory.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Since this fixes an unvalidated IOCRequestFrameSize assignment in
_base_allocate_memory_pools(), should the commit message include a Fixes
tag?
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=1
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 18/37] scsi: mpt3sas: Clamp firmware reply copies to the allocated reply buffer
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:29 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for unbounded MsgLength
reply copies
--
commit b374b47a54633c9bf2af24964142863927dcf94a
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Clamp firmware reply copies to the allocated reply buffer
>
> Clamp MsgLength-based memcpy()s of firmware replies to ioc->reply_sz
> across the driver's completion handlers.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes unbounded reply copies present since the driver was added.
Should this include:
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=18
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 07/37] scsi: mpt3sas: Validate SMP request/response length in bsg handler
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:29 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for
_transport_smp_handler() fix
--
commit 060984be700991973c1d95141b9dd8e66c82834b
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Validate SMP request/response length in bsg handler
>
> Reject SMP requests whose mapped request or response buffer is
> smaller than 4 bytes, avoiding a length underflow when building the
> SGE.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes a length underflow in _transport_smp_handler(). Should this
include a Fixes: tag, such as:
Fixes: 651a01364994 ("scsi: scsi_transport_sas: switch to bsg-lib for SMP passthrough")
or:
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=7
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 17/37] scsi: mpt3sas: Clamp ValidEntries in driver trigger page update helpers
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:29 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailers for trigger page update
helpers
--
commit dcd564521e5587b8463313055759db28291e6ac0
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Clamp ValidEntries in driver trigger page update helpers
>
> Clamp ValidEntries to NUM_VALID_ENTRIES in the pg2/pg3/pg4 trigger
> update helpers before it's used as a copy count.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes an unclamped copy loop in the driver trigger page update
helpers. Should this include:
Fixes: 71b3fb8fe6dd ("scsi: mpt3sas: Add persistent Event trigger page")
Fixes: 2a5c3a35c156 ("scsi: mpt3sas: Add persistent SCSI sense trigger page")
Fixes: 0e17a87c5950 ("scsi: mpt3sas: Add persistent MPI trigger page")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=17
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 06/37] scsi: mpt3sas: Fix invalid kfree() of fw_event_work event_data
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:30 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for
mpt3sas_scsih_event_callback() fix
--
commit 919960a29ab6529ce505fc0fb585ac3b629d2374
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix invalid kfree() of fw_event_work event_data
>
> Drop an errant kfree() of fw_event->event_data, a flexible array
> member of fw_event_work rather than its own allocation.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Should this bug fix include a Fixes: tag for the commit that added the
kfree(fw_event->event_data) call?
Fixes: ad5957193107 ("scsi: mpt3sas: Add firmware event requeue support for busy devices")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=6
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 12/37] scsi: mpt3sas: Fix leak and dangling pointer for io_uring_poll_queues
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:32 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] scsi: mpt3sas: NULL deref of io_uring_poll_queues after
disable_msix()
- [Low] scsi: mpt3sas: missing Fixes trailer for commit 432bc7caef4e
--
commit a58948543f4caa46f0c5cf6ea2380d1623cf71c1
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix leak and dangling pointer for io_uring_poll_queues
>
> Free ioc->io_uring_poll_queues on the legacy-IRQ fallback path and
> NULL it after freeing.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Should this include a Fixes tag for the commit that introduced the
allocation and cleanup of ioc->io_uring_poll_queues:
Fixes: 432bc7caef4e ("scsi: mpt3sas: Add io_uring iopoll support")
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 8182c7ba8b9a7..24b74760d6816 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -3362,6 +3362,7 @@ mpt3sas_base_disable_msix(struct MPT3SAS_ADAPTER *ioc)
> pci_free_irq_vectors(ioc->pdev);
> ioc->msix_enable = 0;
> kfree(ioc->io_uring_poll_queues);
> + ioc->io_uring_poll_queues = NULL;
> }
>
> /**
> @@ -3541,6 +3542,8 @@ _base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
>
> /* failback to io_apic interrupt routing */
> try_ioapic:
> + kfree(ioc->io_uring_poll_queues);
> + ioc->io_uring_poll_queues = NULL;
> ioc->high_iops_queues = 0;
> ioc_info(ioc, "High IOPs queues : disabled\n");
> ioc->reply_queue_count = 1;
[Severity: Medium]
Can setting ioc->io_uring_poll_queues to NULL cause a NULL pointer
dereference in mpt3sas_base_pause_mq_polling() or mpt3sas_blk_mq_poll()?
Unlike the try_ioapic path in _base_enable_msix(),
mpt3sas_base_disable_msix() frees and NULLs ioc->io_uring_poll_queues
without resetting ioc->iopoll_q_start_index to ioc->reply_queue_count.
During PCIe error recovery, scsih_pci_error_detected() handles
pci_channel_io_frozen by calling mpt3sas_base_free_resources() ->
mpt3sas_base_unmap_resources() -> mpt3sas_base_disable_msix(). If slot
reset or resource remapping subsequently fails,
scsih_pci_error_detected() is called with pci_channel_io_perm_failure and
invokes mpt3sas_base_pause_mq_polling(), which computes a non-zero
iopoll_q_count and dereferences ioc->io_uring_poll_queues:
drivers/scsi/mpt3sas/mpt3sas_base.c:mpt3sas_base_pause_mq_polling() {
int iopoll_q_count =
ioc->reply_queue_count - ioc->iopoll_q_start_index;
int qid;
for (qid = 0; qid < iopoll_q_count; qid++)
atomic_set(&ioc->io_uring_poll_queues[qid].pause, 1);
...
}
In addition, if an adapter probes with poll_queues > 0 (mapping
HCTX_TYPE_POLL queues in blk-mq) and later falls back to try_ioapic
during scsih_resume() or scsih_pci_slot_reset(), ioc->io_uring_poll_queues
is NULL while HCTX_TYPE_POLL queues remain registered, so subsequent calls
to mpt3sas_blk_mq_poll() will also dereference NULL.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=12
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 22/37] scsi: mpt3sas: Clamp num_luns in _scsih_wait_for_target_to_become_ready
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:32 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for
_scsih_wait_for_target_to_become_ready() OOB fix
--
commit d3ac3b98212039d9647a54f40707cb4be2616395
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Clamp num_luns in _scsih_wait_for_target_to_become_ready
>
> Clamp num_luns to the lun_data allocation size before using it as a
> loop bound.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes an out-of-bounds read on lun_data[] in
_scsih_wait_for_target_to_become_ready(). Should this include:
Fixes: aee682fad6cd ("scsi: mpt3sas: Improve device discovery and readiness handling for slow devices")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=22
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 20/37] scsi: mpt3sas: Validate CurrentHostPageSize before using it as a shift amount
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:33 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for _base_get_ioc_facts()
shift fix
--
commit 397af194b8267f2475a201fdc3150680a1b5ba71
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Validate CurrentHostPageSize before using it as a shift amount
>
> Reject an out-of-range CurrentHostPageSize instead of using it
> directly as a shift amount.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Since this fixes the unvalidated shift of facts->CurrentHostPageSize in
_base_get_ioc_facts(), should it include a Fixes tag?
Fixes: 016d5c35e278 ("scsi: mpt3sas: SGL to PRP Translation for I/Os to NVMe devices")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=20
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 19/37] scsi: mpt3sas: Reject implausibly small MaxReplyDescriptorPostQueueDepth
2026-11-18 9:56 ` [PATCH v2 19/37] scsi: mpt3sas: Reject implausibly small MaxReplyDescriptorPostQueueDepth Shivasharan S
@ 2026-11-18 10:33 ` sashiko-bot
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:33 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for queue depth underflow
check
--
commit bb0ded0f5bb17ca3004a3f754f6ece2a684ed10e
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Reject implausibly small MaxReplyDescriptorPostQueueDepth
>
> Avoid an unsigned underflow in the hba_queue_depth calculation when
> firmware reports a too-small queue depth.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Since this fixes an unsigned underflow in the queue depth calculation in
_base_allocate_memory_pools(), should this include:
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=19
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 08/37] scsi: mpt3sas: Validate firmware/user supplied device handles against MaxDevHandle
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:33 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] scsi: mpt3sas: missing MaxDevHandle checks in PCIe event and
add paths
- [Medium] scsi: mpt3sas: missing MaxDevHandle checks in SAS phy change
and check paths
--
commit 1475cb70df52e6382fa2780421f221a0823686a6
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
scsi: mpt3sas: Validate firmware/user supplied device handles against MaxDevHandle
This commit validates firmware-supplied and ioctl-supplied device handles
against ioc->facts.MaxDevHandle across event, discovery, post-reset scan,
TM/control completion, and ioctl passthrough paths.
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index 852c164996384..a310605806b18 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
[ ... ]
> @@ -8399,6 +8418,13 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
> u8 connector_name[5];
> u8 port_id;
>
> + if (handle >= ioc->facts.MaxDevHandle) {
> + /* not retryable: drop the device instead of looping forever */
> + ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
> + handle, __func__);
> + return 0;
> + }
> +
> if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
> MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
> ioc_err(ioc, "failure at %s:%d/%s()!\n",
> @@ -9186,6 +9212,12 @@ _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
[Severity: Medium]
Can an out-of-bounds AttachedDevHandle in _scsih_sas_topology_change_event()
still index ioc->pend_os_device_add and overwrite sas_device->handle before
reaching _scsih_add_device()?
On MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED, _scsih_sas_topology_change_event()
passes the unvalidated handle to _scsih_check_device() (which unlike
_scsih_pcie_check_device() has no MaxDevHandle check and overwrites
sas_target_priv_data->handle and sas_device->handle) and then reads
test_bit(handle, ioc->pend_os_device_add) before falling through to
_scsih_add_device():
drivers/scsi/mpt3sas/mpt3sas_scsih.c:_scsih_sas_topology_change_event() {
...
case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
...
_scsih_check_device(ioc, sas_address, handle,
phy_number, link_rate);
...
if (!test_bit(handle, ioc->pend_os_device_add))
break;
...
}
> struct MPT3SAS_TARGET *sas_target_priv_data;
> u32 device_info;
>
> + if (handle >= ioc->facts.MaxDevHandle) {
> + ioc_err(ioc, "handle(0x%04x) out of bounds in %s\n",
> + handle, __func__);
> + return;
> + }
> +
> if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
> &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle)))
> return;
[Severity: Medium]
When _scsih_pcie_check_device() returns early on an out-of-bounds handle,
does its caller _scsih_pcie_topology_change_event() still pass that handle to
test_bit(handle, ioc->pend_os_device_add)?
Because _scsih_pcie_check_device() returns void,
_scsih_pcie_topology_change_event() continues after __mpt3sas_get_pdev_by_handle()
returns NULL and reads past the end of ioc->pend_os_device_add:
drivers/scsi/mpt3sas/mpt3sas_scsih.c:_scsih_pcie_topology_change_event() {
...
_scsih_pcie_check_device(ioc, handle);
...
if (pcie_device) {
pcie_device_put(pcie_device);
break;
}
if (!test_bit(handle, ioc->pend_os_device_add))
break;
...
}
In addition, _scsih_pcie_add_device() (called from the
MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED case right below and from
_scsih_scan_for_devices_after_reset()) lacks the handle >=
ioc->facts.MaxDevHandle check added to _scsih_add_device(), so an
out-of-bounds PCIe handle will execute set_bit(handle,
ioc->pend_os_device_add) and corrupt adjacent heap memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=8
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 21/37] scsi: mpt3sas: Clamp sense_length before copying into transfer_packet->sense
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:35 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes: trailer for _scsi_send_scsi_io()
overflow fix
--
commit 4d7bd86fa6f45295740631c1c707cf0f676eab3c
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Clamp sense_length before copying into transfer_packet->sense
>
> Clamp the firmware-reported SenseCount to sizeof(sense) before the
> copy.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes a potential buffer overflow in _scsi_send_scsi_io(). Should
this include:
Fixes: aee682fad6cd ("scsi: mpt3sas: Improve device discovery and readiness handling for slow devices")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=21
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 05/37] scsi: mpt3sas: Fix unlocked use of raid_device in enable_sdev_max_qd_store
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:36 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for commit 8dc8d29a00e2
--
commit 684177668e14060ff21b25ff736981f016e8a747
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix unlocked use of raid_device in enable_sdev_max_qd_store
>
> Take ioc->raid_device_lock around the raid_device lookup and check
> for NULL before dereferencing it.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Should this bug fix include a Fixes tag for the commit that introduced
enable_sdev_max_qd_store()?
Fixes: 8dc8d29a00e2 ("scsi: mpt3sas: Introduce module parameter to override queue depth")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=5
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 04/37] scsi: mpt3sas: Fix locking and bounds checks on host_trace_buffer sysfs files
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:37 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for host_trace_buffer sysfs
fix
- [Low] scsi: mpt3sas: redundant ring_buffer reset in
_ctl_diag_register_2()
--
commit 3535763c07f27fef4db2f60a5c7aeaf47d1bbea7
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix locking and bounds checks on host_trace_buffer sysfs files
>
> Serialize the host_trace_buffer* sysfs handlers on ctl_cmds.mutex and
> clamp the reported/used buffer size to the actual allocation size.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Since this fixes locking and bounds checks in the host_trace_buffer sysfs
handlers, should it include a Fixes tag?
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> index f4eeef572f6ec..ef28da96dc262 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> @@ -1772,6 +1772,11 @@ _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc,
> /* Reset ioc variables used for additional query commands */
> ioc->reset_from_user = 0;
> memset(&ioc->htb_rel, 0, sizeof(struct htb_rel_query));
> + /* a (re)posted trace buffer starts a fresh capture */
> + if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
> + ioc->ring_buffer_sz = 0;
> + ioc->ring_buffer_offset = 0;
> + }
> ioc->diag_buffer_status[buffer_type] &=
> MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED;
> memcpy(ioc->product_specific[buffer_type],
> @@ -1791,6 +1796,10 @@ _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc,
> if (request_data == NULL) {
> ioc->diag_buffer_sz[buffer_type] = 0;
> ioc->diag_buffer_dma[buffer_type] = 0;
> + if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
> + ioc->ring_buffer_sz = 0;
> + ioc->ring_buffer_offset = 0;
> + }
[Severity: Low]
This isn't a bug, but the second reset of ioc->ring_buffer_sz and
ioc->ring_buffer_offset inside the request_data == NULL block is redundant
since both fields are already zeroed unconditionally just above.
Also, when a released trace buffer is re-posted via the MPT3DIAGREADBUFFER
ioctl with MPT3_FLAGS_REREGISTER in _ctl_diag_read_buffer(),
ioc->ring_buffer_sz and ioc->ring_buffer_offset are not reset, leaving
stale sysfs ring buffer state across ioctl-initiated re-registration.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=4
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 31/37] scsi: mpt3sas: Restrict ioc_dump debugfs and replace raw ioc dump with text
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:38 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for ioc_dump debugfs fix
- [Low] scsi: mpt3sas: inaccurate leak fix claim in
_debugfs_iocdump_release()
--
commit 820d81c18cf70e4f505e1114ea0578843ea87567
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Restrict ioc_dump debugfs and replace raw ioc dump with text
>
> The ioc_dump debugfs file previously exposed raw MPT3SAS_ADAPTER bytes,
> leaking kernel addresses, and was world-readable.
>
> Create the file with mode 0400 instead of 0444, replace the raw dump
> with a small human-readable text summary of key adapter properties, and
> fix the memory leak in the release path.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Since this fixes the raw adapter structure exposure and world-readable
debugfs permissions introduced in 2b01b293f359 ("scsi: mpt3sas: Capture IOC
data for debugging purposes"), should the commit message include:
Fixes: 2b01b293f359 ("scsi: mpt3sas: Capture IOC data for debugging purposes")
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_debugfs.c b/drivers/scsi/mpt3sas/mpt3sas_debugfs.c
> index 183391f6b8d19..432e120ac81db 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_debugfs.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_debugfs.c
> @@ -49,22 +49,62 @@ _debugfs_iocdump_read(struct file *filp, char __user *ubuf, size_t cnt,
> return simple_read_from_buffer(ubuf, cnt, ppos, debug->buf, debug->len);
> }
>
> +/* Buffer size for the text dump */
> +#define MPT3SAS_IOCDUMP_BUF_SZ 1024
> +
> /*
> - * _debugfs_iocdump_open : open the ioc_dump debugfs attribute file
> + * _debugfs_iocdump_open: open the ioc_dump debugfs attribute file.
> + * Populates the debugfs buffer with a summary of key adapter properties.
> */
> static int
> _debugfs_iocdump_open(struct inode *inode, struct file *file)
> {
> struct MPT3SAS_ADAPTER *ioc = inode->i_private;
> struct mpt3sas_debugfs_buffer *debug;
> + char *buf;
> + size_t len = 0;
>
> debug = kzalloc_obj(struct mpt3sas_debugfs_buffer);
> if (!debug)
> return -ENOMEM;
>
> - debug->buf = (void *)ioc;
> - debug->len = sizeof(struct MPT3SAS_ADAPTER);
> + buf = kzalloc(MPT3SAS_IOCDUMP_BUF_SZ, GFP_KERNEL);
> + if (!buf) {
> + kfree(debug);
> + return -ENOMEM;
> + }
[ ... ]
> + debug->buf = buf;
> + debug->len = len;
> file->private_data = debug;
> +
> return 0;
> }
>
> @@ -82,6 +122,7 @@ _debugfs_iocdump_release(struct inode *inode, struct file *file)
> return 0;
>
> file->private_data = NULL;
> + kfree(debug->buf);
> kfree(debug);
> return 0;
> }
[Severity: Low]
Is the commit message accurate when it says this fixes a memory leak in the
release path?
Previously _debugfs_iocdump_open() set debug->buf = (void *)ioc and only
allocated struct mpt3sas_debugfs_buffer, which _debugfs_iocdump_release()
freed with kfree(debug). kfree(debug->buf) frees the text buffer newly
allocated by this patch in _debugfs_iocdump_open() rather than fixing an
existing leak.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=31
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 32/37] scsi: mpt3sas: Fix out-of-bounds bit operation in _scsih_check_topo_delete_events
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:38 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer on out-of-bounds bitop fix
--
commit 7e5a1d39be62ca30c67d676c42b692226b0240a2
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix out-of-bounds bit operation in _scsih_check_topo_delete_events
>
> When find_first_bit() returns a value >= MaxDevHandle (no bit set), the
> loop called test_and_clear_bit() with the out-of-range index. Break out
> immediately when the returned position is >= MaxDevHandle.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Since this fixes an out-of-bounds bit operation present since the driver was
added, should the commit message include a Fixes tag?
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=32
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 29/37] scsi: mpt3sas: Bound event-log copy size against reply frame size
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:39 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for
mpt3sas_ctl_add_to_event_log() bounds fix
--
commit dc77a741c46884a47491b6aaf492e68771521963
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Bound event-log copy size against reply frame size
>
> Cap the event data copy in mpt3sas_ctl_add_to_event_log() against the
> space available in the reply frame, not just MPT3_EVENT_DATA_SIZE. Treat
> frames too small to hold the Mpi2EventNotificationReply_t header as having
> nothing to copy to avoid underflow in the size calculation.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes an unclamped copy in mpt3sas_ctl_add_to_event_log() present
since the driver was added. Should this include:
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=29
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 25/37] scsi: mpt3sas: Fix SGE offset boundary check in _ctl_do_mpt_command
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:39 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] scsi: mpt3sas: commit message mismatches SGE check in
_ctl_do_mpt_command()
- [Low] scsi: mpt3sas: missing Fixes trailer for _ctl_do_mpt_command()
SGE bounds fix
--
commit 5758bc759aacfe053f7ee27bcc8629e05f1607de
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Fix SGE offset boundary check in _ctl_do_mpt_command
>
> Ensure data_sge_offset leaves room for two SGE entries within the request
> frame by checking that data_sge_offset * 4 does not exceed request_sz - 32.
> Reorder the overflow guard before the multiplication to prevent wraparound.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Since this fixes the overflow ordering and SGE bounds check from the
initial driver commit, should it include a Fixes tag?
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> index f979672353677..d3166e0489918 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> @@ -714,6 +714,7 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
> unsigned long timeout;
> u8 issue_reset;
> u32 sz, sz_arg;
> + u32 sge_cnt;
> void *psge;
> void *data_out = NULL;
> dma_addr_t data_out_dma = 0;
> @@ -746,8 +747,9 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
> }
>
> /* Check for overflow and wraparound */
> - if (karg.data_sge_offset * 4 > ioc->request_sz ||
> - karg.data_sge_offset > (UINT_MAX / 4)) {
> + if (karg.data_sge_offset > (UINT_MAX / 4) ||
> + karg.data_sge_offset * 4 >
> + ioc->request_sz - max_t(u32, ioc->sge_size, ioc->sge_size_ieee)) {
> ret = -EINVAL;
> goto out;
> }
> @@ -782,6 +784,23 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
> data_out_sz = karg.data_out_size;
> data_in_sz = karg.data_in_size;
>
> + /*
> + * SGEs follow the request header and must stay inside the frame.
> + * MCTP, mem-move and bidirectional data need two, others need one.
> + */
> + sge_cnt = (data_out_sz && data_in_sz) ? 2 : 1;
> + if (mpi_request->Function == MPI2_FUNCTION_MCTP_PASSTHROUGH ||
> + (mpi_request->Function == MPI2_FUNCTION_TOOLBOX &&
> + ((Mpi2ToolboxCleanRequest_t *)mpi_request)->Tool ==
> + MPI2_TOOLBOX_MEMORY_MOVE_TOOL))
> + sge_cnt = 2;
> + if (karg.data_sge_offset * 4 + sge_cnt *
> + max_t(u32, ioc->sge_size, ioc->sge_size_ieee) > ioc->request_sz) {
> + mpt3sas_base_free_smid(ioc, smid);
> + ret = -EINVAL;
> + goto out;
> + }
[Severity: Medium]
Does the commit message match the bounds check implemented here?
The changelog says data_sge_offset * 4 is checked against request_sz - 32
to leave room for two SGE entries. Instead, _ctl_do_mpt_command() first
checks against ioc->request_sz - max_t(u32, ioc->sge_size,
ioc->sge_size_ieee) for one SGE, and after copying mpi_request from
userspace checks whether 1 or 2 SGEs are needed based on the transfer
direction and MPI function.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=25
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 33/37] scsi: mpt3sas: Bound SMP passthrough buffer reads to actual buffer size
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:40 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for _ctl_do_mpt_command()
OOB read
--
commit 5f3c301389fcadf4a6fbd2c4af7efab3ea17511d
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Bound SMP passthrough buffer reads to actual buffer size
>
> The SMP passthrough handler reads bytes at offsets 1 and 10 of the data
> buffer to detect link-reset commands without checking the buffer length.
> Guard each read against the actual buffer size to prevent out-of-bounds
> access on undersized non-inline buffers.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes an out-of-bounds read in _ctl_do_mpt_command(). Should this
include:
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=33
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 03/37] scsi: mpt3sas: Pin Scsi_Host while an ioctl is using its ioc
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:41 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] scsi: mpt3sas: premature publication of ioc on
mpt3sas_ioc_list in _scsih_probe()
- [Medium] scsi: mpt3sas: scsi_host_get() in _ctl_verify_adapter() does
not block teardown
- [Low] scsi: mpt3sas: missing Fixes trailer on bug-fix commit
--
commit 60e7b794a30f8451bb00b5913b1698ad94d9c3dd
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Pin Scsi_Host while an ioctl is using its ioc
>
> Take a Scsi_Host reference in _ctl_verify_adapter() and release it
> once the ioctl is done, so the adapter can't be torn down while an
> ioctl is in flight.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This is a bug fix for the unreferenced ioc lookup in the ioctl path. Should
it include a Fixes tag?
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> index 8bb947004885b..f4eeef572f6ec 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> @@ -447,6 +447,11 @@ _ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp,
> continue;
> }
> out:
> + if (!ioc->shost || !scsi_host_get(ioc->shost)) {
> + spin_unlock(&gioc_lock);
> + *iocpp = NULL;
> + return -1;
> + }
> spin_unlock(&gioc_lock);
> *iocpp = ioc;
> return ioc_number;
[Severity: Medium]
Does scsi_host_get(ioc->shost) prevent scsih_remove() from tearing down
shost->tag_set while an ioctl is already in flight?
scsi_host_get() pins the Scsi_Host memory allocation via shost->shost_gendev
and blocks new lookups once scsi_remove_host() sets SHOST_DEL, but it does
not take shost->tagset_refcnt or block scsih_remove(). If an ioctl acquires
ioc->pci_access_mutex and passes the ioc->remove_host check before
scsih_remove() sets ioc->remove_host = 1, scsih_remove() proceeds without
acquiring ioc->pci_access_mutex until mpt3sas_base_detach() ->
mpt3sas_base_free_resources():
CPU0 CPU1
_ctl_ioctl_main()
_ctl_verify_adapter()
scsi_host_get(ioc->shost)
mutex_lock(&ioc->pci_access_mutex)
if (ioc->remove_host) // false
scsih_remove()
ioc->remove_host = 1;
...
sas_remove_host(shost)
scsi_remove_host(shost)
...
blk_mq_free_tag_set(&shost->tag_set)
_ctl_do_reset()
mpt3sas_base_hard_reset_handler()
mpt3sas_wait_for_commands_to_complete()
scsi_host_busy(ioc->shost)
blk_mq_tagset_busy_iter() <-- use-after-free / NULL dereference
mpt3sas_base_detach(ioc)
mpt3sas_base_free_resources(ioc)
mutex_lock(&ioc->pci_access_mutex)
Acquiring ioc->pci_access_mutex around setting ioc->remove_host = 1 in
scsih_remove(), or synchronizing with in-flight ioctls before
sas_remove_host(), would prevent teardown from racing with an active ioctl.
[ ... ]
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index a77bbc3d2b666..b30a215141c35 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> @@ -13496,11 +13496,12 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> return -ENODEV;
> }
>
> + /* shost must be valid before the ioc becomes visible to ioctls */
> + ioc->shost = shost;
> INIT_LIST_HEAD(&ioc->list);
> spin_lock(&gioc_lock);
> list_add_tail(&ioc->list, &mpt3sas_ioc_list);
> spin_unlock(&gioc_lock);
> - ioc->shost = shost;
> ioc->pdev = pdev;
> ioc->scsi_io_cb_idx = scsi_io_cb_idx;
> ioc->tm_cb_idx = tm_cb_idx;
[Severity: Medium]
Can an ioctl on /dev/mpt3ctl or /dev/mpt2ctl access ioc before _scsih_probe()
has initialized its mutexes and fields?
In _mpt3sas_init(), mpt3sas_ctl_init() registers the misc devices before
pci_register_driver() runs, and the device nodes remain active across hotplug
events. Because scsi_host_alloc() sets shost->shost_state to SHOST_CREATED,
scsi_host_get(ioc->shost) in _ctl_verify_adapter() succeeds as soon as ioc is
added to mpt3sas_ioc_list:
CPU0 CPU1
_scsih_probe()
ioc->shost = shost;
list_add_tail(&ioc->list,
&mpt3sas_ioc_list);
_ctl_ioctl_main()
_ctl_verify_adapter()
scsi_host_get(ioc->shost)
mutex_lock(&ioc->pci_access_mutex)
<-- uninitialized mutex
if (ioc->is_driver_loading || ...)
// still 0
mutex_lock(&ioc->ctl_cmds.mutex)
<-- uninitialized mutex
ioc->pdev = pdev;
...
mutex_init(&ioc->pci_access_mutex);
...
ioc->is_driver_loading = 1;
mpt3sas_base_attach(ioc);
mutex_init(&ioc->ctl_cmds.mutex);
At the point list_add_tail() publishes ioc, ioc->pdev is still NULL,
ioc->pci_access_mutex has not been initialized, ioc->is_driver_loading is
still 0 (until after alloc_ordered_workqueue()), and ioc->ctl_cmds.mutex is
not initialized until mpt3sas_base_attach(). Adding ioc to mpt3sas_ioc_list
only after ioc->pci_access_mutex is initialized and ioc->is_driver_loading is
set to 1 (or after mpt3sas_base_attach() succeeds) would close this window.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=3
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 23/37] scsi: mpt3sas: Validate phy_number in mpt3sas_transport_update_links
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:42 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] scsi: mpt3sas: mpt3sas_transport_update_links() breaks
disabling HBA phys
- [Low] scsi: mpt3sas: missing Fixes trailer for
mpt3sas_transport_update_links() fix
--
commit c51193b4a92bbce96daf63111a51b7401382049e
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Validate phy_number in mpt3sas_transport_update_links
>
> Check phy_number against sas_node->num_phys before indexing the phy
> array.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
Should this bug fix include a Fixes tag:
Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS")
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c
> index e88205b69067f..5f087d0b4d7a9 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
> @@ -1176,6 +1176,11 @@ mpt3sas_transport_update_links(struct MPT3SAS_ADAPTER *ioc,
> return;
> }
>
> + if (phy_number >= sas_node->num_phys) {
> + spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
> + return;
> + }
> +
> mpt3sas_phy = &sas_node->phy[phy_number];
> mpt3sas_phy->attached_handle = handle;
> spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
[Severity: Medium]
Does this regression break disabling excess HBA phys in
_scsih_sas_host_refresh()?
When HBA firmware is downgraded to an image exposing fewer phys,
_scsih_sas_port_refresh() updates ioc->sas_hba.num_phys to the lower count,
and _scsih_sas_host_refresh() then disables the remaining allocated phys:
drivers/scsi/mpt3sas/mpt3sas_scsih.c:_scsih_sas_host_refresh() {
...
for (i = ioc->sas_hba.num_phys;
i < ioc->sas_hba.nr_phys_allocated; i++) {
if (ioc->sas_hba.phy[i].phy &&
ioc->sas_hba.phy[i].phy->negotiated_linkrate >=
SAS_LINK_RATE_1_5_GBPS)
mpt3sas_transport_update_links(ioc,
ioc->sas_hba.sas_address, 0, i,
MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED, NULL);
}
}
Because sas_node is &ioc->sas_hba here and i starts at sas_node->num_phys,
every call in this loop now returns early without clearing attached_handle,
remote_identify, or negotiated_linkrate on the disabled phys.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=23
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 26/37] scsi: mpt3sas: Enforce minimum reply frame size and validate chain segment size
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:46 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
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
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 36/37] scsi: mpt3sas: Bound NVMe passthrough transfer size against PRP buffer capacity
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:47 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for commit aff39e61218f
--
commit dcbf2f39152738ac023acb7b93f4568b59a44fcd
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Bound NVMe passthrough transfer size against PRP buffer capacity
>
> The NVMe ioctl passthrough path builds a PRP list into a fixed per-command
> buffer sized as sg_tablesize * page_size. Reject requests where either
> data_in_size or data_out_size exceeds that limit to prevent overrunning
> the buffer and corrupting adjacent DMA allocations.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
This fixes an unbounded DMA buffer overrun in the NVMe encapsulated
request handler introduced in aff39e61218f ("scsi: mpt3sas: Added
support for nvme encapsulated request message."). Should the commit
message include:
Fixes: aff39e61218f ("scsi: mpt3sas: Added support for nvme encapsulated request message.")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=36
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 34/37] scsi: mpt3sas: Release sas_device reference on error in mpt3sas_transport_port_add
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 10:51 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: mpt3sas: missing Fixes trailer for sas_device refcount
leak fix
--
commit 0205a572d96fdf5a63e44438539df3b46769fba0
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> scsi: mpt3sas: Release sas_device reference on error in mpt3sas_transport_port_add
>
> The reference taken by mpt3sas_get_sdev_by_addr() is never released on
> error paths that branch to out_fail. Add sas_device_put() there to
> prevent a reference count leak.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
[Severity: Low]
7d310f241001 ("scsi: mpt3sas: Get device objects using sas_address &
portID") moved mpt3sas_get_sdev_by_addr() ahead of error checks that jump
to out_fail, and d3c577724f156 ("scsi: mpt3sas: Fix NULL pointer access in
mpt3sas_transport_port_add()") added error jumps to out_delete_port before
sas_device_put() is called. Should this include:
Fixes: 7d310f241001 ("scsi: mpt3sas: Get device objects using sas_address & portID")
Fixes: d3c57724f156 ("scsi: mpt3sas: Fix NULL pointer access in mpt3sas_transport_port_add()")
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=34
^ permalink raw reply [flat|nested] 68+ messages in thread
* Re: [PATCH v2 16/37] scsi: mpt3sas: Fix page fault from stale ioc->chip after PCI error recovery
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
0 siblings, 0 replies; 68+ messages in thread
From: sashiko-bot @ 2026-11-18 11:01 UTC (permalink / raw)
To: Shivasharan S, linux-scsi
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] scsi: mpt3sas: NULL ioc->chip dereference in
mpt3sas_scsih_issue_tm()
- [Medium] scsi: mpt3sas: NULL ioc->chip dereference in
_ctl_ioctl_main() paths
- [Medium] scsi: mpt3sas: race on ioc->chip unmap in hard reset and
config paths
--
commit a0d3f2d15f67ea6a7bb531279de17b869e022f10
Author: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
scsi: mpt3sas: Fix page fault from stale ioc->chip after PCI error recovery
This commit clears ioc->chip when unmapping controller resources and adds
NULL checks on ioc->chip across interrupt masking, IOC state queries, reset
handling, config requests, and shutdown paths.
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 24b74760d6816..cf7861a4068fc 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
[ ... ]
> @@ -3579,6 +3583,7 @@ mpt3sas_base_unmap_resources(struct MPT3SAS_ADAPTER *ioc)
>
> if (ioc->chip_phys) {
> iounmap(ioc->chip);
> + ioc->chip = NULL;
> ioc->chip_phys = 0;
> }
>
[Severity: Medium]
Can _ctl_ioctl_main() still reach ioc->put_smid_default() and dereference a
NULL ioc->chip when controller registers are unmapped?
In scsih_pci_slot_reset(), ioc->pci_error_recovery is cleared to 0 before
calling mpt3sas_base_map_resources(ioc); if mapping fails (or if the
adapter is suspended via scsih_suspend()), ioc->chip remains NULL while
ioc->pci_error_recovery, ioc->shost_recovery, ioc->is_driver_loading, and
ioc->remove_host are all 0. _ctl_ioctl_main() only checks those four flags,
so ioctls such as MPT3EVENTENABLE (_ctl_eventenable() ->
mpt3sas_base_validate_event_type() -> _base_event_notification()) and
MPT3DIAGREADBUFFER with MPT3_FLAGS_REREGISTER (_ctl_diag_read_buffer())
proceed without checking ioc->chip or IOC state and call
ioc->put_smid_default(), which writes to ioc->chip registers.
[ ... ]
> @@ -6739,6 +6746,15 @@ mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER *ioc, int cooked)
> {
> u32 s, sc;
>
> + /*
> + * Registers are unmapped (e.g. after PCI error recovery/suspend).
> + * Return a state value that matches no real IOC state, so callers
> + * neither treat the IOC as FAULT (and try a register-based diag
> + * reset) nor as READY/OPERATIONAL.
> + */
> + if (!ioc->chip)
> + return MPI2_IOC_STATE_MASK;
> +
> s = ioc->base_readl_ext_retry(&ioc->chip->Doorbell);
> sc = s & MPI2_IOC_STATE_MASK;
> return cooked ? sc : s;
[Severity: High]
Does returning MPI2_IOC_STATE_MASK here cause mpt3sas_scsih_issue_tm() to
fall through and dereference a NULL ioc->chip during SCSI error recovery?
When in-flight SCSI commands time out after scsih_pci_slot_reset() clears
ioc->pci_error_recovery = 0 and fails in mpt3sas_base_map_resources(ioc),
the SCSI error handler runs eh_abort_handler, eh_device_reset_handler, and
eh_target_reset_handler before escalating to eh_host_reset_handler. Those
callbacks invoke mpt3sas_scsih_issue_tm(), which only checks for
MPI2_DOORBELL_USED, MPI2_IOC_STATE_FAULT, and MPI2_IOC_STATE_COREDUMP:
drivers/scsi/mpt3sas/mpt3sas_scsih.c:mpt3sas_scsih_issue_tm() {
...
ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
if (ioc_state & MPI2_DOORBELL_USED) {
...
}
if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
...
} else if ((ioc_state & MPI2_IOC_STATE_MASK) ==
MPI2_IOC_STATE_COREDUMP) {
...
}
smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
...
ioc->put_smid_hi_priority(ioc, smid, msix_task);
...
}
Because MPI2_IOC_STATE_MASK matches none of those conditions,
mpt3sas_scsih_issue_tm() falls through and calls
ioc->put_smid_hi_priority(), dereferencing NULL ioc->chip (and scsih_abort()
also calls mpt3sas_halt_firmware(ioc) before checking ioc->chip).
> @@ -8136,7 +8152,7 @@ mpt3sas_base_make_ioc_ready(struct MPT3SAS_ADAPTER *ioc, enum reset_type type)
>
> dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__));
>
> - if (ioc->pci_error_recovery)
> + if (ioc->pci_error_recovery || !ioc->chip)
> return 0;
>
> ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
> @@ -8969,6 +8985,13 @@ mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER *ioc,
> goto out_unlocked;
> }
>
> + if (!ioc->chip) {
> + ioc_err(ioc, "%s: controller registers are not mapped\n",
> + __func__);
> + r = -ENODEV;
> + goto out_unlocked;
> + }
> +
> if (mpt3sas_fwfault_debug)
> mpt3sas_halt_firmware(ioc);
>
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c
> index eb51ce3610c8a..2609b298af0b2 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_config.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_config.c
> @@ -304,6 +304,10 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
> struct config_request mem;
> u32 ioc_status = UINT_MAX;
>
> + /* registers are unmapped (e.g. after PCI error recovery/suspend) */
> + if (!ioc->chip)
> + return -ENODEV;
> +
> mutex_lock(&ioc->config_cmds.mutex);
> if (ioc->config_cmds.status != MPT3_CMD_NOT_USED) {
> ioc_err(ioc, "%s: config_cmd in use\n", __func__);
[Severity: Medium]
Can mpt3sas_base_free_resources() unmap and clear ioc->chip after the
!ioc->chip checks in mpt3sas_base_hard_reset_handler() and
_config_request()?
CPU0 CPU1
mpt3sas_base_hard_reset_handler()
if (!ioc->chip)
mutex_lock(&ioc->reset_in_progress_mutex)
...
mpt3sas_wait_for_commands_to_complete()
scsih_pci_error_detected()
mpt3sas_base_free_resources()
mutex_lock(&ioc->pci_access_mutex)
mpt3sas_base_unmap_resources()
iounmap(ioc->chip)
ioc->chip = NULL
mutex_unlock(&ioc->pci_access_mutex)
mpt3sas_base_make_ioc_ready()
if (... || !ioc->chip)
return 0;
_base_get_ioc_facts()
_base_handshake_req_reply_wait()
ioc->base_readl(&ioc->chip->Doorbell)
<-- NULL pointer dereference
mpt3sas_base_free_resources() serializes only with ioc->pci_access_mutex,
which neither mpt3sas_base_hard_reset_handler() nor _config_request() holds.
When mpt3sas_base_make_ioc_ready() returns 0 for !ioc->chip,
mpt3sas_base_hard_reset_handler() treats the controller as ready and
proceeds into _base_get_ioc_facts(), dereferencing NULL ioc->chip.
Similarly, _config_request() checks !ioc->chip before acquiring
ioc->config_cmds.mutex and can race with mpt3sas_base_free_resources()
before calling ioc->put_smid_default().
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794995806-5835-1-git-send-email-shivasharan.srikanteshwara@broadcom.com?part=16
^ permalink raw reply [flat|nested] 68+ messages in thread
end of thread, other threads:[~2026-11-18 11:01 UTC | newest]
Thread overview: 68+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox