usbnet: increase URB reference count before usb_unlink_urb
PATCH 1/2 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.
--- drivers/net/usb/usbnet.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/net/usb/usbnet.c +9 -0
@@ -589,6 +589,14 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q) entry = (struct skb_data *) skb->cb; urb = entry->urb; +/* +* Get reference count of the URB to avoid it to be +* freed during usb_unlink_urb, which may trigger +* use-after-free problem inside usb_unlink_urb since +* usb_unlink_urb is always racing with .complete +* handler(include defer_bh). +*/ +usb_get_urb (urb);spin_unlock_irqrestore (&q->lock, flags);// during some PM-driven resume scenarios, // these (async) unlinks complete immediately
@@ -597,6 +605,7 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)netdev_dbg (dev->net,"unlink urb err, %d\n" , retval); else count++; +usb_put_urb (urb);spin_lock_irqsave (&q->lock, flags); }spin_unlock_irqrestore (&q->lock, flags);
Signature · 6 lines
1.7.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Ming Lei
Commit 4231d47e6fe69f061f96c98c30eaf9fb4c14b96d(net/usbnet: avoid recursive locking in
usbnet_stop()) fixes the recursive locking problem by releasing the skb queue lock, but it makesusb_unlink_urbracing withdefer_bh, and the URB to being unlinked may be freed before or during callingusb_unlink_urb, so use-after-free problem may be triggerd insideusb_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 fromusb_unlink_urb.
Quoted 6 lines
Cc Sebastian Andrzej Siewior <[email protected]>Cc Alan Stern <[email protected]>Cc Oliver Neukum <[email protected]>Reported-by Dave Jones <[email protected]>Signed-off-by Ming Lei <[email protected]>
A message that is not in the archive (sent off-list or not yet received): [email protected]
From: Greg Kroah-Hartman <[email protected]>
Date: Thu, 22 Mar 2012 07:35:53 -0700
Quoted 13 lines · Ming Lei
Quoted 12 lines
Commit 4231d47e6fe69f061f96c98c30eaf9fb4c14b96d(net/usbnet: avoid recursive locking in
usbnet_stop()) fixes the recursive locking problem by releasing the skb queue lock, but it makesusb_unlink_urbracing withdefer_bh, and the URB to being unlinked may be freed before or during callingusb_unlink_urb, so use-after-free problem may be triggerd insideusb_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 fromusb_unlink_urb.
Quoted 8 lines
Quoted 6 lines
Cc Sebastian Andrzej Siewior <[email protected]>Cc Alan Stern <stern-nwvwT67g6+6dFdvTe/[email protected]>Cc Oliver Neukum <[email protected]>Reported-by Dave Jones <[email protected]>Signed-off-by Ming Lei <[email protected]>
Applied.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html