Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2481414pxj; Mon, 10 May 2021 04:08:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsBKELzmIMpcx9wamQS2x+QVHfW5Y8itH8DubPd8eyeTgQCRWhiOj6orw4KlotFDwLAV5F X-Received: by 2002:a17:907:1ca8:: with SMTP id nb40mr25096483ejc.181.1620644926186; Mon, 10 May 2021 04:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620644926; cv=none; d=google.com; s=arc-20160816; b=D0dhC8Et84++uJIa+I9FDMJ2H5ej81qt4ceHSSoVtRGLYc9z6i4THaGo/kiQ5LIbTj jnxJIZpdcOfMN7pbrfum8pqDpPDTE8eBMxtN3gXLOJd/Oo02tCTh1PSfL4CSwT6FayeQ jK3T9ABYqHPZBBu9NA1Gk7Bs+JkfdJKYDSKQQoSd64fKQAyXkAP695/ky9iQ0GHuQjQA CaovV17Ut3JCh2ib31tEin7CClgYaErmQ4iMxhakJnEmWGdMrZ9p40bqkB25ZbowLm1t UHfrEN+hUSx7xWQvamA+w0E3OTohaVQ6ve68LXcqEcnz+WddbYVZOBJoHK+35SCZPNph iCyA== 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=okz3YA4PJ2mvC3qkVBVdt8ZvqiyakgHORxeUkw9D+hY=; b=MfJhqoK0ImtKPr++uilsLEYEHnGgGw4YKqdxiFPRCRyGvDJZKxrtg4VphO2lpIFG// 1sCZbYOuDPeSl1WJ0YLSQXV0O0BRcBCz+QR39YoOlth0Hgz+yRpwWH+eO9+cbKv7M54C Y1A/5BECh3+OVbrLRzY66Stxuio9boH2keFVFiMlMsCJQx7uqIa+4J0Y/xBqLaPLY7ld eBRcnKlcEekUgabz5FdrBR5r1RCeS8bAiRAjOfisOSONg9K9vgpQoiM8hsvOD2SZZBEh Tv/ASRsyf5T5XzSQaheRTwIJTDrx20RFKRjspiiAP2vHXgwoWPRpPoXb6EUkcfA0UvHi PzRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S7h833gI; 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 5si9306688ejw.423.2021.05.10.04.08.19; Mon, 10 May 2021 04:08:46 -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=S7h833gI; 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 S231279AbhEJLD4 (ORCPT + 99 others); Mon, 10 May 2021 07:03:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:59640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233324AbhEJKpg (ORCPT ); Mon, 10 May 2021 06:45:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 22C946199D; Mon, 10 May 2021 10:36:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642963; bh=ZdN9GT06305btmjfh7D0HPbNyyKvti3JuTNAtvrEzxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S7h833gIaL8mdvbpS0phY9sWvlUEknxUtXBW/yzlnNSPstwuQy6TOmwPmoeIS2TAO mTjj9pLF6QTXYBMK3EVnBHDe/lrQxXovorxmaYr1v35rS73TIiEUd2D5MwlxqZ39+a fJrmWYJt51HEExCcza/X45gNb8fWtOdl6a1oZhbQ= 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.10 087/299] xhci: fix potential array out of bounds with several interrupters Date: Mon, 10 May 2021 12:18:04 +0200 Message-Id: <20210510102007.825868563@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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 286fd02fd54b6acab65809549cf5fb3f2a886696 ] The Max Interrupters supported by the controller is given in a 10bit wide bitfield, but the driver uses a fixed 128 size array to index these interrupters. Klockwork reports a possible array out of bounds case which in theory is possible. In practice this hasn't been hit as a common number of Max Interrupters for new controllers is 8, not even close to 128. This needs to be fixed anyway Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20210406070208.3406266-4-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/xhci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 384076e169f4..dbe5553872ff 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -228,6 +228,7 @@ static void xhci_zero_64b_regs(struct xhci_hcd *xhci) struct device *dev = xhci_to_hcd(xhci)->self.sysdev; int err, i; u64 val; + u32 intrs; /* * Some Renesas controllers get into a weird state if they are @@ -266,7 +267,10 @@ static void xhci_zero_64b_regs(struct xhci_hcd *xhci) if (upper_32_bits(val)) xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); - for (i = 0; i < HCS_MAX_INTRS(xhci->hcs_params1); i++) { + intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), + ARRAY_SIZE(xhci->run_regs->ir_set)); + + for (i = 0; i < intrs; i++) { struct xhci_intr_reg __iomem *ir; ir = &xhci->run_regs->ir_set[i]; -- 2.30.2