diff options
| author | tom.leiming@gmail.com <tom.leiming@gmail.com> | 2012-03-21 23:22:18 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-04-02 12:27:17 -0400 |
| commit | 27c3e5f205c085075547cb376bdae37693bd7090 (patch) | |
| tree | 5ad033404f5033a6052cad80e93abed06a638a7e /drivers/net/usb | |
| parent | 77d77ab09b1b57cf3cc30d0dbdf8c55137146a8f (diff) | |
usbnet: increase URB reference count before usb_unlink_urb
commit 0956a8c20b23d429e79ff86d4325583fc06f9eb4 upstream.
Commit 4231d47e6fe69f061f96c98c30eaf9fb4c14b96d(net/usbnet: avoid
recursive locking in usbnet_stop()) fixes the recursive locking
problem by releasing the skb queue lock, but it makes usb_unlink_urb
racing with defer_bh, and the URB to being unlinked may be freed before
or during calling usb_unlink_urb, so use-after-free problem may be
triggerd inside usb_unlink_urb.
The patch fixes the use-after-free problem by increasing URB
reference count with skb queue lock held before calling
usb_unlink_urb, so the URB won't be freed until return from
usb_unlink_urb.
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Oliver Neukum <oliver@neukum.org>
Reported-by: Dave Jones <davej@redhat.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/net/usb')
| -rw-r--r-- | drivers/net/usb/usbnet.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index 4918cf54c47..9f9e5876bdf 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c | |||
| @@ -585,6 +585,14 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q) | |||
| 585 | entry = (struct skb_data *) skb->cb; | 585 | entry = (struct skb_data *) skb->cb; |
| 586 | urb = entry->urb; | 586 | urb = entry->urb; |
| 587 | 587 | ||
| 588 | /* | ||
| 589 | * Get reference count of the URB to avoid it to be | ||
| 590 | * freed during usb_unlink_urb, which may trigger | ||
| 591 | * use-after-free problem inside usb_unlink_urb since | ||
| 592 | * usb_unlink_urb is always racing with .complete | ||
| 593 | * handler(include defer_bh). | ||
| 594 | */ | ||
| 595 | usb_get_urb(urb); | ||
| 588 | spin_unlock_irqrestore(&q->lock, flags); | 596 | spin_unlock_irqrestore(&q->lock, flags); |
| 589 | // during some PM-driven resume scenarios, | 597 | // during some PM-driven resume scenarios, |
| 590 | // these (async) unlinks complete immediately | 598 | // these (async) unlinks complete immediately |
| @@ -593,6 +601,7 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q) | |||
| 593 | netdev_dbg(dev->net, "unlink urb err, %d\n", retval); | 601 | netdev_dbg(dev->net, "unlink urb err, %d\n", retval); |
| 594 | else | 602 | else |
| 595 | count++; | 603 | count++; |
| 604 | usb_put_urb(urb); | ||
| 596 | spin_lock_irqsave(&q->lock, flags); | 605 | spin_lock_irqsave(&q->lock, flags); |
| 597 | } | 606 | } |
| 598 | spin_unlock_irqrestore (&q->lock, flags); | 607 | spin_unlock_irqrestore (&q->lock, flags); |
