[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251216060156.41320-1-qu@darknavy.com>
Date: Tue, 16 Dec 2025 14:01:53 +0800
From: Shipei Qu <qu@...knavy.com>
To: Adam Radford <aradford@...il.com>,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>
Cc: Shipei Qu <qu@...knavy.com>,
linux-scsi@...r.kernel.org,
linux-kernel@...r.kernel.org,
DARKNAVY <vr@...knavy.com>
Subject: [PATCH v2] scsi: 3w-sas: validate request_id reported by controller
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@...nel.org. 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@...knavy.com>
Signed-off-by: Shipei Qu <qu@...knavy.com>
---
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
Powered by blists - more mailing lists