Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp37721imu; Thu, 8 Nov 2018 14:20:10 -0800 (PST) X-Google-Smtp-Source: AJdET5cMmEOmXoYVxd/0eFtT2Ru7lUjXbxs0bRK1hLwnUJ+tSISKUi2KS8KSPS9/JzyJkvMobkbV X-Received: by 2002:a62:cfc1:: with SMTP id b184-v6mr6305373pfg.162.1541715610307; Thu, 08 Nov 2018 14:20:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541715610; cv=none; d=google.com; s=arc-20160816; b=SmntSiSOJJpT5UsUZN7pDkx3W+Z4nUfPeQJzCelTtlDgblMfFI/L+ymZifBumsLuDA eaIiO7c4JsxW+crGAv9uOjxzcMpFmnnhZEjOHopOLr7Ifs7o8YGhQcCVqdiHEycTS94f CUmAeo3p0lFQHocLE+ACMRflEQJzPOaxNmBh1udd3awnRbZolJiLBLPmnPLnYTbcSjnC 4/zDdtA0SEDAQRIQpIx8jzO3C7w9FHztKd99YH9Qy8l/eGtgGe1U3KUBnu3yKQUGO0z6 q81F0TLDh6Xbv1T6Qyy6jifsCFv3QUFLdIfBbaLJfpv3XTcTRJ0T6PIdgFFCz9Ll5n7Y /RzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zdA47UagD9c9FtIf7Aqh1l2cJu+5SZbTXGsA0C5N1zA=; b=jKjUR1Si1PWu9xtVlEoNU6TDKueDRoBuszQ/PlJrL3xOPmal+993bHcvi6FmyWJUrf PQSKKhfJosgAYvfYLS3dZuKbb5LmyRjvXWfgxreujf8KiAPN5rjv0d6lIctFGUGpvmcC 2jm/9usvqeD+Sqt8FohgcPk72i8NYJqUbriQQ4SIbazuVEyBOBTug+YKBGL7Z15+AtTB j3YLMZVckRpQTbUxnuzQLlA6UoUxcEMj+butyB3y3/70Bee0BIFz/tlJ3RP6W/6PYjPt v3o2XGKEwAH9lK4Ri56g5SfZOShYHoPK5AhOSi0Ft7WvXq2/5Yu9U8OWVTgRXmffln7b jxZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0XNhIW60; 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 g8-v6si5641153pli.338.2018.11.08.14.19.55; Thu, 08 Nov 2018 14:20:10 -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; dkim=pass header.i=@kernel.org header.s=default header.b=0XNhIW60; 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 S1730654AbeKIH5I (ORCPT + 99 others); Fri, 9 Nov 2018 02:57:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:36360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731902AbeKIHnw (ORCPT ); Fri, 9 Nov 2018 02:43:52 -0500 Received: from localhost (unknown [208.72.13.198]) (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 B5C0B21479; Thu, 8 Nov 2018 22:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714781; bh=+ld6kpdjAzEzw9IdBt4Zh1UHHCEDSgcHx+V3vvws71k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0XNhIW605St+VtNVEJp/d5nOZZSJ2oRFolXwxhZzPkGgZU+rYxtcsxhM7Tuu4bDKS gcMCcucbSjX+DhjGfxRrTg1rVmVRc4w5x+3AyJivh9l/FkRbwK7fidm1uVKaY3KC/3 dkeSkrr+wg4ngSQk26uY1q2I1WWls8ZkCEtRrtHY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jordan Glover , Mathias Nyman , Sasha Levin Subject: [PATCH 4.9 124/171] xhci: Fix USB3 NULL pointer dereference at logical disconnect. Date: Thu, 8 Nov 2018 13:51:34 -0800 Message-Id: <20181108215136.225961233@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215127.257643509@linuxfoundation.org> References: <20181108215127.257643509@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. ------------------ [ Upstream commit 2278446e2b7cd33ad894b32e7eb63afc7db6c86e ] 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 Signed-off-by: Sasha Levin --- drivers/usb/host/xhci-hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 45a03eff4db1..0f09ab5399f4 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -366,7 +366,7 @@ int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, 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)) -- 2.17.1