Commit 0eccbfbc authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

USB: fix linked-list corruption in rh_call_control()

commit 16336820 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: default avatarAlan Stern <stern@rowland.harvard.edu>
Reported-and-tested-by: default avatarDmitry Vyukov <dvyukov@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 21fd1700
...@@ -498,8 +498,10 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) ...@@ -498,8 +498,10 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
*/ */
tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength); tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
tbuf = kzalloc(tbuf_size, GFP_KERNEL); tbuf = kzalloc(tbuf_size, GFP_KERNEL);
if (!tbuf) if (!tbuf) {
return -ENOMEM; status = -ENOMEM;
goto err_alloc;
}
bufp = tbuf; bufp = tbuf;
...@@ -702,6 +704,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) ...@@ -702,6 +704,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
} }
kfree(tbuf); kfree(tbuf);
err_alloc:
/* any errors get returned through the urb completion */ /* any errors get returned through the urb completion */
spin_lock_irq(&hcd_root_hub_lock); spin_lock_irq(&hcd_root_hub_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment