diff options
author | tom.leiming@gmail.com <tom.leiming@gmail.com> | 2012-03-21 23:22:18 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-03-22 19:32:34 -0400 |
commit | 0956a8c20b23d429e79ff86d4325583fc06f9eb4 (patch) | |
tree | 65adc5a7fc8b19ca046ba661692a75a65fd04e88 /drivers | |
parent | 1265fd616782ef03b98fd19f65c2b47fcd4ea11f (diff) |
usbnet: increase URB reference count before usb_unlink_urb
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: stable@kernel.org
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>
Diffstat (limited to 'drivers')
-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 4b8b52ca09d8..febfdceeb9e5 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c | |||
@@ -589,6 +589,14 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q) | |||
589 | entry = (struct skb_data *) skb->cb; | 589 | entry = (struct skb_data *) skb->cb; |
590 | urb = entry->urb; | 590 | urb = entry->urb; |
591 | 591 | ||
592 | /* | ||
593 | * Get reference count of the URB to avoid it to be | ||
594 | * freed during usb_unlink_urb, which may trigger | ||
595 | * use-after-free problem inside usb_unlink_urb since | ||
596 | * usb_unlink_urb is always racing with .complete | ||
597 | * handler(include defer_bh). | ||
598 | */ | ||
599 | usb_get_urb(urb); | ||
592 | spin_unlock_irqrestore(&q->lock, flags); | 600 | spin_unlock_irqrestore(&q->lock, flags); |
593 | // during some PM-driven resume scenarios, | 601 | // during some PM-driven resume scenarios, |
594 | // these (async) unlinks complete immediately | 602 | // these (async) unlinks complete immediately |
@@ -597,6 +605,7 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q) | |||
597 | netdev_dbg(dev->net, "unlink urb err, %d\n", retval); | 605 | netdev_dbg(dev->net, "unlink urb err, %d\n", retval); |
598 | else | 606 | else |
599 | count++; | 607 | count++; |
608 | usb_put_urb(urb); | ||
600 | spin_lock_irqsave(&q->lock, flags); | 609 | spin_lock_irqsave(&q->lock, flags); |
601 | } | 610 | } |
602 | spin_unlock_irqrestore (&q->lock, flags); | 611 | spin_unlock_irqrestore (&q->lock, flags); |