Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usbip: prevent bind loops on devices attached to vhci_hcd

usbip host binds to devices attached to vhci_hcd on the same server
when user does attach over localhost or specifies the server as the
remote.

usbip attach -r localhost -b busid
or
usbip attach -r servername (or server IP)

Unbind followed by bind works, however device is left in a bad state with
accesses via the attached busid result in errors and system hangs during
shutdown.

Fix it to check and bail out if the device is already attached to vhci_hcd.

Cc: stable@vger.kernel.org
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Shuah Khan and committed by
Greg Kroah-Hartman
ef54cf0c f0b4198f

+9
+9
tools/usb/usbip/src/usbip_bind.c
··· 144 144 int rc; 145 145 struct udev *udev; 146 146 struct udev_device *dev; 147 + const char *devpath; 147 148 148 149 /* Check whether the device with this bus ID exists. */ 149 150 udev = udev_new(); ··· 153 152 err("device with the specified bus ID does not exist"); 154 153 return -1; 155 154 } 155 + devpath = udev_device_get_devpath(dev); 156 156 udev_unref(udev); 157 + 158 + /* If the device is already attached to vhci_hcd - bail out */ 159 + if (strstr(devpath, USBIP_VHCI_DRV_NAME)) { 160 + err("bind loop detected: device: %s is attached to %s\n", 161 + devpath, USBIP_VHCI_DRV_NAME); 162 + return -1; 163 + } 157 164 158 165 rc = unbind_other(busid); 159 166 if (rc == UNBIND_ST_FAILED) {