This is a note to let you know that I've just added the patch titled

    USB: fix use-after-free bug in usb_hcd_unlink_urb()

to the 3.19-stable tree which can be found at:
    
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     usb-fix-use-after-free-bug-in-usb_hcd_unlink_urb.patch
and it can be found in the queue-3.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <[email protected]> know about it.


>From c99197902da284b4b723451c1471c45b18537cde Mon Sep 17 00:00:00 2001
From: Alan Stern <[email protected]>
Date: Fri, 30 Jan 2015 12:58:26 -0500
Subject: USB: fix use-after-free bug in usb_hcd_unlink_urb()

From: Alan Stern <[email protected]>

commit c99197902da284b4b723451c1471c45b18537cde upstream.

The usb_hcd_unlink_urb() routine in hcd.c contains two possible
use-after-free errors.  The dev_dbg() statement at the end of the
routine dereferences urb and urb->dev even though both structures may
have been deallocated.

This patch fixes the problem by storing urb->dev in a local variable
(avoiding the dereference of urb) and moving the dev_dbg() up before
the usb_put_dev() call.

Signed-off-by: Alan Stern <[email protected]>
Reported-by: Joe Lawrence <[email protected]>
Tested-by: Joe Lawrence <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 drivers/usb/core/hcd.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1618,6 +1618,7 @@ static int unlink1(struct usb_hcd *hcd,
 int usb_hcd_unlink_urb (struct urb *urb, int status)
 {
        struct usb_hcd          *hcd;
+       struct usb_device       *udev = urb->dev;
        int                     retval = -EIDRM;
        unsigned long           flags;
 
@@ -1629,20 +1630,19 @@ int usb_hcd_unlink_urb (struct urb *urb,
        spin_lock_irqsave(&hcd_urb_unlink_lock, flags);
        if (atomic_read(&urb->use_count) > 0) {
                retval = 0;
-               usb_get_dev(urb->dev);
+               usb_get_dev(udev);
        }
        spin_unlock_irqrestore(&hcd_urb_unlink_lock, flags);
        if (retval == 0) {
                hcd = bus_to_hcd(urb->dev->bus);
                retval = unlink1(hcd, urb, status);
-               usb_put_dev(urb->dev);
+               if (retval == 0)
+                       retval = -EINPROGRESS;
+               else if (retval != -EIDRM && retval != -EBUSY)
+                       dev_dbg(&udev->dev, "hcd_unlink_urb %p fail %d\n",
+                                       urb, retval);
+               usb_put_dev(udev);
        }
-
-       if (retval == 0)
-               retval = -EINPROGRESS;
-       else if (retval != -EIDRM && retval != -EBUSY)
-               dev_dbg(&urb->dev->dev, "hcd_unlink_urb %p fail %d\n",
-                               urb, retval);
        return retval;
 }
 


Patches currently in stable-queue which might be from [email protected] 
are

queue-3.19/usb-add-flag-for-hcds-that-can-t-receive-wakeup-requests-isp1760-hcd.patch
queue-3.19/usb-fix-use-after-free-bug-in-usb_hcd_unlink_urb.patch
queue-3.19/usb-core-buffer-smallest-buffer-should-start-at-arch_dma_minalign.patch
queue-3.19/usb-don-t-cancel-queued-resets-when-unbinding-drivers.patch
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to