Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2530842pxj; Mon, 10 May 2021 05:17:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXHQFKeB+ZpmyXMPgChYpcn0mh2VH3QVezzj/DEsiqlDMfRQVHJfwZEY+Fpx7+z7e5wmFo X-Received: by 2002:a6b:f808:: with SMTP id o8mr18164331ioh.140.1620649078283; Mon, 10 May 2021 05:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620649078; cv=none; d=google.com; s=arc-20160816; b=FsCF88KKDyK8vIt5lN/IpqDI7uC4zpGZW2lqh0p6CPyjzyv42w7jYzCjM/Ga/beERp M823X8Ie70SsR8t9oC8O1ZLRHpQd4Ze2xkX8pd9lg1T8k8Zb+f9CACf9+myb46kDLbKF L6pRsrwnLkUkIhkTZRC6V6CUunbkKnTnUiBorE5BgApdtOzP8L9w0mDnC2gEpA2JdvZR Vvt9cgmy5tHtEFowNEcOvlxd44tVYECmJFjoYg4gGg+eHGEE1l1CK8skTFYtPCKtDods HuPMWvOol3A9fTeyd7DZFOEihAIjwwAef9ITO9+HJJU8j68SzPbGKNpwslXn0Jepr205 gNoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Qm/E4MhvTo+pyJoKDzsz5mTPa6W5smdBTETVu7dL4GU=; b=h1KNx7Mhd64RftKzhZ97f5ISzHxHtnoI8Do61LFPA+WYmBxujiA7/rOQJSWhKhOBxw joaG6xMAOrn7TQK8s0/tjeWS1NRWAobPMrRr05YIDBhL89skyyHI6LAFQUQYd1fgc/dc 82rK/SvaVtN6sn3XaolJB4f2jIkA8r9tnQ5jbyjFiN7vGcGW+dgTVUUCqY8hhxux8y96 Hxdvx3N24zydE23qsQkJhtiyO3cTFBDpp3cddJvufCnGBzulVHN/FqiVWVQ5E0gGEdsI cJguveR8YOWJRa61Qq5BYyVPqDi1dJFqiWpuB7Aod0MrxhXk9zKmyoElh2sgw7Wq5rM5 wV0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kmlWtKhT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u26si5618321ior.34.2021.05.10.05.17.46; Mon, 10 May 2021 05:17:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kmlWtKhT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344636AbhEJMQA (ORCPT + 99 others); Mon, 10 May 2021 08:16:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:45204 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236483AbhEJLIO (ORCPT ); Mon, 10 May 2021 07:08:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5FF0D61433; Mon, 10 May 2021 11:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620644493; bh=oE3rq8mzqK9C9QSxi4EmW0MEeCJS2JJlFnlcTfcYlEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kmlWtKhTJLq6k9RIvp+iZWS3tECeC2wwGhrtxIQm0RGNiXd5XiN9WoXw0j45yhXBc lNEQOowpi3q+ONrMeS8tfoxD1//3PdU87bZRn/rOPJp9XrE3UW0iDFUxQhE7M0gJWl OpjbSXCEcQNxzd5J4gNWVLfdNiKU3EJ1J3uGOa0Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman , Sasha Levin Subject: [PATCH 5.12 104/384] xhci: check control context is valid before dereferencing it. Date: Mon, 10 May 2021 12:18:13 +0200 Message-Id: <20210510102018.311627398@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathias Nyman [ Upstream commit 597899d2f7c5619c87185ee7953d004bd37fd0eb ] Don't dereference ctrl_ctx before checking it's valid. Issue reported by Klockwork Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20210406070208.3406266-3-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/xhci.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 1975016f46bf..5df780d55df0 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3269,6 +3269,14 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, /* config ep command clears toggle if add and drop ep flags are set */ ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); + if (!ctrl_ctx) { + spin_unlock_irqrestore(&xhci->lock, flags); + xhci_free_command(xhci, cfg_cmd); + xhci_warn(xhci, "%s: Could not get input context, bad type.\n", + __func__); + goto cleanup; + } + xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ctrl_ctx, ep_flag, ep_flag); xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); -- 2.30.2