Re: [syzbot] [usb?] general protection fault in rebind_store
From: syzbot
Date: Fri Nov 27 2026 - 08:25:40 EST
> #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
Patch testing via #syz test is temporarily disabled.
See https://github.com/google/syzkaller/issues/8122 for details.
>
> diff --git a/drivers/usb/usbip/stub.h b/drivers/usb/usbip/stub.h
> index d11270560c24..ab5726eeed29 100644
> --- a/drivers/usb/usbip/stub.h
> +++ b/drivers/usb/usbip/stub.h
> @@ -75,7 +75,6 @@ struct bus_id_priv {
> char status;
> int interf_count;
> struct stub_device *sdev;
> - struct usb_device *udev;
> char shutdown_busid;
> spinlock_t busid_lock;
> };
> diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
> index abfa11d6bde7..b03c77d598e8 100644
> --- a/drivers/usb/usbip/stub_dev.c
> +++ b/drivers/usb/usbip/stub_dev.c
> @@ -371,7 +371,6 @@ static int stub_probe(struct usb_device *udev)
> dev_set_drvdata(&udev->dev, sdev);
>
> busid_priv->sdev = sdev;
> - busid_priv->udev = udev;
>
> save_status = busid_priv->status;
> busid_priv->status = STUB_BUSID_ALLOC;
> diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
> index 01452f7bdabb..563c92ab88e7 100644
> --- a/drivers/usb/usbip/stub_main.c
> +++ b/drivers/usb/usbip/stub_main.c
> @@ -196,18 +196,28 @@ static ssize_t match_busid_store(struct device_driver *dev, const char *buf,
> }
> static DRIVER_ATTR_RW(match_busid);
>
> -static int do_rebind(char *busid, struct bus_id_priv *busid_priv)
> +static int do_rebind(char *busid)
> {
> + struct device *dev;
> int ret = 0;
>
> + /*
> + * Look the device up by name: it may have been disconnected and
> + * freed since it was bound to usbip-host.
> + */
> + dev = bus_find_device_by_name(stub_driver.driver.bus, NULL, busid);
> + if (!dev)
> + return -ENODEV;
> +
> /* device_attach() callers should hold parent lock for USB */
> - if (busid_priv->udev->dev.parent)
> - device_lock(busid_priv->udev->dev.parent);
> - ret = device_attach(&busid_priv->udev->dev);
> - if (busid_priv->udev->dev.parent)
> - device_unlock(busid_priv->udev->dev.parent);
> + if (dev->parent)
> + device_lock(dev->parent);
> + ret = device_attach(dev);
> + if (dev->parent)
> + device_unlock(dev->parent);
> if (ret < 0)
> - dev_err(&busid_priv->udev->dev, "rebind failed\n");
> + dev_err(dev, "rebind failed\n");
> + put_device(dev);
> return ret;
> }
>
> @@ -232,8 +242,7 @@ static void stub_device_rebind(void)
> for (i = 0; i < MAX_BUSID; i++) {
> if (busid_table[i].name[0] &&
> busid_table[i].shutdown_busid) {
> - busid_priv = &(busid_table[i]);
> - do_rebind(busid_table[i].name, busid_priv);
> + do_rebind(busid_table[i].name);
> }
> }
> #endif
> @@ -261,8 +270,9 @@ static ssize_t rebind_store(struct device_driver *dev, const char *buf,
> /* release the busid lock */
> put_busid_priv(bid);
>
> - ret = do_rebind((char *) buf, bid);
> - if (ret < 0)
> + ret = do_rebind((char *) buf);
> + /* a device disconnected meanwhile has nothing to rebind */
> + if (ret < 0 && ret != -ENODEV)
> return ret;
>
> /* delete device from busid_table */