xhci: Fix use-after-free in xhci_free_virt_device
Subsystems (3)
PATCH 1/1 xhci: Fix use-after-free in xhci_free_virt_device
From: Mathias Nyman <[email protected]>
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.
---
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(+)
drivers/usb/host/xhci.c +3 -0
@@ -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) ||
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Greg Kroah-Hartman
maintainerQuoted 25 lines · Matthias Kaehlcke
From: Mathias Nyman <[email protected]>
commit
44a182b9d17765514fa2b1cc911e4e65134eef93upstream.KASAN found a use-after-free in
xhci_free_virt_device+0x33b/0x38ewherexhci_free_virt_device()sets slot id to 0 if udev exists:
if (dev->udev&&dev->udev->slot_id)dev->udev->slot_id = 0;
dev->udevwill be true even if udev is freed becausedev->udevis not set to NULL.set
dev->udevpointer to NULL inxhci_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 <[email protected]>Reported-by Guenter Roeck <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Tested-by Guenter Roeck <[email protected]>Signed-off-by Mathias Nyman <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Signed-off-by Matthias Kaehlcke <[email protected]>
Quoted 5 lines
---
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 inxhci_free_dev()changed a bit because upstream addedxhci_disable_slot().
Now queued up, thanks.
greg k-h