android_kernel_oneplus_msm8998/drivers/usb/core
Alan Stern 8f67bc7c8d USB: core: Fix races in character device registration and deregistraion
commit 303911cfc5b95d33687d9046133ff184cf5043ff upstream.

The syzbot fuzzer has found two (!) races in the USB character device
registration and deregistration routines.  This patch fixes the races.

The first race results from the fact that usb_deregister_dev() sets
usb_minors[intf->minor] to NULL before calling device_destroy() on the
class device.  This leaves a window during which another thread can
allocate the same minor number but will encounter a duplicate name
error when it tries to register its own class device.  A typical error
message in the system log would look like:

    sysfs: cannot create duplicate filename '/class/usbmisc/ldusb0'

The patch fixes this race by destroying the class device first.

The second race is in usb_register_dev().  When that routine runs, it
first allocates a minor number, then drops minor_rwsem, and then
creates the class device.  If the device creation fails, the minor
number is deallocated and the whole routine returns an error.  But
during the time while minor_rwsem was dropped, there is a window in
which the minor number is allocated and so another thread can
successfully open the device file.  Typically this results in
use-after-free errors or invalid accesses when the other thread closes
its open file reference, because the kernel then tries to release
resources that were already deallocated when usb_register_dev()
failed.  The patch fixes this race by keeping minor_rwsem locked
throughout the entire routine.

Reported-and-tested-by: syzbot+30cf45ebfe0b0c4847a1@syzkaller.appspotmail.com
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.1908121607590.1659-100000@iolanthe.rowland.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-25 10:53:01 +02:00
..
buffer.c
config.c USB: Fix slab-out-of-bounds write in usb_get_bos_descriptor 2019-06-11 12:24:08 +02:00
devices.c usb: define USB_SPEED_SUPER_PLUS speed for SuperSpeedPlus USB3.1 devices 2016-09-07 08:32:39 +02:00
devio.c USB: fix the usbfs flag sanitization for control transfers 2018-11-10 07:41:43 -08:00
driver.c USB: core: Fix bug caused by duplicate interface PM usage counter 2019-05-16 19:45:00 +02:00
endpoint.c usb: endpoint: convert spaces to tabs 2015-08-14 16:50:36 -07:00
file.c USB: core: Fix races in character device registration and deregistraion 2019-08-25 10:53:01 +02:00
generic.c USB:fix USB3 devices behind USB3 hubs not resuming at hibernate thaw 2018-04-24 09:32:06 +02:00
hcd-pci.c usb: Don't die twice if PCI xhci host is not responding in resume 2018-09-26 08:35:07 +02:00
hcd.c usb: core: Add PM runtime calls to usb_hcd_platform_shutdown 2019-06-11 12:24:05 +02:00
hub.c usb: core: hub: Disable hub-initiated U1/U2 2019-08-04 09:34:56 +02:00
hub.h
Kconfig usb: kconfig: fix warning of select USB_OTG 2015-11-19 16:31:42 -08:00
Makefile
message.c USB: core: Fix unterminated string returned by usb_string() 2019-05-16 19:45:00 +02:00
notify.c
otg_whitelist.h usb: otg_whitelist: remove whitespace 2015-08-14 16:50:36 -07:00
port.c usb: Quiet down false peer failure messages 2015-12-04 08:19:55 -08:00
quirks.c USB: Fix chipmunk-like voice when using Logitech C270 for recording audio. 2019-06-22 08:18:24 +02:00
sysfs.c USB: Add new USB LPM helpers 2019-05-16 19:44:44 +02:00
urb.c USB: core: replace %p with %pK 2017-05-25 14:30:07 +02:00
usb-acpi.c usb: optimize acpi companion search for usb port devices 2017-08-24 17:02:36 -07:00
usb.c USB: check usb_get_extra_descriptor for proper size 2018-12-13 09:21:35 +01:00
usb.h USB: Add new USB LPM helpers 2019-05-16 19:44:44 +02:00