Received: by 10.223.176.5 with SMTP id f5csp1007052wra; Fri, 2 Feb 2018 09:35:27 -0800 (PST) X-Google-Smtp-Source: AH8x226hyGaxuNwHCNzR5H62zeHFvlL2LUyXLMGGFEXAOBMr7u+CmDOp/xOTFm7ZP47qPSq5soB3 X-Received: by 2002:a17:902:d81:: with SMTP id 1-v6mr36549091plv.270.1517592926945; Fri, 02 Feb 2018 09:35:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517592926; cv=none; d=google.com; s=arc-20160816; b=C6pU2D8/GkI8WmKor5JTUYadqfELj42tMgeisoWHohQipWrAYvl8NqGsuzrXWoknMW Hi3hGcLDsiS81RqkQO5WPWGtFU5ZoIJ2gyYZlDiHfh0AUZJUhYj01baPhihQqx3+FrXM YarIo8HbN3DBrdN47AbTBLI1g0ezImDjKqAzRZXrq02H31opwBvpJL+jsOGi7+gn3P3W Du8mLJT572zc0oDJx4+o7yeHqn8OpteZXTTinSPwlmLCZrGhVuu8Exli4WtAmQXLS4Fn KSND5TDK3DGju0xdYoA4YX59wNnFQWOJHStM1IHxsBXDkYufb1IkMseM7J66k8/5dtS+ AxNg== 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=AeSHPvftPOgNaAzWArL9NNilRrZn6FiA1tfR3w0R3fs=; b=kqKZO0WvpEZ9rghdyrcqNmifPTD53wP+fZBWMV0LR6B5fxpB4RjWEq4LFh89G5hB6A BavOUCLZs6qvHs6ubfM+JsekYYKPD3une5sPWJSCCPZzCkbcpv9GxugZA71GrKXc5vli szjTG+fh5EZ+llBi5ee6gfiyWCCVY/bkvseh0d2zXGPcCeSUltB4H2z7tDepaNvKeohx FsDv8a0xF1lG3QHXvjgsdZRU94er/rvKSqDZ+w4J1OYZ9stQBYYrT3CGIq6a6zjS0ODn +3P48oRVz794K8K2M4sQFNiagbgLZiJFv2yUSpEq0LOxj5fzgSdAA7HJXXTTkFwR/iqa dgkg== 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 e17si1713793pgo.189.2018.02.02.09.35.12; Fri, 02 Feb 2018 09:35:26 -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 S1753528AbeBBRYb (ORCPT + 99 others); Fri, 2 Feb 2018 12:24:31 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40526 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753409AbeBBROe (ORCPT ); Fri, 2 Feb 2018 12:14:34 -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 A0FDFAD8; Fri, 2 Feb 2018 17:14:32 +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.14 138/156] usbip: prevent bind loops on devices attached to vhci_hcd Date: Fri, 2 Feb 2018 17:58:39 +0100 Message-Id: <20180202140846.622444985@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@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.14-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);