Patch "usb: core: Fix crash w/ usb_choose_configuration() if no driver" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

    usb: core: Fix crash w/ usb_choose_configuration() if no driver

to the 6.6-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-core-fix-crash-w-usb_choose_configuration-if-no-.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit f40a7d1b7ffa8ee851a2a3bcd4237c10c564445d
Author: Douglas Anderson <dianders@xxxxxxxxxxxx>
Date:   Mon Dec 11 07:32:41 2023 -0800

    usb: core: Fix crash w/ usb_choose_configuration() if no driver
    
    [ Upstream commit 44995e6f07028f798efd0c3c11a1efc78330f600 ]
    
    It's possible that usb_choose_configuration() can get called when a
    USB device has no driver. In this case the recent commit a87b8e3be926
    ("usb: core: Allow subclassed USB drivers to override
    usb_choose_configuration()") can cause a crash since it dereferenced
    the driver structure without checking for NULL. Let's add a check.
    
    A USB device with no driver is an anomaly, so make
    usb_choose_configuration() return immediately if there is no driver.
    
    This was seen in the real world when usbguard got ahold of a r8152
    device at the wrong time. It can also be simulated via this on a
    computer with one r8152-based USB Ethernet adapter:
      cd /sys/bus/usb/drivers/r8152-cfgselector
      to_unbind="$(ls -d *-*)"
      real_dir="$(readlink -f "${to_unbind}")"
      echo "${to_unbind}" > unbind
      cd "${real_dir}"
      echo 0 > authorized
      echo 1 > authorized
    
    Fixes: a87b8e3be926 ("usb: core: Allow subclassed USB drivers to override usb_choose_configuration()")
    Reviewed-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Douglas Anderson <dianders@xxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20231211073237.v3.1.If27eb3bf7812f91ab83810f232292f032f4203e0@changeid
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index dcb897158228..b134bff5c3fe 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -59,7 +59,16 @@ int usb_choose_configuration(struct usb_device *udev)
 	int num_configs;
 	int insufficient_power = 0;
 	struct usb_host_config *c, *best;
-	struct usb_device_driver *udriver = to_usb_device_driver(udev->dev.driver);
+	struct usb_device_driver *udriver;
+
+	/*
+	 * If a USB device (not an interface) doesn't have a driver then the
+	 * kernel has no business trying to select or install a configuration
+	 * for it.
+	 */
+	if (!udev->dev.driver)
+		return -1;
+	udriver = to_usb_device_driver(udev->dev.driver);
 
 	if (usb_device_is_owned(udev))
 		return 0;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux