Skip to content

Commit fc834e6

Browse files
AlanSterngregkh
authored andcommitted
USB: dummy-hcd: Fix failure to give back unlinked URBs
The syzkaller USB fuzzer identified a failure mode in which dummy-hcd would never give back an unlinked URB. This causes usb_kill_urb() to hang, leading to WARNINGs and unkillable threads. In dummy-hcd, all URBs are given back by the dummy_timer() routine as it scans through the list of pending URBS. Failure to give back URBs can be caused by failure to start or early exit from the scanning loop. The code currently has two such pathways: One is triggered when an unsupported bus transfer speed is encountered, and the other by exhausting the simulated bandwidth for USB transfers during a frame. This patch removes those two paths, thereby allowing all unlinked URBs to be given back in a timely manner. It adds a check for the bus speed when the gadget first starts running, so that dummy_timer() will never thereafter encounter an unsupported speed. And it prevents the loop from exiting as soon as the total bandwidth has been used up (the scanning loop continues, giving back unlinked URBs as they are found, but not transferring any more data). Thanks to Andrey Konovalov for manually running the syzkaller fuzzer to help track down the source of the bug. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Reported-and-tested-by: syzbot+d919b0f29d7b5a4994b9@syzkaller.appspotmail.com CC: <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c01c348 commit fc834e6

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎drivers/usb/gadget/udc/dummy_hcd.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,18 @@ static int dummy_udc_start(struct usb_gadget *g,
979979
struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
980980
struct dummy *dum = dum_hcd->dum;
981981

982-
if (driver->max_speed == USB_SPEED_UNKNOWN)
982+
switch (g->speed) {
983+
/* All the speeds we support */
984+
case USB_SPEED_LOW:
985+
case USB_SPEED_FULL:
986+
case USB_SPEED_HIGH:
987+
case USB_SPEED_SUPER:
988+
break;
989+
default:
990+
dev_err(dummy_dev(dum_hcd), "Unsupported driver max speed %d\n",
991+
driver->max_speed);
983992
return -EINVAL;
993+
}
984994

985995
/*
986996
* SLAVE side init ... the layer above hardware, which
@@ -1784,9 +1794,10 @@ static void dummy_timer(struct timer_list *t)
17841794
/* Bus speed is 500000 bytes/ms, so use a little less */
17851795
total = 490000;
17861796
break;
1787-
default:
1797+
default: /* Can't happen */
17881798
dev_err(dummy_dev(dum_hcd), "bogus device speed\n");
1789-
return;
1799+
total = 0;
1800+
break;
17901801
}
17911802

17921803
/* FIXME if HZ != 1000 this will probably misbehave ... */
@@ -1828,7 +1839,7 @@ static void dummy_timer(struct timer_list *t)
18281839

18291840
/* Used up this frame's bandwidth? */
18301841
if (total <= 0)
1831-
break;
1842+
continue;
18321843

18331844
/* find the gadget's ep for this request (if configured) */
18341845
address = usb_pipeendpoint (urb->pipe);

0 commit comments

Comments
 (0)