aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuah Khan <shuahkh@osg.samsung.com>2018-01-17 14:07:30 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-01-22 09:34:37 -0500
commitef54cf0c600fb8f5737fb001a9e357edda1a1de8 (patch)
treee2ee1552dd7ab77b6701bac39f4aac2628a152fc
parentf0b4198f0727dd758a6ef34eca938c559b5d5ae5 (diff)
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>
-rw-r--r--tools/usb/usbip/src/usbip_bind.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/usb/usbip/src/usbip_bind.c b/tools/usb/usbip/src/usbip_bind.c
index fa46141ae68b..e121cfb1746a 100644
--- a/tools/usb/usbip/src/usbip_bind.c
+++ b/tools/usb/usbip/src/usbip_bind.c
@@ -144,6 +144,7 @@ static int bind_device(char *busid)
144 int rc; 144 int rc;
145 struct udev *udev; 145 struct udev *udev;
146 struct udev_device *dev; 146 struct udev_device *dev;
147 const char *devpath;
147 148
148 /* Check whether the device with this bus ID exists. */ 149 /* Check whether the device with this bus ID exists. */
149 udev = udev_new(); 150 udev = udev_new();
@@ -152,8 +153,16 @@ static int bind_device(char *busid)
152 err("device with the specified bus ID does not exist"); 153 err("device with the specified bus ID does not exist");
153 return -1; 154 return -1;
154 } 155 }
156 devpath = udev_device_get_devpath(dev);
155 udev_unref(udev); 157 udev_unref(udev);
156 158
159 /* If the device is already attached to vhci_hcd - bail out */
160 if (strstr(devpath, USBIP_VHCI_DRV_NAME)) {
161 err("bind loop detected: device: %s is attached to %s\n",
162 devpath, USBIP_VHCI_DRV_NAME);
163 return -1;
164 }
165
157 rc = unbind_other(busid); 166 rc = unbind_other(busid);
158 if (rc == UNBIND_ST_FAILED) { 167 if (rc == UNBIND_ST_FAILED) {
159 err("could not unbind driver from device on busid %s", busid); 168 err("could not unbind driver from device on busid %s", busid);