Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3707641pxb; Mon, 24 Jan 2022 15:58:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxDfQTTM8oe6na7k+IeeT593jo24fQIHCGixCRgxNRWVdWLJIVxyoSSvn9qRE5JjUWa+Yy X-Received: by 2002:a05:6a00:1817:b0:4c9:f264:1aa7 with SMTP id y23-20020a056a00181700b004c9f2641aa7mr3664428pfa.13.1643068692839; Mon, 24 Jan 2022 15:58:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068692; cv=none; d=google.com; s=arc-20160816; b=GFoDbrsQn/cUKdM3D4IkfR3qtHT5JXeuxsKWTkE+20H7XdB4NsxtZzn2qtepF2GXsB Kwr8EDDwui1xRfMTpCwxd0kJHoA/4AVRrvCgJ2uEwM/6IrQa5vZMS/nTQPGe1X+1WNxW 86prge04m5WuT5+7GzacK5i11TnDx8teDCQkK25Va3WV/s+0Kb21B4/KAPkP19FWz1FA uyy6IoLTY8rHvGe0Hs8fCRn92UB7LLAQW3L0nFAF0/VteGCsdlFLbHfFs3GgGy4siNCo 3qNHwXn2Y/ue55fcVI05GQNklWFQ5RC5nhgEVJidb98QbWHw0Q0YAMy2eEK8DMTptu8d Idvg== 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=zdeErvBCNyUsFzoN7+sz675X0U1lc4MEILt69ZoYpPU=; b=Ebu2890ja1356K3KA0G74nVaY4QLcca/gZyTMDpd3HnlXajWvbwOr0W0yMxc7QesUp GGnuaJxE7OovYE47/6TlCdMGP/DFmEDaXjSKLdntpiY3qh4oi6Mw1KqJhhpWSwzg+m4W MGh1XINO4ZL5/s6N2QvLnDPwgXeWWXKPefjvQko6ddbfyVmKjAN6nERgxextnxsQ2qE6 764U+vdFxPwWAqZjTPNWjsWIXb2KVnN9lYOlMukJQosshEvxU/c+q3q2bJ8+6PJORHul lsWOGL0majCpP5zXGF1KpEYhmArdU7cLabh66oj8NrvKhDN1ffJiqIBtvOnT9IMmihUm 1KOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b7Zj3ZfU; 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 k4si15502626plt.331.2022.01.24.15.58.00; Mon, 24 Jan 2022 15:58:12 -0800 (PST) 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=b7Zj3ZfU; 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 S2366662AbiAXXxQ (ORCPT + 99 others); Mon, 24 Jan 2022 18:53:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1846008AbiAXXOO (ORCPT ); Mon, 24 Jan 2022 18:14:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B852C061A82; Mon, 24 Jan 2022 13:21:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3B205614D7; Mon, 24 Jan 2022 21:21:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DB2CC340E4; Mon, 24 Jan 2022 21:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059292; bh=K/eWSfljgcMu7/mLCM+m/uhl8K632G9yFcOz1ichPVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b7Zj3ZfUfX6v0H9cyqxmksu7gEG9ghYPaViczv31gJG3rBGuicNHCJWKZHyx3EHn9 gB0CaqN5MHs/2XS+PIQdDui5LpOZw/9mglcrE46u+bh2CiB8W0c++CG+vTpEUKq/43 cn37bajq3BRmM88MMBb5bqwAlEZS4UfsH81QPzyw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, TCS Robot , Haimin Zhang , Alan Stern , Sasha Levin Subject: [PATCH 5.16 0567/1039] USB: ehci_brcm_hub_control: Improve port index sanitizing Date: Mon, 24 Jan 2022 19:39:16 +0100 Message-Id: <20220124184144.386514080@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Haimin Zhang [ Upstream commit 9933698f6119886c110750e67c10ac66f12b730f ] Due to (wIndex & 0xff) - 1 can get an integer greater than 15, this can cause array index to be out of bounds since the size of array port_status is 15. This change prevents a possible out-of-bounds pointer computation by forcing the use of a valid port number. Reported-by: TCS Robot Signed-off-by: Haimin Zhang Signed-off-by: Alan Stern Link: https://lore.kernel.org/r/20211113165320.GA59686@rowland.harvard.edu Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/ehci-brcm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/ehci-brcm.c b/drivers/usb/host/ehci-brcm.c index d3626bfa966b4..6a0f64c9e5e88 100644 --- a/drivers/usb/host/ehci-brcm.c +++ b/drivers/usb/host/ehci-brcm.c @@ -62,8 +62,12 @@ static int ehci_brcm_hub_control( u32 __iomem *status_reg; unsigned long flags; int retval, irq_disabled = 0; + u32 temp; - status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1]; + temp = (wIndex & 0xff) - 1; + if (temp >= HCS_N_PORTS_MAX) /* Avoid index-out-of-bounds warning */ + temp = 0; + status_reg = &ehci->regs->port_status[temp]; /* * RESUME is cleared when GetPortStatus() is called 20ms after start -- 2.34.1