Skip to contentSkip to conversation

usb-storage: option_ms: bound probe-time bulk transfers

PATCH Superseded Lee Yongjun 4 participants 5 messages Oct 13 – Oct 21

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb-storage: option_ms: bound probe-time bulk transfers

The Option device initialization path issues bulk transfers without a timeout. If a device does not complete a transfer, the USB hub worker can remain blocked while holding the device mutex, causing usb_device_read() to hang.

Use the timeout-aware bulk transfer helper for the transfers in option_inquiry() and option_rezero(). This bounds the wait for each probe-time transfer to 30 seconds.

Tested with the syzbot C reproducer under QEMU/KVM. The patched kernel repeatedly completed USB device initialization attempts after approximately 30 seconds without triggering the previously observed hung-task warning.

This patch depends on Hongyu Xie's pending v3 series:
https://lore.kernel.org/r/[email protected]/

Fixes 32ebbe7b6ad4 ("USB: usb-storage: add filter to "option_ms" to leave unrecognized devices alone")
Reported-by [email protected]
Assisted-by LLM
---
 drivers/usb/storage/option_ms.c | 38 +++++++++++++++++----------------
 1 file changed, 20 insertions(+), 18 deletions(-)
drivers/usb/storage/option_ms.c +20 -18
index 7c0b05a36554..1f3d984d6932 100644
@@ -10,6 +10,7 @@
 #include <linux/usb.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/jiffies.h>
 
 #include "usb.h"
 #include "transport.h"
@@ -18,6 +19,7 @@
 
 #define ZCD_FORCE_MODEM			0x01
 #define ZCD_ALLOW_MS 			0x02
+#define OPTION_MS_PROBE_TIMEOUT		(30 * HZ)
 
 static unsigned int option_zero_cd = ZCD_FORCE_MODEM;
 module_param(option_zero_cd, uint, S_IRUGO | S_IWUSR);
@@ -44,9 +46,9 @@ static int option_rezero(struct us_data *us)
 		return USB_STOR_TRANSPORT_ERROR;
 
 	memcpy(buffer, rezero_msg, sizeof(rezero_msg));
