[PATCH v2] scsi: 3w-sas: validate request_id reported by controller
From: Shipei Qu
Date: Tue Dec 16 2025 - 01:03:07 EST
Hi,
resending with a correctly generated diff (the previous email had a malformed
patch header). The content is unchanged: while testing 3w-sas with an emulated
3ware 9750-compatible controller we noticed that the driver trusts the
request_id field reported by the controller in the completion path and uses it
as an index into several TW_Q_LENGTH-sized arrays without validating the range.
A bogus value can lead to out-of-bounds accesses and crashes.
For example, a malicious PCIe/Thunderbolt-attached device that emulates a
3ware controller can return crafted completions and drive the driver out of
bounds in this way. We have a small QEMU-based PoC that reproduces the problem
and can share it if that would be helpful.
This driver is enabled by default in common distributions (e.g. Ubuntu), so a
misbehaving or emulated controller can trigger this on a stock installation.
The same pattern is present in current mainline kernels.
This issue was first reported via security@xxxxxxxxxx. The kernel security team
replied that, under the usual upstream threat model (only trusted
PCIe/Thunderbolt devices are allowed to bind to such drivers), it should be
treated as a normal robustness bug rather than a security issue, and asked us
to send fixes to the relevant development lists. This email follows that
guidance.
The fix is to reject out-of-range request_id values before indexing the
per-request arrays in the interrupt handler.
Reported-by: DARKNAVY (@DarkNavyOrg) <vr@xxxxxxxxxxxx>
Signed-off-by: Shipei Qu <qu@xxxxxxxxxxxx>
---
drivers/scsi/3w-sas.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index e319be7d3..4d1c31c04 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -1184,6 +1184,15 @@ static irqreturn_t twl_interrupt(int irq, void *dev_instance)
} else
request_id = TW_RESID_OUT(response);
+ if (request_id >= TW_Q_LENGTH) {
+ TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10,
+ "Received out-of-range request id %u",
+ request_id);
+ TWL_MASK_INTERRUPTS(tw_dev);
+ /* let the reset / error handling path deal with it */
+ goto twl_interrupt_bail;
+ }
+
full_command_packet = tw_dev->command_packet_virt[request_id];
/* Check for correct state */
--
2.45.1