Received: by 10.223.176.5 with SMTP id f5csp1055507wra; Fri, 2 Feb 2018 10:23:42 -0800 (PST) X-Google-Smtp-Source: AH8x226RHKTUFtI3SZ4nFt+fEYUFP18dds5DUBycf89Lp0+vJSZaR0ROMstvvDlc4KmSYkkJo6yF X-Received: by 10.98.73.76 with SMTP id w73mr40830063pfa.61.1517595821887; Fri, 02 Feb 2018 10:23:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517595821; cv=none; d=google.com; s=arc-20160816; b=m7pJZAR+BZ3Td0ROJEIF5dyfQ0iPtiSi+x2R84NIbsQIQFO7AXIJAwlriP47zH65+b G4XL48hliMv9KLsWwb9KJphax8irFXZaFZ2cZkPvZxNXXWPc0bqO4xD7pn8s4PQWaM1W 32P1nVDqyShEymLrqplgzzcJJ38MNUWFLnni0aeTyjzn1mk7RxwfYOmUOKR90+H07IGG nOlcaQrjVsv6d+J5b3ysyFZ+RQh3yyIBnYZqMaRefZH6+N0AyOy6XD4RXFlnJS6fgywl gKjTTlQUlimXTSxQPbHNRzQqq9buyywvAd11oqcVJ3oLP9zk9BCfjM4Bnh2PJsbZFg+9 W5Uw== 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=UbjQjweQo/kwKB6eas6QWmSzBPq+wM1QPVxr6eK7ZkQ=; b=knlRDDa3DSXUc/kHhsnBmS6x/BHJKAVvbK1jzhd4eHug8onut4imkBtfrYwLTj8B85 khUHoVoPykl2w9eld9s2zgP2Za2SLQ0RH/iyqvqxNGSSnkd3fr22aeCft311cHr7nOSp yUFw71zzsrazm+C+41Mai/47lmsXrCaQwL0yjaFWZ6zXMBWSGp0hKLF5FAf+ZmpujR0w LpPdemqnVMJFJ+ntZyDTCLaqc9qLo7ToiY9QBYgCE0QZ10VVawnDQ9PeR68Px2gfIa3O VeklsoLciGIFS9GTxkjWG5VXLXNjAkSg2IicoVY/wOgeWMfRQRUtUGr8vNY7v2Y32mN6 WCRg== 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 x185si52163pgx.159.2018.02.02.10.23.27; Fri, 02 Feb 2018 10:23:41 -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 S1754548AbeBBSW1 (ORCPT + 99 others); Fri, 2 Feb 2018 13:22:27 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35524 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752430AbeBBRCr (ORCPT ); Fri, 2 Feb 2018 12:02:47 -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 C41FFE5E; Fri, 2 Feb 2018 17:02:46 +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.4 60/67] usbip: prevent bind loops on devices attached to vhci_hcd Date: Fri, 2 Feb 2018 17:58:29 +0100 Message-Id: <20180202140821.868570518@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140815.091718203@linuxfoundation.org> References: <20180202140815.091718203@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.4-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);