Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp92654rwj; Wed, 21 Dec 2022 23:38:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXvQrxbWQsh6zlEfzA0SBa5Y4yndyDPI//qLz8ELhhQY2eHAe1oVABe0/0ewyro7jy1pZ8bJ X-Received: by 2002:a05:6402:33a:b0:468:3d69:ac81 with SMTP id q26-20020a056402033a00b004683d69ac81mr3947357edw.29.1671694698630; Wed, 21 Dec 2022 23:38:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671694698; cv=none; d=google.com; s=arc-20160816; b=V1+KhesUgPeWBxGj6GGc9ZkC2Hy6sigz/a+nwcZs3EliHGZwgFvU8eY5n5+Qh1xEws 1JaJWwJRX0mlz8Y1z2uIjWpEVBjAAWqSGnWcbHJPZGlWqAOdBaTZTXeM2QI/WtVpRUly q8BQaMUMh9gCpI6qkvN5jYziPDOilDTO3mDJ+OTRXfOxTUwLCmt+/AyVxz6p5lVTUbCs Sv8dujnObcnHyFW+xYB4HocLzSFUp2pmU1+YXhH9C+mZydPvlnEAhkWHJZVTXo4qRJxG nTlsUaau2aG/Z2GEmbIX7S8EduM2ND5ClR1XXohYjpinOmdhOLLaAzMENbGYol1wtxTk FBmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=YDBQOU+0luLi27shrHHDO2SRv4ai6dz5pCa52is39dQ=; b=zakAIY7Wbh6CpSeAXUs/pkUm85mmue6xkhM8eeKHly2qDAaiCUdDF5db9KmSzXYYSE 7uz6JpvSY1N/Yzya9PHJKNRFVef4Uxh6BJiAvI9xEf/jppBzZkCaSuaifXCT+pXo8vOs dng5VLC3gdKi/HseVBVny6lJs81rZzw4K8s79Izx9e5s6JEAotulnc3WGESK//EJbu0j dlS8MfiQoDbyeeikXEtyu+RFCt3fRQ5hB8xiJuai46SXN6espLfAWPO4VCycotxjlC/p Y7rCZRQl6C7ZAl1gSVTrF+HEind/HYzAftf3hRg5icUalFIerWnOvDHaSYyTUpM1X4vT IB4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=iyErmQIm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a1709064fcd00b00780488c11bbsi17177493ejw.388.2022.12.21.23.38.01; Wed, 21 Dec 2022 23:38:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=iyErmQIm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231221AbiLVH3X (ORCPT + 68 others); Thu, 22 Dec 2022 02:29:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229682AbiLVH3U (ORCPT ); Thu, 22 Dec 2022 02:29:20 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1A322BDA for ; Wed, 21 Dec 2022 23:29:18 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-43ea89bc5d8so12951507b3.4 for ; Wed, 21 Dec 2022 23:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=YDBQOU+0luLi27shrHHDO2SRv4ai6dz5pCa52is39dQ=; b=iyErmQImVKKNNTRt+pdj6Ntw0fQgB9SlSnTHvhEXKX9A1ANKW81xBXTTwAdp7y2JDx u6bWXDVQuSRQjViyREmniY3etXM4sCrTuCKcLWSBbs2hRUH4CNCuWooUyMkW3gVccYEt 7K4yX2KFPokD1wGq7s9sSWJNSHYUbdlsiDfEjILmWobBEJnLEE5JkKpwvVAd93q665gT cNuCR8oY7J1lWy4ntIfDwlL/8p6TJ+dQMm7RC/pX4Z5nCOyFeagZE49TF4JrNdLLW0s6 rSYu7mEakG3h5ZTcpaFegNCEla3Mku56Zw59AYRALgXhl1zfa9ZmaGU6XRoVh96alT4o llIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=YDBQOU+0luLi27shrHHDO2SRv4ai6dz5pCa52is39dQ=; b=44E0/l77U36+AjNxd7Furq3JGCNbbmGLTReNQRQkkl7MZaACx4SUaVMqif2lCQTxOU kR+2EcxJTgAf37vNHC7CxjhI2tcDikx377UcHpjPttomLLKILjZyDg/tWAaiCO4vzerr n8rnFaGN7vi9Bl3BZ24ah9NL/kSX12Hj4EtbkedzDYP0wH3D0AwBsqsCoMSGwqXuuVcU 2NmnMQDDO719/99N5iQtuR9E+qnT+7BpADX++xKgjxxdZPoGGkVODENxkQ+7uHHv+EB4 lzl11u3kLBK3wsmKlDFHWqrXhkrAnQMvhrElHRKhob1ehxKv59k7Oe6DxtlhqX47hiDv qQuw== X-Gm-Message-State: AFqh2koqcQo2zXseUBs8/bhfWpmhHhd2GdaYC6ZCwR139hmu96yrPzUz 3/ogQ+ofm3lK7a++wvPOIUwR6BHIZmQ= X-Received: from hhhuuu.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:c80]) (user=hhhuuu job=sendgmr) by 2002:a0d:ca93:0:b0:44d:26dc:2fc7 with SMTP id m141-20020a0dca93000000b0044d26dc2fc7mr359175ywd.333.1671694158099; Wed, 21 Dec 2022 23:29:18 -0800 (PST) Date: Thu, 22 Dec 2022 07:29:12 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221222072912.1843384-1-hhhuuu@google.com> Subject: [PATCH v2] usb: xhci: Check endpoint is valid before dereferencing it From: Jimmy Hu To: mathias.nyman@intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jimmy Hu , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the host controller is not responding, all URBs queued to all endpoints need to be killed. This can cause a kernel panic if we dereference an invalid endpoint. Fix this by using xhci_get_virt_ep() helper to find the endpoint and checking if the endpoint is valid before dereferencing it. [233311.853271] xhci-hcd xhci-hcd.1.auto: xHCI host controller not responding, assume dead [233311.853393] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000e8 [233311.853964] pc : xhci_hc_died+0x10c/0x270 [233311.853971] lr : xhci_hc_died+0x1ac/0x270 [233311.854077] Call trace: [233311.854085] xhci_hc_died+0x10c/0x270 [233311.854093] xhci_stop_endpoint_command_watchdog+0x100/0x1a4 [233311.854105] call_timer_fn+0x50/0x2d4 [233311.854112] expire_timers+0xac/0x2e4 [233311.854118] run_timer_softirq+0x300/0xabc [233311.854127] __do_softirq+0x148/0x528 [233311.854135] irq_exit+0x194/0x1a8 [233311.854143] __handle_domain_irq+0x164/0x1d0 [233311.854149] gic_handle_irq.22273+0x10c/0x188 [233311.854156] el1_irq+0xfc/0x1a8 [233311.854175] lpm_cpuidle_enter+0x25c/0x418 [msm_pm] [233311.854185] cpuidle_enter_state+0x1f0/0x764 [233311.854194] do_idle+0x594/0x6ac [233311.854201] cpu_startup_entry+0x7c/0x80 [233311.854209] secondary_start_kernel+0x170/0x198 Fixes: 50e8725e7c42 ("xhci: Refactor command watchdog and fix split string.") Cc: stable@vger.kernel.org Signed-off-by: Jimmy Hu --- drivers/usb/host/xhci-ring.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index ddc30037f9ce..f5b0e1ce22af 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1169,7 +1169,10 @@ static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci, struct xhci_virt_ep *ep; struct xhci_ring *ring; - ep = &xhci->devs[slot_id]->eps[ep_index]; + ep = xhci_get_virt_ep(xhci, slot_id, ep_index); + if (!ep) + return; + if ((ep->ep_state & EP_HAS_STREAMS) || (ep->ep_state & EP_GETTING_NO_STREAMS)) { int stream_id; -- 2.39.0.314.g84b9a713c41-goog