From: Shipei Qu <qu@darknavy.com>
To: Adam Radford <aradford@gmail.com>,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Shipei Qu <qu@darknavy.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
DARKNAVY <vr@darknavy.com>
Subject: [PATCH v2] scsi: 3w-sas: validate request_id reported by controller
Date: Tue, 16 Dec 2025 14:01:53 +0800 [thread overview]
Message-ID: <20251216060156.41320-1-qu@darknavy.com> (raw)
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@kernel.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@darknavy.com>
Signed-off-by: Shipei Qu <qu@darknavy.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
next reply other threads:[~2025-12-16 6:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 6:01 Shipei Qu [this message]
2025-12-16 6:18 ` James Bottomley
2025-12-16 6:43 ` Shipei Qu
2025-12-16 7:03 ` James Bottomley
2025-12-20 14:00 ` kernel test robot
2025-12-20 14:34 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251216060156.41320-1-qu@darknavy.com \
--to=qu@darknavy.com \
--cc=aradford@gmail.com \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=vr@darknavy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®