netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] usbnet: increase URB reference count before usb_unlink_urb
@ 2012-03-22 13:22 Ming Lei
  2012-03-22 14:35 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Ming Lei @ 2012-03-22 13:22 UTC (permalink / raw)
  To: David S. Miller, Greg Kroah-Hartman
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	Ming Lei, stable-DgEjT+Ai2ygdnm+yROfE0A,
	Sebastian Andrzej Siewior, Alan Stern, Oliver Neukum

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-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Cc: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
Cc: Oliver Neukum <oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
Reported-by: Dave Jones <davej-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Ming Lei <tom.leiming-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 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 4b8b52c..febfdce 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)
 		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);
-- 
1.7.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] usbnet: increase URB reference count before usb_unlink_urb
  2012-03-22 13:22 [PATCH 1/2] usbnet: increase URB reference count before usb_unlink_urb Ming Lei
@ 2012-03-22 14:35 ` Greg Kroah-Hartman
       [not found]   ` <20120322143553.GC19835-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2012-03-22 14:35 UTC (permalink / raw)
  To: Ming Lei
  Cc: David S. Miller, netdev, linux-usb, stable,
	Sebastian Andrzej Siewior, Alan Stern, Oliver Neukum

On Thu, Mar 22, 2012 at 09:22:18PM +0800, Ming Lei wrote:
> 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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] usbnet: increase URB reference count before usb_unlink_urb
       [not found]   ` <20120322143553.GC19835-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
@ 2012-03-22 23:33     ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2012-03-22 23:33 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r
  Cc: tom.leiming-Re5JQEeQqe8AvxtiuMwx3w,
	netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	stable-DgEjT+Ai2ygdnm+yROfE0A, bigeasy-hfZtesqFncYOwBW4kG4KsQ,
	stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz,
	oliver-GvhC2dPhHPQdnm+yROfE0A

From: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
Date: Thu, 22 Mar 2012 07:35:53 -0700

> On Thu, Mar 22, 2012 at 09:22:18PM +0800, Ming Lei wrote:
>> 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-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
>> Cc: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
>> Cc: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
>> Cc: Oliver Neukum <oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
>> Reported-by: Dave Jones <davej-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> Signed-off-by: Ming Lei <tom.leiming-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> 
> Acked-by: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-03-22 23:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-22 13:22 [PATCH 1/2] usbnet: increase URB reference count before usb_unlink_urb Ming Lei
2012-03-22 14:35 ` Greg Kroah-Hartman
     [not found]   ` <20120322143553.GC19835-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2012-03-22 23:33     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).