Skip to content

Commit eac3ab3

Browse files
AlanSterngregkh
authored andcommitted
USB: fix linked-list corruption in rh_call_control()
commit 1633682053a7ee8058e10c76722b9b28e97fb73f upstream. Using KASAN, Dmitry found a bug in the rh_call_control() routine: If buffer allocation fails, the routine returns immediately without unlinking its URB from the control endpoint, eventually leading to linked-list corruption. This patch fixes the problem by jumping to the end of the routine (where the URB is unlinked) when an allocation failure occurs. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Reported-and-tested-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0a1757c commit eac3ab3

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

drivers/usb/core/hcd.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,10 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
499499
*/
500500
tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
501501
tbuf = kzalloc(tbuf_size, GFP_KERNEL);
502-
if (!tbuf)
503-
return -ENOMEM;
502+
if (!tbuf) {
503+
status = -ENOMEM;
504+
goto err_alloc;
505+
}
504506

505507
bufp = tbuf;
506508

@@ -705,6 +707,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
705707
}
706708

707709
kfree(tbuf);
710+
err_alloc:
708711

709712
/* any errors get returned through the urb completion */
710713
spin_lock_irq(&hcd_root_hub_lock);

0 commit comments

Comments
 (0)