Received: by 10.223.176.5 with SMTP id f5csp2837676wra; Mon, 5 Feb 2018 10:41:52 -0800 (PST) X-Google-Smtp-Source: AH8x226msACrgrEHhcoKBrTvDCuEwwt+bDc7xSiWGFaDbxVHJgG9woJzCQEnDuuouoYseffeG4jP X-Received: by 2002:a17:902:a5c5:: with SMTP id t5-v6mr23590262plq.160.1517856112081; Mon, 05 Feb 2018 10:41:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517856112; cv=none; d=google.com; s=arc-20160816; b=miQOF3/XV7MSvooTvLZb0ICVKozJI3DerbTJybWreBANcv+CwVCrZryOk5jIR8FyzO Dn1VQ5fPSbj7487EhIcoMvnu6PtGfqfl3BqwbMO6rxkTR06u9MyNeBY5eBGWak8NX693 2b79CPF5qJUFlgTmEXgAUUSWRa4Rrpv3cuYUCNf546z17TijNhtyh/CNoZ4R/Yvw5jpU rZY1SUO45gH69BxMxbu4e9JxLEDyn01E9oCpgONpLg2r6WcIfbh1RHpjTB4hPgIFW3Yy TNLltrSLlkbZuHMAqBgk3O/HyG/y+j/OZgVrAg8s9ZsFNeXbxYp4mDre7ekPAwXgWTkD /6nQ== 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=ri1i0ZLEh5U7S3k2vbItrgvgZ5NRVG94dIQ2Ao05/GE=; b=HBRr7OQwUSbr8P36FoV4y0x+3Y6c+Ce4pcCU7nKNgWIjqQGjCNq5qV6PjxA5Tv71X1 8noIEbFZHR/1eNKxxqIdyZBlQQmO/Hol8+qeYexcuESlhdtmSQMWLG6notxMQKLk+Kgq 57UpjDR7KR7UuaosL8zHOVhpiyRZps4FlCW+1rBYKx9gH2nBmbqTVvUWjjZ2swrvdJp1 AbMXYkX4ikmxenKFAal8otcL8Dqty0UqSuQDsDnBlwQxX+owhwO7+dmVH9UMqe956hdA eECVY6mZcCvwkPhy2l22t/+XqZ2I+vLccGbfe3FVPFhpG7UR+StDRQTL2vpb+7UHNsiu eZSw== 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 l6si5744541pgq.164.2018.02.05.10.41.37; Mon, 05 Feb 2018 10:41:52 -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 S1754032AbeBESjx (ORCPT + 99 others); Mon, 5 Feb 2018 13:39:53 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:54252 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753924AbeBES0m (ORCPT ); Mon, 5 Feb 2018 13:26:42 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9F093D8E; Mon, 5 Feb 2018 18:26:27 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuah Khan Subject: [PATCH 3.18 29/36] usbip: prevent bind loops on devices attached to vhci_hcd Date: Mon, 5 Feb 2018 10:23:57 -0800 Message-Id: <20180205182352.968973260@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182351.774761393@linuxfoundation.org> References: <20180205182351.774761393@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 3.18-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);