Received: by 10.223.176.5 with SMTP id f5csp981817wra; Fri, 2 Feb 2018 09:12:52 -0800 (PST) X-Google-Smtp-Source: AH8x224AbHERUkqYgGARoCdpaXQWgvSJENkhiIPy5phVkIGo6nsbPm+SfH5/VB6A6wrfeOj1f2wv X-Received: by 10.98.42.79 with SMTP id q76mr37600242pfq.23.1517591572124; Fri, 02 Feb 2018 09:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517591572; cv=none; d=google.com; s=arc-20160816; b=m5dOJAbv9Yu7uPhdtTSnef7IAEfffEkCPiUWzqsuBoD0INJIT1RhMVFezopoMtamXO PzZFkRfL1tcq2fMxlovtCLLecGIJqO+vhylpjrdKHwzPWE7RwLRkbPpTA+5Gx/ZoOLYr TJ8BnpKV7sQG5twHy5VEkpcRzFiwnvfkUxjGL9vxADP+D7uI3AWxtWkAbhEr0nzycmRi /GwuSaafvY8VwkqD39Gm+u1qc/Cq1E3sERwnI/Kcha7d4cxZg6Z+ACYXhbkctyDilqAt wUdPwitQS4vqW/IvB/3Gmg1Qho3IS00/t765PF9T86KSFv9qd0VVO+ouVdjXP681QDXC VtNw== 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=c32QVSOvxW7fDK7u+z6PLTYyqCX65cfyhb3WG0MZvzY=; b=jlru0TC37e1eF5XQXVuQuYgFAyJKdsKUfWZ/S9I3hZqN5Tq5G0XIUsK0WsfEg/XJW7 bsu2Bya0Tm9hw3y1xO0RghpnBUZTJjgK7meSAss8so4pGu3GW7GX6CiIlkYYAkGoqJIv KMu8Boh8odzGjicG1CVKnvWt4J58BDbAfSL7AE5To1KfXIfb0VQNoELryxKZGzkmlqbi oHvpNgZ66X8XmQQtEL2nh+4lFUc17zpF65IsGvgTWWzlyRehdLHu/Ptbp9OYU4lhzCDR X67SOJnE1dZyTiHvONMKfH5+PWHo4Ag6qnWdMthM6LykHVDcTZ6K8ZThmW/gtFzX3Seu 9YAg== 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 c19-v6si2141863plo.278.2018.02.02.09.12.37; Fri, 02 Feb 2018 09:12: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 S1752840AbeBBRLw (ORCPT + 99 others); Fri, 2 Feb 2018 12:11:52 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36746 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753078AbeBBRGV (ORCPT ); Fri, 2 Feb 2018 12:06:21 -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 537E5E3B; Fri, 2 Feb 2018 17:06:20 +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.9 78/86] usbip: prevent bind loops on devices attached to vhci_hcd Date: Fri, 2 Feb 2018 17:58:38 +0100 Message-Id: <20180202140829.853191066@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140822.679101338@linuxfoundation.org> References: <20180202140822.679101338@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.9-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);