diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2017-03-24 13:38:28 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-04-08 03:30:34 -0400 |
commit | 67e41b1368b146ff6508a4efe5552400412d2f32 (patch) | |
tree | 969f81d050866fd8687f7b0499ee530781b506a3 /drivers/usb | |
parent | 1f1c9e29651df61516b028c58632124b345ec85b (diff) |
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>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/core/hcd.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 479e223f9cff..f029aad67183 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -520,8 +520,10 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
520 | */ | 520 | */ |
521 | tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength); | 521 | tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength); |
522 | tbuf = kzalloc(tbuf_size, GFP_KERNEL); | 522 | tbuf = kzalloc(tbuf_size, GFP_KERNEL); |
523 | if (!tbuf) | 523 | if (!tbuf) { |
524 | return -ENOMEM; | 524 | status = -ENOMEM; |
525 | goto err_alloc; | ||
526 | } | ||
525 | 527 | ||
526 | bufp = tbuf; | 528 | bufp = tbuf; |
527 | 529 | ||
@@ -734,6 +736,7 @@ error: | |||
734 | } | 736 | } |
735 | 737 | ||
736 | kfree(tbuf); | 738 | kfree(tbuf); |
739 | err_alloc: | ||
737 | 740 | ||
738 | /* any errors get returned through the urb completion */ | 741 | /* any errors get returned through the urb completion */ |
739 | spin_lock_irq(&hcd_root_hub_lock); | 742 | spin_lock_irq(&hcd_root_hub_lock); |