Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1733264pxb; Thu, 16 Sep 2021 14:16:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFAOdGOIJ5pxxm6UZyl9Ig1dxlFQTGaChfpgz8mZX4sVCnod+GPcQwGj9y8BARXsJUqgRd X-Received: by 2002:a05:6638:1301:: with SMTP id r1mr6160062jad.32.1631826992843; Thu, 16 Sep 2021 14:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631826992; cv=none; d=google.com; s=arc-20160816; b=uYMIVN3OFsU+KnmUVcr49kXa2w1wviYEdE8AcDV/zOZ3ayTyoxz6vgeT7BoTJ0tSpK VV5hfj2juUZDQ2d2U0ozxaVPUfVRYCWLmAf2qwi7tMXNy1QEF89kk+uT/SZ6/p/yXweN 9c2oCi5wAZsxFIEYchvJxhs1AkMKOWLjwSYBqqpGF125lld/DfBoPYWaH+EhFd8RMH9a 3q/Z1rUO8sz+0wK3aoeooruZ7f/eMAc7+hCf3vbj5YXAi8gjSYaz/RmAZ7I8Gp0bpNvO TlHducCb19ER/MLAn5rUPr5tqAw096wNpQzriEf1G2XwvR5G2suaoXbuMneE9La4kiDu G4Rg== 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=0Us9xXKnqONkUASajxT2PSK/n0eLAbSSWkQH32iMt1A=; b=QMntkoQQ/AY7NURoaPVpGfZGbdPRyNCNM77cYqgQkrJVddNTcuwBiUxecvq9CPBNZW KCh1rfWewV59Uu5Z4pW6CBWGQFI+mttYeLmGdRGhCKCe4X2cVlcOHCTxDipQhHZkUGOr zNEuNGvpl7ja3DXVZNtmziQrnEOFGLh3cDnuwomN1MVpmlar6oKa2gIKRWgWcF9Bl9O1 1iEd+6cqDzOKhdqeAzHosq0yuQvX9FXTLJhvlZf079UpgjtoyzDRQx9ufORvAqFh5Pvs es9m7JusQPjCB1Y+oQhBt0W6nPn6pGCmGYCY/o1Dg4Ie6W6l2Zl1ZSGGobjLNerShBUn zavQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u4e0epFl; 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 a3si3568941ilf.18.2021.09.16.14.16.17; Thu, 16 Sep 2021 14:16:32 -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=u4e0epFl; 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 S242237AbhIPQ10 (ORCPT + 99 others); Thu, 16 Sep 2021 12:27:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:55232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241478AbhIPQTi (ORCPT ); Thu, 16 Sep 2021 12:19:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A9CE7613D2; Thu, 16 Sep 2021 16:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808818; bh=K/PGg6kLoihHZ8O6+cHlmGT+jLvgPdnTCFTMk7Bxex0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u4e0epFlL3anwwpR7d+23O0GlIT2X8xjj3rxNh0PRwZ4chvvQbzT9j4AjzAG/Im40 4Yf8RDtQnst1uiTZW3PWliPEuL3O/iAsDangZ/jxllm1/MkdBtsUC15TGr5Ze6CpfR LsFE2z57uEBEkyir7o1EPwBBIqui1SqQVw85B+r4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhipeng Wang , Li Jun , Peter Chen , Sasha Levin Subject: [PATCH 5.10 233/306] usb: chipidea: host: fix port index underflow and UBSAN complains Date: Thu, 16 Sep 2021 17:59:38 +0200 Message-Id: <20210916155801.994045399@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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: Li Jun [ Upstream commit e5d6a7c6cfae9e714a0e8ff64facd1ac68a784c6 ] If wIndex is 0 (and it often is), these calculations underflow and UBSAN complains, here resolve this by not decrementing the index when it is equal to 0, this copies the solution from commit 85e3990bea49 ("USB: EHCI: avoid undefined pointer arithmetic and placate UBSAN") Reported-by: Zhipeng Wang Signed-off-by: Li Jun Link: https://lore.kernel.org/r/1624004938-2399-1-git-send-email-jun.li@nxp.com Signed-off-by: Peter Chen Signed-off-by: Sasha Levin --- drivers/usb/chipidea/host.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 48e4a5ca1835..f5f56ee07729 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -233,18 +233,26 @@ static int ci_ehci_hub_control( ) { struct ehci_hcd *ehci = hcd_to_ehci(hcd); + unsigned int ports = HCS_N_PORTS(ehci->hcs_params); u32 __iomem *status_reg; - u32 temp; + u32 temp, port_index; unsigned long flags; int retval = 0; struct device *dev = hcd->self.controller; struct ci_hdrc *ci = dev_get_drvdata(dev); - status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1]; + port_index = wIndex & 0xff; + port_index -= (port_index > 0); + status_reg = &ehci->regs->port_status[port_index]; spin_lock_irqsave(&ehci->lock, flags); if (typeReq == SetPortFeature && wValue == USB_PORT_FEAT_SUSPEND) { + if (!wIndex || wIndex > ports) { + retval = -EPIPE; + goto done; + } + temp = ehci_readl(ehci, status_reg); if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) != 0) { retval = -EPIPE; @@ -273,7 +281,7 @@ static int ci_ehci_hub_control( ehci_writel(ehci, temp, status_reg); } - set_bit((wIndex & 0xff) - 1, &ehci->suspended_ports); + set_bit(port_index, &ehci->suspended_ports); goto done; } -- 2.30.2