Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2512722imm; Thu, 7 Jun 2018 11:56:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIoHaG05FjuyD9GxBfwmCyQhJDFUZmUDsvqCyOmLyyjuI6FI4SKR/jMG4Nr0F1obari64v8 X-Received: by 2002:a65:4c0e:: with SMTP id u14-v6mr2507935pgq.388.1528397762221; Thu, 07 Jun 2018 11:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528397762; cv=none; d=google.com; s=arc-20160816; b=jxKTfyYn18SzrC+YYQzVV01W9LgkKhfjxZJm9PhdGQqveowQOlcLY1Pt6j5Ok87lw+ gtCYUHGrHYEDAnmSrdCTts9DwPtpt4CJ8uq4ndm4n6eYoox7w263qe6jo9iI/Hzy1f8f 4lDaIrkmPfuQy37zZfDrUcChRyesDSkuK1PU2Vn9a7dbWbU/wPw53tzBrn4lXOYZPaXD gX5ktWNILkhk9f1cjEb1DXmwV1sUeLCdhXi1kCiGUETEcY4vQhBWDZoXh335p+9aXuBk 43oFcDbHr65eNQB/0lSCPdhDpBX/DtdGYjqszBOL4c2Uvsi42ygx+sB+TjyBqYxI1LZ4 1klA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=p0JdDBFGtJu8ghU4Pp27ZRNC9UmI7zGThQROisfb5q4=; b=q6FGR8vpt4gSwZCRTyxH9XgJiye6uK8te+q8IORtkTqESqt4F/JwNE5TGPRtzISh53 uEyQhxJ4nu5NVWzEA2eK4sozquv1wtR8AZmm02YlmslXOOH6y3vxKcVGssA0l965ypsR PVsHFm7R5cvhFKFo9U3ld1owX5tJKDkc7DRuRkXWJwLsl2nvijMD9xW72fgpQnJ8G9dd JkO0Nia9VS3Cac0KIEhYS5co6253vY7VRJCVit+NZwMnMtgG+vxcrxUzetDt7dYYm4TR Nx32gayDCs99ZFXt5U0K3QvzDRsu4bvKdugjDMM1disn8qTU5nIRvmENJ32NvdVYdvVc bZ6w== 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 a92-v6si55685244pla.291.2018.06.07.11.55.48; Thu, 07 Jun 2018 11:56:02 -0700 (PDT) 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 S934310AbeFGP5y (ORCPT + 99 others); Thu, 7 Jun 2018 11:57:54 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39357 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933058AbeFGOJH (ORCPT ); Thu, 7 Jun 2018 10:09:07 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvb7-0005a0-K7; Thu, 07 Jun 2018 15:09:05 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb3-0002vR-Ox; Thu, 07 Jun 2018 15:09:01 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Greg Kroah-Hartman" , "Shuah Khan" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 156/410] usbip: prevent bind loops on devices attached to vhci_hcd In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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 Signed-off-by: Ben Hutchings --- drivers/staging/usbip/userspace/src/usbip_bind.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/staging/usbip/userspace/src/usbip_bind.c +++ b/drivers/staging/usbip/userspace/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);