Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2348905pxb; Mon, 20 Sep 2021 19:41:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7jTTc30fbnYexGH/DQ+YQw0v1wP07NOcxBQIDHXVCIYynYhezddsDWZuqtd9vZ06ziT+Q X-Received: by 2002:a50:9dc4:: with SMTP id l4mr8405352edk.208.1632192118565; Mon, 20 Sep 2021 19:41:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192118; cv=none; d=google.com; s=arc-20160816; b=jK5hcU00KtcrP/UUs4T8jwodxr8H3u8ZdPyyzy9esjwViF8hL4F6nbLn5m11vtc4oW SX4rJnVdRmxyUWnEFNtjRaanWRrw/d1CO8jIPuB+XINqfhWcDHOsBUtB9mrVdqk1wJig POBCW7jCnOA6iF4w4KVPv1xqaM/5pfeJBaJaWTsER4CIJFGd4fjMg8GcMnfApKC4gubx RuSVaFeW+cS26/Y3TUUET5+9Z9gWfVuWyeYwCC+ah/uYK8nQs0vkIT3FKli+h3RB2FLS 87cxUzlzXUATmYx2ZLWW5toKHR4caAIHOooodyzj+/oi++gyMQ7DeEYC19ZnTiprnCtv SMeA== 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=ZEn6e/G/Pr4fyQ50EGuVaZT6E2DogzDir9znbCjfX0si6lJ54K+psl+EpITG1LHZuh bGfQQo8bYIYEEHIcSb2v16lbEgfXn2jAI0Msr/Sb0MnmWMMx3P/QDCoqZeyrMuTGqZ46 3UWKmr2AjCJkjzftZ/1p9LI3jgwLHw5pWnRLcZi5ArFsl6ujIjeqoMtBv+zD1bupbUzw +xPTbwMTB7M1/Knsi8j1jU3qrqp9kZQVHlUR1DVrUP9RDUmKvggy/JwUPZLmnMV6LOew 4YekfEXbW9DPWdLWkLR21Q9hDdrdqJPepj/+El1SE6vKt1T3NEoRy8sPwki1UMEV+Gz3 Bu6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y2ZYwmgs; 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 hg19si19009668ejc.506.2021.09.20.19.41.35; Mon, 20 Sep 2021 19:41: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=y2ZYwmgs; 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 S1357530AbhITSQa (ORCPT + 99 others); Mon, 20 Sep 2021 14:16:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:35522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345178AbhITSKr (ORCPT ); Mon, 20 Sep 2021 14:10:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1E10063273; Mon, 20 Sep 2021 17:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158412; bh=K/PGg6kLoihHZ8O6+cHlmGT+jLvgPdnTCFTMk7Bxex0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y2ZYwmgsOJO/y7nfZqft4BQSRelVBhuMy4EshTqqhoKLGjZzdQkilw1LQ5x9nvRHX Qf+lA3sAsV8xrdjxbNk+kWPk7Je7S9UDBiinjGLB7naAK/bRSPetl7YiEtmqsPdF6M mu1Ix7GCwd34R2w9p+NEvOiiKAm4PuJjilFfQY4U= 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.4 144/260] usb: chipidea: host: fix port index underflow and UBSAN complains Date: Mon, 20 Sep 2021 18:42:42 +0200 Message-Id: <20210920163936.011358747@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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