Received: by 10.223.176.5 with SMTP id f5csp999283wra; Fri, 2 Feb 2018 09:28:37 -0800 (PST) X-Google-Smtp-Source: AH8x22770TWpb5ciZ+9QsbZwpsZ4xYDeAPh9qzbTSUyi+kkvrDqDCJekUFic7y/5sW9plNZ/VhEq X-Received: by 10.98.5.129 with SMTP id 123mr41174717pff.75.1517592516990; Fri, 02 Feb 2018 09:28:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517592516; cv=none; d=google.com; s=arc-20160816; b=vuf2XsL6+XstF2VJ9nsisZ9wtDv5+KeqWpgtdyFgADUVyQwD0VZz7iF0ttA8Fv+8r2 M+WPgeqe7o1atWlRCKiPGbJLJJHIKkytTKRRVZ7HmR9Gmx/plGVJm/wFSycyMN60nna7 wWDdozpdVCK0dKwk0Wt9f5V2LAaf4hA/dQVLT5K7BdOyM007P9sDKSEKstq6lFP/We2/ lD1JIljn67ySK8IXv1uzZYy0tG5EuqUsPc46mMH4RG9vD7GE+YrQFA7vNrOKY76eakYa z7LWT0aUVbh08fzo1zhv2psMrz+OAYWc6qbV1L7fNMYuW58l0E3SdTr0498socux2oA8 biGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wHCZAKkFJuZyR7ZzwVXibUvZwga838kiskoA9qjWAR0=; b=UXeND0CyhybfdUsYVZw6hV0eV8TPGx1mdbwmIs1Qbb0hPe+o2E5rVGfKG1bTPKn/rC WdQv1uWGODMgFVzE3+AVc5xziWfHWy+SCike7CQWxyK/De+LS6DhhymgrVaTfDvg6fOI 8gUtm6lBjIFNBIXzcmjQCT2RaCgwMsuxhDicJttMJJjHY5FRKVBSM/ZZh6F6AxsXU9PZ fxHqiSOEskM6kCUDWRyNrTBDQwZDko9UXsyooL0Mb9hgu4yqz3jWvOmPVbBVqNqCXoos 83LoDzhYvu3/GOWC1Hoo1ehfMrfnc9s1zHQGIwVeSDS8TozRDTzlm0d+S0v6+LlGs3Jt Srwg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i14si1684805pgp.516.2018.02.02.09.28.21; Fri, 02 Feb 2018 09:28:36 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754177AbeBBR1J (ORCPT + 99 others); Fri, 2 Feb 2018 12:27:09 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40912 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753641AbeBBRQF (ORCPT ); Fri, 2 Feb 2018 12:16:05 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C1912ED5; Fri, 2 Feb 2018 17:16:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuah Khan Subject: [PATCH 4.15 36/55] usbip: prevent bind loops on devices attached to vhci_hcd Date: Fri, 2 Feb 2018 17:58:54 +0100 Message-Id: <20180202140829.760810465@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140826.117602411@linuxfoundation.org> References: <20180202140826.117602411@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shuah Khan commit ef54cf0c600fb8f5737fb001a9e357edda1a1de8 upstream. 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. Signed-off-by: Shuah Khan Signed-off-by: Greg Kroah-Hartman --- tools/usb/usbip/src/usbip_bind.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- 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);