Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp6639478rwj; Wed, 21 Dec 2022 19:08:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXv091mEgp9uUGTUBiZNowV6YRksRsjAGBBZnZRBJC1E5MmgAGXW+rHOp4sMPucxT948fFbf X-Received: by 2002:a05:6402:685:b0:470:25cf:99d1 with SMTP id f5-20020a056402068500b0047025cf99d1mr3516525edy.31.1671678504356; Wed, 21 Dec 2022 19:08:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671678504; cv=none; d=google.com; s=arc-20160816; b=nQguBj2Qrw7JdP1rBqa4jeRKZM6SKaYMj3edkGRAkeXb7IgrfkPVOqJNHO+MsdyHqw 0rlJgFHqFlfGhDFfya+o54v7ar0pyCT3G9qauuMcBI1Xw1+wdVezYtICS5K5BJb6JzNs KXSLRXNeFVZoF6ZSmUtqUroEv1/KmSwhrw84piRzMJxBxBVzUCj7ACQHO8OG7XA2yvEQ +psLgt+qK7+bS6EYOwBctBna4aEtrNTaxJdHAMq4hemuUcVrwC+rZECaiVWxOcMTBs4G nTzQHmsMXiSA4sLsFYW7ZmdY4OOXh80cetmo1mh/lRwxxVnGZ5u93UvINTdklvCXJ8Kr tOHw== 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=Efktw4hJ8FupRr4DbW13wyao5oV1mILrrOmGsxieh5g=; b=mwQ+G/8Hdjvhn3z7+Z2NadHai6JJyvzstx4cy3ZHyyQttNTfHGsWp5I9fEnuZKrbee rlbNLxInLQckBr8Kg+Nbn5SB6R9DB1oOr6mrvmaoCu8Q4xSRAFvbbGjEfvOKcYDsyWnJ 45IG0FkkjZT7O8bhptDC7K9UOY3VdiI1r9Cf1WNJhXuWn1Ey87+swRuLJ1R/SUPRcDRX Qmp0JTgCFpcwh6FNGcCrd98/WVn4xcUdyfG0NrKviU6Xrr3Us1aIRVHioaIovg+fQ9hg vofrU0sMfa0xZfdPBnDZ+4IqK8Bpxp8UCEqCz46Ks0cFwPiO6d9o7voaRnzfudkjJPRz Xc9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="hIYk/tbR"; 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 cy8-20020a0564021c8800b004674c93ecb8si13717851edb.326.2022.12.21.19.08.08; Wed, 21 Dec 2022 19:08:24 -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="hIYk/tbR"; 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 S232013AbiLVCqq (ORCPT + 68 others); Wed, 21 Dec 2022 21:46:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234792AbiLVCqn (ORCPT ); Wed, 21 Dec 2022 21:46:43 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0879EE1E for ; Wed, 21 Dec 2022 18:46:42 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-3d2994e2d7dso8016197b3.9 for ; Wed, 21 Dec 2022 18:46:42 -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=Efktw4hJ8FupRr4DbW13wyao5oV1mILrrOmGsxieh5g=; b=hIYk/tbRU8Rxy+twOLZ5QXSjOx5ydJ3m2rrO01CElOVULlqfTH9bSnDeqB/ks7/YUX xLp9jHyK4J6oOjvsSbRbz7KDaWUAkBbzxAcACmbn93oh1+dEoFtmLZdDMfnMrQY7+pPm 7Fbo1dIyXEUdo69/3LBshEmzkvvwzQACMq2AAl6+8wA5g4b7kqZNWwRlZVakPROnwARV h6uyx68TT0yjSS3IQ0YA1+klsjVkOtSn1BF1C1L3KPC7xD5LJFyMyDX9QkOS0jo//JZB kYero4XVvQ1xCqa/vfs7WY9s7ko3qxOoe1JcJmm/H+u1JXlwDLqKbqtn/SvM6XC9sPA7 gOsw== 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=Efktw4hJ8FupRr4DbW13wyao5oV1mILrrOmGsxieh5g=; b=NxrGf/SyAhZ4jgkIEGlejLHyVVD2T8z8LsRrLWvGI4JgKSLt/g3U08EJgAf6TrnsKB nvGDx/wNrgei7CnYo/5b6WTWOuEGAoERqFTQsVDC69vJrLLmpwF0e968JHx0DG8GFH3p aKOgFpwG/7/YUyafsjbu0f94tl9SBL3qysp6MlGS+6c3blX676xyeJpC3gST3wgG2CnJ 014UvUOdGauD69hls5iGOSfC37kDG+yNl3Oti2re5vqsReQsRsK2BDpJUbn+x6DP2cu7 p/AqWr+zD2yKu4MwgHphC3Hd5wGRRFLCGBP5UurPM4kcJkrACYsjbCBB3yFgNe4aZio7 JGnQ== X-Gm-Message-State: AFqh2krVh7+m8cRWZ65PJHnrGkvYSvg1sXLRY5KuKL9rrBMmO/ONBpB8 eZxR9IhrntG8jRTPocsP6IIPxpzf1Qg= X-Received: from hhhuuu.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:c80]) (user=hhhuuu job=sendgmr) by 2002:a05:6902:128d:b0:6f9:fd74:22f with SMTP id i13-20020a056902128d00b006f9fd74022fmr398672ybu.100.1671677202022; Wed, 21 Dec 2022 18:46:42 -0800 (PST) Date: Thu, 22 Dec 2022 02:46:30 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221222024630.1812735-1-hhhuuu@google.com> Subject: [PATCH 1/1] 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 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=ham 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 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 ad81e9a508b1..4a514c227db7 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1170,7 +1170,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.38.0.rc1.362.ged0d419d3c-goog