-	result = usb_stor_bulk_transfer_buf(us,
-			us->send_bulk_pipe,
-			buffer, sizeof(rezero_msg), NULL);
+	result = usb_stor_bulk_transfer_buf_timeout(us, us->send_bulk_pipe,
+						    buffer, sizeof(rezero_msg), NULL,
+						    OPTION_MS_PROBE_TIMEOUT);
 	if (result != USB_STOR_XFER_GOOD) {
 		result = USB_STOR_XFER_ERROR;
 		goto out;
@@ -56,14 +58,14 @@ static int option_rezero(struct us_data *us)
 	 * Some of the devices need to be asked for a response, but we don't
 	 * care what that response is.
 	 */
-	usb_stor_bulk_transfer_buf(us,
-			us->recv_bulk_pipe,
-			buffer, RESPONSE_LEN, NULL);
+	usb_stor_bulk_transfer_buf_timeout(us, us->recv_bulk_pipe,
+					   buffer, RESPONSE_LEN, NULL,
+					   OPTION_MS_PROBE_TIMEOUT);
 
 	/* Read the CSW */
-	usb_stor_bulk_transfer_buf(us,
-			us->recv_bulk_pipe,
-			buffer, 13, NULL);
+	usb_stor_bulk_transfer_buf_timeout(us, us->recv_bulk_pipe,
+					   buffer, 13, NULL,
+					   OPTION_MS_PROBE_TIMEOUT);
 
 	result = USB_STOR_XFER_GOOD;
 
@@ -90,17 +92,17 @@ static int option_inquiry(struct us_data *us)
 		return USB_STOR_TRANSPORT_ERROR;
 
 	memcpy(buffer, inquiry_msg, sizeof(inquiry_msg));
-	result = usb_stor_bulk_transfer_buf(us,
-			us->send_bulk_pipe,
-			buffer, sizeof(inquiry_msg), NULL);
+	result = usb_stor_bulk_transfer_buf_timeout(us, us->send_bulk_pipe,
+						    buffer, sizeof(inquiry_msg), NULL,
+						    OPTION_MS_PROBE_TIMEOUT);
 	if (result != USB_STOR_XFER_GOOD) {
 		result = USB_STOR_XFER_ERROR;
 		goto out;
 	}
 
-	result = usb_stor_bulk_transfer_buf(us,
-			us->recv_bulk_pipe,
-			buffer, 0x24, NULL);
+	result = usb_stor_bulk_transfer_buf_timeout(us, us->recv_bulk_pipe,
+						    buffer, 0x24, NULL,
+						    OPTION_MS_PROBE_TIMEOUT);
 	if (result != USB_STOR_XFER_GOOD) {
 		result = USB_STOR_XFER_ERROR;
 		goto out;
@@ -112,9 +114,9 @@ static int option_inquiry(struct us_data *us)
 		result = memcmp(buffer+8, "ZCOPTION", 8);
 
 	/* Read the CSW */
-	usb_stor_bulk_transfer_buf(us,
-			us->recv_bulk_pipe,
-			buffer, 13, NULL);
+	usb_stor_bulk_transfer_buf_timeout(us, us->recv_bulk_pipe,
+					   buffer, 13, NULL,
+					   OPTION_MS_PROBE_TIMEOUT);
 
 out:
 	kfree(buffer);
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] usb-storage: build failure due to missing usb_stor_bulk_transfer_buf_timeout() dependency --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usb-storage: build failure due to missing usb_stor_bulk_transfer_buf_timeout() dependency --

commit 3551a3904408bdea1ed0fe7ef3aadc1aebde4e98
Author: Lee Yongjun <[email protected]>

usb-storage: option_ms: bound probe-time bulk transfers

This commit replaces bulk transfers in the option_ms initialization path with timeout-aware equivalents to prevent the USB hub worker from hanging indefinitely if a device stops responding. A 30-second timeout is introduced for transfers in option_inquiry() and option_rezero().

Quoted 4 lines
drivers/usb/storage/option_ms.c +0 -0
index 7c0b05a365543..1f3d984d69326 100644

[ ... ]

drivers/usb/storage/option_ms.c static int option_rezero(struct us_data *us) · line 51

Quoted 10 lines
drivers/usb/storage/option_ms.c +3 -3
@@ -44,9 +46,9 @@ static int option_rezero(struct us_data *us)
 		return USB_STOR_TRANSPORT_ERROR;
 
 	memcpy(buffer, rezero_msg, sizeof(rezero_msg));
-	result = usb_stor_bulk_transfer_buf(us,
-			us->send_bulk_pipe,
-			buffer, sizeof(rezero_msg), NULL);
+	result = usb_stor_bulk_transfer_buf_timeout(us, us->send_bulk_pipe,
+						    buffer, sizeof(rezero_msg), NULL,
+						    OPTION_MS_PROBE_TIMEOUT);

[Severity: High]
Does this cause a build failure? The new helper function usb_stor_bulk_transfer_buf_timeout() does not appear to be defined or declared anywhere in the current tree.

The commit message notes a dependency on a pending v3 series, but without that series applied, compiling drivers/usb/storage/option_ms.c results in an implicit function declaration and subsequent linker failure when the usb-storage driver is enabled.

Should this patch be held back from the tree until its dependencies are merged?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Lee Yongjun
Quoted 4 lines · Lee Yongjun

The Option device initialization path issues bulk transfers without a timeout. If a device does not complete a transfer, the USB hub worker can remain blocked while holding the device mutex, causing usb_device_read() to hang.

So a broken device?

Quoted 3 lines

Use the timeout-aware bulk transfer helper for the transfers in option_inquiry() and option_rezero(). This bounds the wait for each probe-time transfer to 30 seconds.

That feels very long, are you sure that works well?

Quoted 7 lines

Tested with the syzbot C reproducer under QEMU/KVM. The patched kernel repeatedly completed USB device initialization attempts after approximately 30 seconds without triggering the previously observed hung-task warning.

This patch depends on Hongyu Xie's pending v3 series:
https://lore.kernel.org/r/[email protected]/

This should go below the --- line and is why sashiko is confused.

Quoted 6 lines
Fixes 32ebbe7b6ad4 ("USB: usb-storage: add filter to "option_ms" to leave unrecognized devices alone")
Reported-by [email protected]
Assisted-by LLM

No blank line above here is needed.

thanks,

greg k-h

author
#3 lore raw
Quoted 1 line

So a broken device?

Yes, effectively. The reproducer emulates a USB device that completes enumeration but does not respond to the subsequent bulk OUT transfer. Without a timeout, the hub worker remains blocked while holding the device mutex, preventing other operations such as usb_device_read() from proceeding.

Quoted 1 line

That feels very long, are you sure that works well?

I've reduced the timeout to 5 seconds, using usb_modeswitch's 3 seconds timeout for similar bulk transfers as a reference, with some additional margin.
I retested with the syzkaller reproducer under QEMU, and initialization now proceeds after 5 seconds instead of 30.

Quoted 1 line

This should go below the --- line and is why sashiko is confused.

Thank you, I'll move the dependency note below the --- line

Quoted 1 line

No blank line above here is needed.

I'll remove the extra blank line.

Thanks for your review. I'll send v2 with these changes.

Lee Yongjun

2026년 10월 14일 (수) 오전 1:18, Greg KH <[email protected]>님이 작성:

Quoted 37 lines · Lee Yongjun
Quoted 4 lines

The Option device initialization path issues bulk transfers without a timeout. If a device does not complete a transfer, the USB hub worker can remain blocked while holding the device mutex, causing usb_device_read() to hang.

So a broken device?

Quoted 3 lines

Use the timeout-aware bulk transfer helper for the transfers in option_inquiry() and option_rezero(). This bounds the wait for each probe-time transfer to 30 seconds.

That feels very long, are you sure that works well?

Quoted 7 lines

Tested with the syzbot C reproducer under QEMU/KVM. The patched kernel repeatedly completed USB device initialization attempts after approximately 30 seconds without triggering the previously observed hung-task warning.

This patch depends on Hongyu Xie's pending v3 series:
https://lore.kernel.org/r/[email protected]/

This should go below the --- line and is why sashiko is confused.

Quoted 6 lines
Fixes 32ebbe7b6ad4 ("USB: usb-storage: add filter to "option_ms" to leave unrecognized devices alone")
Reported-by [email protected]
Assisted-by LLM

No blank line above here is needed.

thanks,

greg k-h

#4 lore raw
In reply to Greg KH
Quoted 7 lines · Greg KH
Quoted 4 lines · Lee Yongjun

The Option device initialization path issues bulk transfers without a timeout. If a device does not complete a transfer, the USB hub worker can remain blocked while holding the device mutex, causing usb_device_read() to hang.

So a broken device?

On a generic note, the SCSI layer is ready to deal with broken devices. In consequence, so have SCSI LLDs. We cannot hold a lock that will stall the SCSI layer in error handling indefinitely.

Regards
Oliver