Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp808356imm; Mon, 21 May 2018 14:54:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqvlIg9+l9W363fM/yytJ79uhwKurgZX4oJXqdTY4/HtqcVWiF5YyLdAzJ+aKtwvtF7aSnu X-Received: by 2002:a17:902:5e3:: with SMTP id f90-v6mr22504284plf.175.1526939646021; Mon, 21 May 2018 14:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526939645; cv=none; d=google.com; s=arc-20160816; b=AH6T8pjI3eTU7JtfL/+Gl8rBauiAGMh3aP0dio0bKq7ck0pjWVUgFRCZ9EeZ/8kyiE 84A8QFMONjwPAzCEhjHaxLs4DwwrcaM9pJVEPSijdfjgjBbba4VI5FPNiI4Gy6kyktE6 9IMzkRIANqCMa28GYRA2JnAq0Q3i7Twf/4o+rNWCZhgoF9ZraZ9BbdeNwunZFKy8PQVn ozzdoO15SFpcjb3jLz/TvEUGkVLx5e9uUo70iRL9h1APkc3UAV9+Rg7Oc4QQzHuJcM0A 5ZlsJ5dg8CBNdWFZvbrJ1/ouVXz+V2lSwT2zCuMjTlRlew4unh65fV8yyCZvXfe+BgL+ lXFw== 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:dkim-signature :arc-authentication-results; bh=xQ9xbXIIIjAEpnZ3Rgr7ZdSOIkLJBWfnFsGFPPSncnE=; b=wWZqTQ7AS8T6gdqJRcYPDCTMQZpSnlsfBMqesIodyeYeUgTn6x3zUteh+984MNs32T 3XCw99Tjb6GXE9Lgh51UMRgFHiNFIgSj+wIfa47q3cpbQo+o1F7SjpBOQQIsv5U3KaL9 9XpHI3VWr9TORcpTLu6SencD+oN1zMX5BlxBI3ZjOAZndM5TU627BxVPzgvzzElpQlpk 7YURqogELQN2U/YG4YndEUhAjEZlAnlaRstUJRMMvznlHWYfI4rXQDGTVi+4ppnXSfcH BXrCIaS4lyayQp5JW5Jnpn182lQ1VPxxE/pV8/onHqfmOLqZod2X9iWjOwVwkTFQbADp g54w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AZ0iFYlu; 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 b37-v6si14817313plb.377.2018.05.21.14.53.51; Mon, 21 May 2018 14:54:05 -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; dkim=pass header.i=@kernel.org header.s=default header.b=AZ0iFYlu; 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 S932139AbeEUVxk (ORCPT + 99 others); Mon, 21 May 2018 17:53:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:37256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754201AbeEUVWV (ORCPT ); Mon, 21 May 2018 17:22:21 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A1432075C; Mon, 21 May 2018 21:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937740; bh=/FelGZj/xdsYePQkd4o84UQU0Euii0STJtVGehq+EiA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AZ0iFYluoFu91WN0J77/BqcvLgoQtE6eNfQ4m0yF9JvJQADTKsKTo6QxWwLUtXjkp qKyzFtRVcol8b3lFCyN/ej153pk3EIIl/c/nLnKJek310hxyrcHm7KzvN9xPicbXpX 8/mVGi3ORkYUO6qrUvshMrA58Qepq5YiqfwHCqf4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jordan Glover , Mathias Nyman Subject: [PATCH 4.16 001/110] xhci: Fix USB3 NULL pointer dereference at logical disconnect. Date: Mon, 21 May 2018 23:10:58 +0200 Message-Id: <20180521210503.936834693@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mathias Nyman commit 2278446e2b7cd33ad894b32e7eb63afc7db6c86e upstream. Hub driver will try to disable a USB3 device twice at logical disconnect, racing with xhci_free_dev() callback from the first port disable. This can be triggered with "udisksctl power-off --block-device " or by writing "1" to the "remove" sysfs file for a USB3 device in 4.17-rc4. USB3 devices don't have a similar disabled link state as USB2 devices, and use a U3 suspended link state instead. In this state the port is still enabled and connected. hub_port_connect() first disconnects the device, then later it notices that device is still enabled (due to U3 states) it will try to disable the port again (set to U3). The xhci_free_dev() called during device disable is async, so checking for existing xhci->devs[i] when setting link state to U3 the second time was successful, even if device was being freed. The regression was caused by, and whole thing revealed by, Commit 44a182b9d177 ("xhci: Fix use-after-free in xhci_free_virt_device") which sets xhci->devs[i]->udev to NULL before xhci_virt_dev() returned. and causes a NULL pointer dereference the second time we try to set U3. Fix this by checking xhci->devs[i]->udev exists before setting link state. The original patch went to stable so this fix needs to be applied there as well. Fixes: 44a182b9d177 ("xhci: Fix use-after-free in xhci_free_virt_device") Cc: Reported-by: Jordan Glover Tested-by: Jordan Glover Signed-off-by: Mathias Nyman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -354,7 +354,7 @@ int xhci_find_slot_id_by_port(struct usb slot_id = 0; for (i = 0; i < MAX_HC_SLOTS; i++) { - if (!xhci->devs[i]) + if (!xhci->devs[i] || !xhci->devs[i]->udev) continue; speed = xhci->devs[i]->udev->speed; if (((speed >= USB_SPEED_SUPER) == (hcd->speed >= HCD_USB3))