Received: by 10.223.148.5 with SMTP id 5csp6245720wrq; Wed, 17 Jan 2018 11:09:01 -0800 (PST) X-Google-Smtp-Source: ACJfBovqKRSuZ6PdJnketYAWhOZyBBzVoNe/3rwzaERwElS6MGlsDVRXPmiKCk9Kb3vxnnwJs2TJ X-Received: by 10.84.214.130 with SMTP id j2mr32478089pli.339.1516216141315; Wed, 17 Jan 2018 11:09:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516216141; cv=none; d=google.com; s=arc-20160816; b=IG06dR2VvCJ7De0WQ+HjBAZUWOx8L2QnQTJjnFimNXpywqAyos8xSO98141wSP9cis HUf11vylYpYKdP0g8vBkPFUtcGyKkO6XuRrznNuhuQPWIKGpep7uNw2Ugf6q6N3hJmDt 3lhr4mT3JIa4KmFkJX7sDvoOVhtXA+WiKbwqJW58AKg7AYpJ1iJkE4lyzy/eZv5Kw9ny oD28/ilkleV8NhnkSMEoMhow5z8ebsWavNVQhvD9BsJzaPd5zVzXrycjaCWPbE6m92+q JQnfmyvSOTXnOTSHZ5NL5Mn4wxTQdO69KvUc4D/T6zcVT57rg4wSHPxd6BnMgWi5P1Oq cJxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=iPR2MQp2j3pyQ/1dk+ay4kGdeZODhi8A9xV0mC2dquA=; b=SEIMTUatDbvyuR75BjHOJT2ncilYUYaX8w0I0xRdjg7jqqKjnP55TJgmKkZGGYSlEe x4WTIODjfSaj8WWOLheglN97hdcydtg9hZjctwY+eYI0j7hjsjjeQNbsm2j6uiumF0at J1YmCjVSQFtDPlQOu5T/IamI4jrAkADfRaWMzBfADty/HWHSXTYCXcJi+rXnDilwEaOm Je1ShVHqD7rJbj6AygAOX1/NiOfjdso7dGsunqunPUzMbJcSKIHxv6czgbg5RXslYfTQ kmsdS1yXg2oSdv5GIcJn50AiuRsXx2E8y5ZEYh4v2zcO/r1MVwR0nFzs1Q/onb+aPV1w DzSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i186si4837096pfg.116.2018.01.17.11.08.47; Wed, 17 Jan 2018 11:09:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752654AbeAQTH5 (ORCPT + 99 others); Wed, 17 Jan 2018 14:07:57 -0500 Received: from osg.samsung.com ([64.30.133.232]:52096 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752491AbeAQTH4 (ORCPT ); Wed, 17 Jan 2018 14:07:56 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 5DE771D7AA; Wed, 17 Jan 2018 11:07:55 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1uWXMRnyvn_o; Wed, 17 Jan 2018 11:07:52 -0800 (PST) Received: from localhost.localdomain (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) by osg.samsung.com (Postfix) with ESMTPSA id A32421D7A2; Wed, 17 Jan 2018 11:07:52 -0800 (PST) From: Shuah Khan To: valentina.manea.m@gmail.com, shuah@kernel.org, gregkh@linuxfoundation.org Cc: Shuah Khan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] usbip: prevent bind loops on devices attached to vhci_hcd Date: Wed, 17 Jan 2018 12:07:30 -0700 Message-Id: <20180117190730.14734-1-shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- tools/usb/usbip/src/usbip_bind.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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) int rc; struct udev *udev; struct udev_device *dev; + const char *devpath; /* Check whether the device with this bus ID exists. */ udev = udev_new(); @@ -152,8 +153,16 @@ static int bind_device(char *busid) err("device with the specified bus ID does not exist"); return -1; } + devpath = udev_device_get_devpath(dev); udev_unref(udev); + /* If the device is already attached to vhci_hcd - bail out */ + if (strstr(devpath, USBIP_VHCI_DRV_NAME)) { + err("bind loop detected: device: %s is attached to %s\n", + devpath, USBIP_VHCI_DRV_NAME); + return -1; + } + rc = unbind_other(busid); if (rc == UNBIND_ST_FAILED) { err("could not unbind driver from device on busid %s", busid); -- 2.14.1