stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -stable] xhci: Fix use-after-free in xhci_free_virt_device
@ 2018-09-13 21:10 Matthias Kaehlcke
  2018-09-17 11:41 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Matthias Kaehlcke @ 2018-09-13 21:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Guenter Roeck, Mathias Nyman, stable, Matthias Kaehlcke

From: Mathias Nyman <mathias.nyman@linux.intel.com>

commit 44a182b9d17765514fa2b1cc911e4e65134eef93 upstream.

KASAN found a use-after-free in xhci_free_virt_device+0x33b/0x38e
where xhci_free_virt_device() sets slot id to 0 if udev exists:
if (dev->udev && dev->udev->slot_id)
	dev->udev->slot_id = 0;

dev->udev will be true even if udev is freed because dev->udev is
not set to NULL.

set dev->udev pointer to NULL in xhci_free_dev()

The original patch went to stable so this fix needs to be applied
there as well.

Fixes: a400efe455f7 ("xhci: zero usb device slot_id member when disabling and freeing a xhci slot")
Cc: <stable@vger.kernel.org>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
The original fix has been integrated into some recent -stable versions,
but wasn't backported to older LTS kernel like v4.9 or v4.4. The context
in xhci_free_dev() changed a bit because upstream added
xhci_disable_slot().

 drivers/usb/host/xhci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index c190fabd1875..e9f5f9c32b49 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3656,6 +3656,9 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
 	}
 
 	spin_lock_irqsave(&xhci->lock, flags);
+
+	virt_dev->udev = NULL;
+
 	/* Don't disable the slot if the host controller is dead. */
 	state = readl(&xhci->op_regs->status);
 	if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) ||
-- 
2.19.0.397.gdd90340f6a-goog

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

* Re: [PATCH -stable] xhci: Fix use-after-free in xhci_free_virt_device
  2018-09-13 21:10 [PATCH -stable] xhci: Fix use-after-free in xhci_free_virt_device Matthias Kaehlcke
@ 2018-09-17 11:41 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2018-09-17 11:41 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: Guenter Roeck, Mathias Nyman, stable

On Thu, Sep 13, 2018 at 02:10:24PM -0700, Matthias Kaehlcke wrote:
> From: Mathias Nyman <mathias.nyman@linux.intel.com>
> 
> commit 44a182b9d17765514fa2b1cc911e4e65134eef93 upstream.
> 
> KASAN found a use-after-free in xhci_free_virt_device+0x33b/0x38e
> where xhci_free_virt_device() sets slot id to 0 if udev exists:
> if (dev->udev && dev->udev->slot_id)
> 	dev->udev->slot_id = 0;
> 
> dev->udev will be true even if udev is freed because dev->udev is
> not set to NULL.
> 
> set dev->udev pointer to NULL in xhci_free_dev()
> 
> The original patch went to stable so this fix needs to be applied
> there as well.
> 
> Fixes: a400efe455f7 ("xhci: zero usb device slot_id member when disabling and freeing a xhci slot")
> Cc: <stable@vger.kernel.org>
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> Tested-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
> The original fix has been integrated into some recent -stable versions,
> but wasn't backported to older LTS kernel like v4.9 or v4.4. The context
> in xhci_free_dev() changed a bit because upstream added
> xhci_disable_slot().

Now queued up, thanks.

greg k-h

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

end of thread, other threads:[~2018-09-17 17:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-13 21:10 [PATCH -stable] xhci: Fix use-after-free in xhci_free_virt_device Matthias Kaehlcke
2018-09-17 11:41 ` Greg Kroah-Hartman

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).