Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4598687pxb; Tue, 2 Nov 2021 12:25:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4SBZb6evALij05TzTI6iWtKvyxbB1zKeNODuFFN1Ne5umIlbYEcmZaDfdDt8poHFnKoEK X-Received: by 2002:a17:906:1290:: with SMTP id k16mr48344481ejb.566.1635881113277; Tue, 02 Nov 2021 12:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635881113; cv=none; d=google.com; s=arc-20160816; b=HDyy5bkRY3ruMy0NXYk5S7gWcDgDOQIOBuPCHZHWsV2uEnP6MitqFPaQtcyNqZwzVj 5O9tpWuI8hQmU/dSU5E5jI+4GzWzMaL2yibLOd8Jz6NcUikpQrARlSV3S/XaCLgil2U0 2vx1UCPPHdJQxxKhF5p2pXq6Rx1H95+VusjZvSsX8z4Cj1Viaj9J3DaaC8TfRXetIzYE dI55fjprfOIi6K0NK/WZx1Z+pO2H+KPbSa06mHaUPAAGwrTZVa/B04eEajEVJsTLaZxQ CmypeVpRkwdzgVkyl3/JQ54jJHGwPWQq6qDMmrFU1mnWXshBThL41lMiUyRgIOrCBt+B cJgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=budX3iw9pH/+sabLMR3HIaRQqqRMy2yp7Uo5Q9pAkxg=; b=XHQH4dO8Lljc91ksoEuKfVEKRoQK5acTrTmxVykKTfBHkuZefTYVhdEIfl/P2sJMxz YqdQhEg2YQbX7yFQpPed4K3432r2vA70ZxU/hA76l8sZtieZLvuvENhVvvG/upmBeOL5 4LXYopS9Yw5BgnCgD40iTRCbtTuX3pgzQ+7PADdUVzP3dMMyJMS2UqK/jJglJMDxAyd3 6YA5qquxBWdQLDmhmnY/Ik5+wHudw7bD0HNViZz2L2llaTHmSsF2I1RUdeSXoA7nZLjk C0BOQd6zFmHg/wu/8DdOPx04+dNLtCG2E/yayaWrBKLdGfMZ25Rf530mDjvPw5m+I8zB BY6Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r17si10903250edd.331.2021.11.02.12.24.48; Tue, 02 Nov 2021 12:25:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234486AbhKBP2J (ORCPT + 99 others); Tue, 2 Nov 2021 11:28:09 -0400 Received: from netrider.rowland.org ([192.131.102.5]:33087 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S234502AbhKBP2E (ORCPT ); Tue, 2 Nov 2021 11:28:04 -0400 Received: (qmail 1490824 invoked by uid 1000); 2 Nov 2021 11:25:27 -0400 Date: Tue, 2 Nov 2021 11:25:27 -0400 From: Alan Stern To: Haimin Zhang Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Haimin Zhang , TCS Robot Subject: Re: [PATCH] USB: array-index-out-of-bounds in ehci_brcm_hub_control Message-ID: <20211102152527.GC1490038@rowland.harvard.edu> References: <20211102074446.87107-1-tcs_kernel@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211102074446.87107-1-tcs_kernel@tencent.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 02, 2021 at 03:44:46PM +0800, Haimin Zhang wrote: > There isn't enough check parameter `wIndex` in the function > `ehci_brcm_hub_control`;due to the size of array `port_status` > is 15, so it may lead to out of bounds. > > Signed-off-by: Haimin Zhang > Reported-by: TCS Robot > --- > drivers/usb/host/ehci-brcm.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/host/ehci-brcm.c b/drivers/usb/host/ehci-brcm.c > index d3626bfa966b..4ca3eb9fcda9 100644 > --- a/drivers/usb/host/ehci-brcm.c > +++ b/drivers/usb/host/ehci-brcm.c > @@ -63,7 +63,8 @@ static int ehci_brcm_hub_control( > unsigned long flags; > int retval, irq_disabled = 0; > > - status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1]; > + if (wIndex && wIndex <= ports) > + status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1]; This isn't quite right because it won't work properly if the upper byte of wIndex is nonzero. You should do something like: u32 temp; temp = (wIndex & 0xff) - 1; if (temp < ports) status_reg = &ehci->regs->port_status[temp]; Alan Stern