Received: by 10.223.185.116 with SMTP id b49csp6349345wrg; Wed, 28 Feb 2018 08:00:50 -0800 (PST) X-Google-Smtp-Source: AH8x227DERfZILG6OILVr6Zca79VHgUAMmJfD/r5BL7xYdXyl/PPj/gur6hFb+Fka4droM9lXpoc X-Received: by 10.99.125.8 with SMTP id y8mr14563277pgc.241.1519833650193; Wed, 28 Feb 2018 08:00:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519833650; cv=none; d=google.com; s=arc-20160816; b=uVwAHq4hG+EWR3CdrLyb9iHGl1DmfWigIywQHxdSr1DGu6NUBIqWn5P3VanFjBlX6B dQaDj9xXM1skZR1O/Y6tOjbZ5NjvTOoRX/+EkznxusTMnDDfds4G2LQd2fDO6MJcnWuc v28sTYvFemBAR2s5iyRO2hdYuf6Q8Qz8CcRV7E6r3QFV423glugNtXYdF7dlz9f+sop8 OuYj3z4pZtBIqFL6F08fWUqBVm4nD/8Yj1+b7MVcumRGaF2r6mmtm+dNGZBvvCT+ce3q Llr/c/5R16Ep1HwFnc9sI95chaSNndRLN9EaKERw2FVRjNTo0sZuJrOpRdmbG79lNcvX OLQg== 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=tyIPU0GNxmfLVCOyy0+O6onixUyrNk7PqYOe9gqZOQE=; b=ZDvC1eFH90gEscIZhUdNtWT3ohTpBT8zXyoWClNnQ9D/vLbXqZhfTVwdoPKhDLaicx TxTmd8seNVBQXWqt84WvZil6q2gV9vUjjwDq3rU9NM4P4PDN1TEITsuZaIWclGyglj95 F5ztuR2DxC8oGHy9fc+EvGkT79jojHry1uRrsvhfNqdZIFpNO+YG23OwGv9wT7gBAUkN D1L3RcahXWN31TzcyPgqWJuSV33aRxBDj8L2OpIsR7c71sONPQKSs53ibRIrTwoVIMlC +HvKjBh9KmicdpkFQV6KRy/IGUmMF7vvEgKdrR2wGlYHJmROXnVEgKjwdPjs4Mt129jO jPFA== 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 f3-v6si1408109plb.717.2018.02.28.08.00.34; Wed, 28 Feb 2018 08:00:50 -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 S934374AbeB1P7Q (ORCPT + 99 others); Wed, 28 Feb 2018 10:59:16 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34611 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934361AbeB1P7O (ORCPT ); Wed, 28 Feb 2018 10:59:14 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (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 1er3Yu-0006Xd-7w; Wed, 28 Feb 2018 15:22:32 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Ye-0008Q8-9S; Wed, 28 Feb 2018 15:22:16 +0000 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, "Guenter Roeck" , "Guenter Roeck" , "Fan Ning" , "yangdi" , "Li Rui" , "Greg Kroah-Hartman" , "Yu Chen" , "Mathias Nyman" , "Guenter Roeck" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 047/254] usb: xhci: fix panic in xhci_free_virt_devices_depth_first In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 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.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Yu Chen commit 80e457699a8dbdd70f2d26911e46f538645c55fc upstream. Check vdev->real_port 0 to avoid panic [ 9.261347] [] xhci_free_virt_devices_depth_first+0x58/0x108 [ 9.261352] [] xhci_mem_cleanup+0x1bc/0x570 [ 9.261355] [] xhci_stop+0x140/0x1c8 [ 9.261365] [] usb_remove_hcd+0xfc/0x1d0 [ 9.261369] [] xhci_plat_remove+0x6c/0xa8 [ 9.261377] [] platform_drv_remove+0x2c/0x70 [ 9.261384] [] __device_release_driver+0x80/0x108 [ 9.261387] [] device_release_driver+0x2c/0x40 [ 9.261392] [] bus_remove_device+0xe0/0x120 [ 9.261396] [] device_del+0x114/0x210 [ 9.261399] [] platform_device_del+0x30/0xa0 [ 9.261403] [] dwc3_otg_work+0x204/0x488 [ 9.261407] [] event_work+0x304/0x5b8 [ 9.261414] [] process_one_work+0x148/0x490 [ 9.261417] [] worker_thread+0x50/0x4a0 [ 9.261421] [] kthread+0xe8/0x100 [ 9.261427] [] ret_from_fork+0x10/0x50 The problem can occur if xhci_plat_remove() is called shortly after xhci_plat_probe(). While xhci_free_virt_devices_depth_first been called before the device has been setup and get real_port initialized. The problem occurred on Hikey960 and was reproduced by Guenter Roeck on Kevin with chromeos-4.4. Fixes: ee8665e28e8d ("xhci: free xhci virtual devices with leaf nodes first") Cc: Guenter Roeck Reviewed-by: Guenter Roeck Tested-by: Guenter Roeck Signed-off-by: Fan Ning Signed-off-by: Li Rui Signed-off-by: yangdi Signed-off-by: Yu Chen Signed-off-by: Mathias Nyman Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/usb/host/xhci-mem.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -982,6 +982,12 @@ void xhci_free_virt_devices_depth_first( if (!vdev) return; + if (vdev->real_port == 0 || + vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) { + xhci_dbg(xhci, "Bad vdev->real_port.\n"); + goto out; + } + tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts); list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) { /* is this a hub device that added a tt_info to the tts list */ @@ -995,6 +1001,7 @@ void xhci_free_virt_devices_depth_first( } } } +out: /* we are now at a leaf device */ xhci_free_virt_device(xhci, slot_id); }