]> www.infradead.org Git - users/jedix/linux-maple.git/commit
xhci: Fix USB3 NULL pointer dereference at logical disconnect.
authorMathias Nyman <mathias.nyman@linux.intel.com>
Mon, 14 May 2018 08:57:23 +0000 (11:57 +0300)
committerBrian Maly <brian.maly@oracle.com>
Tue, 26 Jun 2018 19:08:24 +0000 (15:08 -0400)
commitef0a8850b5f759f8bafb1608f108c665131132e9
treebcb0f1a021e5a925ec3e095370c8995aecd1039f
parent7c324005fcea00aa52d29947891173d709eff936
xhci: Fix USB3 NULL pointer dereference at logical disconnect.

Hub driver will try to disable a USB3 device twice at logical disconnect,
racing with xhci_free_dev() callback from the first port disable.

This can be triggered with "udisksctl power-off --block-device <disk>"
or by writing "1" to the "remove" sysfs file for a USB3 device
in 4.17-rc4.

USB3 devices don't have a similar disabled link state as USB2 devices,
and use a U3 suspended link state instead. In this state the port
is still enabled and connected.

hub_port_connect() first disconnects the device, then later it notices
that device is still enabled (due to U3 states) it will try to disable
the port again (set to U3).

The xhci_free_dev() called during device disable is async, so checking
for existing xhci->devs[i] when setting link state to U3 the second time
was successful, even if device was being freed.

The regression was caused by, and whole thing revealed by,
Commit 44a182b9d177 ("xhci: Fix use-after-free in xhci_free_virt_device")
which sets xhci->devs[i]->udev to NULL before xhci_virt_dev() returned.
and causes a NULL pointer dereference the second time we try to set U3.

Fix this by checking xhci->devs[i]->udev exists before setting link state.

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

Fixes: 44a182b9d177 ("xhci: Fix use-after-free in xhci_free_virt_device")
Cc: <stable@vger.kernel.org>
Reported-by: Jordan Glover <Golden_Miller83@protonmail.ch>
Tested-by: Jordan Glover <Golden_Miller83@protonmail.ch>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 2278446e2b7cd33ad894b32e7eb63afc7db6c86e)

Orabug: 27426023
Signed-off-by: Brian Maly <brian.maly@oracle.com>
Conflicts:
   Hand merge the change since multiple patches have been added to
   xhci-hub.c since this cherry pick became available.

Signed-off-by: Joe Moriarty <joe.moriarty@oracle.com>
Reviewed-by: Shannon Nelson <shannon.nelson@oracle.com>
Reviewed-by: Khalid Aziz <khalid.aziz@oracle.com>
Signed-off-by: Brian Maly <brian.maly@oracle.com>
drivers/usb/host/xhci-hub.c