* [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers
@ 2026-04-29 9:44 Oliver Neukum
0 siblings, 0 replies; 5+ messages in thread
From: Oliver Neukum @ 2026-04-29 9:44 UTC (permalink / raw)
To: gregkh, stern, xu.yang_2, linux-usb; +Cc: Oliver Neukum
From within the SCSI error handler memory allocations must not
trigger IO. Handling errors in UAS and the storage driver may
involve resetting a device. The thread doing the reset itself
relies on VM magic. However, that is insufficient, as resetting
a device involves resuming it. Resumption as well as resetting
involves conrol transfers to the parent of the device to be reset.
That may be a root hub. Hence usbcore must heed the flags passed
to usb_submit_urb() processing control transfers to root hubs.
The problem exist since the storage driver has been merged.
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
drivers/usb/core/hcd.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 89221f1ce769..29c74ed40526 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -448,7 +448,8 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len)
/* Root hub control transfers execute synchronously */
-static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
+static int rh_call_control(struct usb_hcd *hcd,
+ struct urb *urb, gfp_t mem_flags)
{
struct usb_ctrlrequest *cmd;
u16 typeReq, wValue, wIndex, wLength;
@@ -483,8 +484,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
* tbuf should be at least as big as the
* USB hub descriptor.
*/
- tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
- tbuf = kzalloc(tbuf_size, GFP_KERNEL);
+ tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
+ tbuf = kzalloc(tbuf_size, mem_flags);
if (!tbuf) {
status = -ENOMEM;
goto err_alloc;
@@ -809,12 +810,13 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
return retval;
}
-static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
+static int rh_urb_enqueue(struct usb_hcd *hcd,
+ struct urb *urb, gfp_t mem_flags)
{
if (usb_endpoint_xfer_int(&urb->ep->desc))
return rh_queue_status (hcd, urb);
if (usb_endpoint_xfer_control(&urb->ep->desc))
- return rh_call_control (hcd, urb);
+ return rh_call_control(hcd, urb, mem_flags);
return -EINVAL;
}
@@ -1535,7 +1537,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
*/
if (is_root_hub(urb->dev)) {
- status = rh_urb_enqueue(hcd, urb);
+ status = rh_urb_enqueue(hcd, urb, mem_flags);
} else {
status = map_urb_for_dma(hcd, urb, mem_flags);
if (likely(status == 0)) {
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers
2026-04-25 2:12 [syzbot] [usb?] memory leak in hub_event (4) syzbot
@ 2026-04-29 10:42 ` Oliver Neukum
2026-04-29 19:04 ` Alan Stern
0 siblings, 1 reply; 5+ messages in thread
From: Oliver Neukum @ 2026-04-29 10:42 UTC (permalink / raw)
To: syzbot+2afd7e71155c7e241560; +Cc: linux-usb, tiwai, Oliver Neukum
From within the SCSI error handler memory allocations must not
trigger IO. Handling errors in UAS and the storage driver may
involve resetting a device. The thread doing the reset itself
relies on VM magic. However, that is insufficient, as resetting
a device involves resuming it. Resumption as well as resetting
involves conrol transfers to the parent of the device to be reset.
That may be a root hub. Hence usbcore must heed the flags passed
to usb_submit_urb() processing control transfers to root hubs.
The problem exist since the storage driver has been merged.
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
drivers/usb/core/hcd.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 89221f1ce769..29c74ed40526 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -448,7 +448,8 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len)
/* Root hub control transfers execute synchronously */
-static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
+static int rh_call_control(struct usb_hcd *hcd,
+ struct urb *urb, gfp_t mem_flags)
{
struct usb_ctrlrequest *cmd;
u16 typeReq, wValue, wIndex, wLength;
@@ -483,8 +484,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
* tbuf should be at least as big as the
* USB hub descriptor.
*/
- tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
- tbuf = kzalloc(tbuf_size, GFP_KERNEL);
+ tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
+ tbuf = kzalloc(tbuf_size, mem_flags);
if (!tbuf) {
status = -ENOMEM;
goto err_alloc;
@@ -809,12 +810,13 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
return retval;
}
-static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
+static int rh_urb_enqueue(struct usb_hcd *hcd,
+ struct urb *urb, gfp_t mem_flags)
{
if (usb_endpoint_xfer_int(&urb->ep->desc))
return rh_queue_status (hcd, urb);
if (usb_endpoint_xfer_control(&urb->ep->desc))
- return rh_call_control (hcd, urb);
+ return rh_call_control(hcd, urb, mem_flags);
return -EINVAL;
}
@@ -1535,7 +1537,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
*/
if (is_root_hub(urb->dev)) {
- status = rh_urb_enqueue(hcd, urb);
+ status = rh_urb_enqueue(hcd, urb, mem_flags);
} else {
status = map_urb_for_dma(hcd, urb, mem_flags);
if (likely(status == 0)) {
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers
2026-04-29 10:42 ` [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers Oliver Neukum
@ 2026-04-29 19:04 ` Alan Stern
2026-04-29 19:13 ` Oliver Neukum
0 siblings, 1 reply; 5+ messages in thread
From: Alan Stern @ 2026-04-29 19:04 UTC (permalink / raw)
To: Oliver Neukum; +Cc: syzbot+2afd7e71155c7e241560, linux-usb, tiwai
On Wed, Apr 29, 2026 at 12:42:06PM +0200, Oliver Neukum wrote:
> From within the SCSI error handler memory allocations must not
> trigger IO. Handling errors in UAS and the storage driver may
> involve resetting a device. The thread doing the reset itself
> relies on VM magic. However, that is insufficient, as resetting
> a device involves resuming it. Resumption as well as resetting
> involves conrol transfers to the parent of the device to be reset.
> That may be a root hub. Hence usbcore must heed the flags passed
> to usb_submit_urb() processing control transfers to root hubs.
The SCSI core prevents devices from suspending while they are in use.
If the error handler wants to do a reset (or if a USB transfer fails and
the driver does a reset to recover), the device won't be in runtime
suspend at the time, and so neither will its root hub.
Besides, even if a resume was necessary, wouldn't the same VM magic that
works for the reset thread also work for the resume? After all, they
will be the same thread; the usb_autoresume_device() call in
usb_reset_device() is synchronous and it is called after
memalloc_noio_save().
Alan Stern
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers
2026-04-29 19:04 ` Alan Stern
@ 2026-04-29 19:13 ` Oliver Neukum
2026-04-29 19:18 ` Alan Stern
0 siblings, 1 reply; 5+ messages in thread
From: Oliver Neukum @ 2026-04-29 19:13 UTC (permalink / raw)
To: Alan Stern, Oliver Neukum; +Cc: linux-usb, tiwai
On 29.04.26 21:04, Alan Stern wrote:
> Besides, even if a resume was necessary, wouldn't the same VM magic that
> works for the reset thread also work for the resume? After all, they
They need not be the same thread. That is the point. usb_reset_device()
does a resume. However, it is possible for this to race with another thread
doing a resume or a suspend. In that case it will block and wait for
another thread. Hence we essentially get priority inversion more or
less.
Regards
Oliver
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers
2026-04-29 19:13 ` Oliver Neukum
@ 2026-04-29 19:18 ` Alan Stern
0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2026-04-29 19:18 UTC (permalink / raw)
To: Oliver Neukum; +Cc: linux-usb, tiwai
On Wed, Apr 29, 2026 at 09:13:59PM +0200, Oliver Neukum wrote:
> On 29.04.26 21:04, Alan Stern wrote:
>
> > Besides, even if a resume was necessary, wouldn't the same VM magic that
> > works for the reset thread also work for the resume? After all, they
>
> They need not be the same thread. That is the point. usb_reset_device()
> does a resume. However, it is possible for this to race with another thread
> doing a resume or a suspend. In that case it will block and wait for
> another thread. Hence we essentially get priority inversion more or
> less.
Okay, I see. Good point. You should include this in the patch
description.
Alan Stern
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-29 19:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-29 9:44 [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers Oliver Neukum
-- strict thread matches above, loose matches on Subject: below --
2026-04-25 2:12 [syzbot] [usb?] memory leak in hub_event (4) syzbot
2026-04-29 10:42 ` [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers Oliver Neukum
2026-04-29 19:04 ` Alan Stern
2026-04-29 19:13 ` Oliver Neukum
2026-04-29 19:18 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox