aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/usbip/stub_rx.c
diff options
context:
space:
mode:
authorNiels Dossche <dossche.niels@gmail.com>2022-04-12 18:50:55 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-04-21 19:01:25 +0200
commitd088fabace2ca337b275d1d4b36db4fe7771e44f (patch)
tree84afb841804e5b97dc54b2dcbf3eff8d3bacf9a1 /drivers/usb/usbip/stub_rx.c
parentusb: usbip: fix a refcount leak in stub_probe() (diff)
downloadlinux-dev-d088fabace2ca337b275d1d4b36db4fe7771e44f.tar.xz
linux-dev-d088fabace2ca337b275d1d4b36db4fe7771e44f.zip
usb: usbip: add missing device lock on tweak configuration cmd
The function documentation of usb_set_configuration says that its callers should hold the device lock. This lock is held for all callsites except tweak_set_configuration_cmd. The code path can be executed for example when attaching a remote USB device. The solution is to surround the call by the device lock. This bug was found using my experimental own-developed static analysis tool, which reported the missing lock on v5.17.2. I manually verified this bug report by doing code review as well. I runtime checked that the required lock is not held. I compiled and runtime tested this on x86_64 with a USB mouse. After applying this patch, my analyser no longer reports this potential bug. Fixes: 2c8c98158946 ("staging: usbip: let client choose device configuration") Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Niels Dossche <dossche.niels@gmail.com> Link: https://lore.kernel.org/r/20220412165055.257113-1-dossche.niels@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/usbip/stub_rx.c')
-rw-r--r--drivers/usb/usbip/stub_rx.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/usb/usbip/stub_rx.c b/drivers/usb/usbip/stub_rx.c
index 325c22008e53..5dd41e8215e0 100644
--- a/drivers/usb/usbip/stub_rx.c
+++ b/drivers/usb/usbip/stub_rx.c
@@ -138,7 +138,9 @@ static int tweak_set_configuration_cmd(struct urb *urb)
req = (struct usb_ctrlrequest *) urb->setup_packet;
config = le16_to_cpu(req->wValue);
+ usb_lock_device(sdev->udev);
err = usb_set_configuration(sdev->udev, config);
+ usb_unlock_device(sdev->udev);
if (err && err != -ENODEV)
dev_err(&sdev->udev->dev, "can't set config #%d, error %d\n",
config, err);