From patchwork Fri Nov 29 11:33:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13888593 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2047.outbound.protection.outlook.com [40.107.21.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3633F14D70B for ; Fri, 29 Nov 2024 11:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732880003; cv=fail; b=k6M/6d+ViLSQEXzkYc1ekdz5KQbVsIpuntr3mdz1dBAd9LqWPegsJgF6J8kdlizLVVVZopNAqQlb2Wx8Ko6LLPFgzUbqqhgudnfH7qIzRBrldg56WLnLRo+GoZHILnM74wNHHCBWmgdhFlbbA9uCyfVaoYoAYuLbu1JVGfhBh44= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732880003; c=relaxed/simple; bh=By4n+gGaJQSKhKjr+end+S5NxwfqZDwKcdouZurWoow=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=K+jl3+2vq7/9x2IQC/KcpCpVOTef62Y6frm+C4xtciCFfWvVuREZBaLXkAbY1x2BvZnMnHF8yiOdycCCUMByM5KL1CzUBiwocfj+B9B3/l1VFAEZ2nHK/cuJDSlSuNt4OZTxNkqS94rKEpvHtriLIDGMty5EP/2LUZU0fSdyVVY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=f1KlenDx; arc=fail smtp.client-ip=40.107.21.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="f1KlenDx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sHLTuelPZO+oRFzDMt56NADYBXYaSvfPphIo6rz1Bg/4rqjUl52Io/e2wmyfoBl60N18OGNfxSDkPThN8nQhLyoggWCtOlMInhs8BQN2TwflwBtrHq+mXSZNCLmkYs9ALgdMEhX8DXuK2/S5n0vFTgCcoPg9K2bADOqSATB/V32i3lsDK+kC0Mgd7L9Fnl7TsbhVrq2/UrWW9UmdSyQPv1yNEtyYfDFK7H7TrFa3ERJccj8s6z/B5Jet2+6bAIF95OldKLLuRwm+XtwHI+ckqlm0XovoWgTWzzbPP7rG3kp4nqrTc4EjQXAKXffMGo+wcHeBSCE+d/7kroqwphip7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cLfjtOWY9Mn3DB+VZb0OaOv0omjEhQBSyDXC7/zaoc4=; b=W5nvSNgTFHWdXgrLLPIcbBpaMu91vbLWvWMfyEDvu3/a9L+aL5AiXq00QX8y3ZqEeU18yi5uGxRY6gG0yABgGNkv3/y1Ju5vfJMcpD2YLpUpxNWvKY9ci51jDwPk7qycqDdfiGMeHvCTEXq6QUBFgC/XPKgD6TKrbz+No7VmYVCq34b5MTX6oBmuZ0fmEscsuqjCWVxwUi4s5Dk6YKVMQ6NVUbVBCH9U52nVczeh2bgdWvCKAAHwe4xXXrIKux0CBf6kQwJvDpbExfahs18ISwnExMz1n8mUdtREs8rok0M0dhJj8sbCVSvx367LG7KwXHJy9jqiZW/PUGZBI6xEAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cLfjtOWY9Mn3DB+VZb0OaOv0omjEhQBSyDXC7/zaoc4=; b=f1KlenDxqoBPUyH17qxPDkcUUMvhOtLbuuRWKyiOBBrAhwQiPREBs5OJjhnIixTrjpHeM9zs9nLMxYlBHgyt+/5o2GyNrqIY88yL7STnKzcg0izRcHGA49E+Jo0J2dDykTdLhYgM24caDElS0aFBMIu0dALEQJyNEOSqo1GStztGQrwdzRnCO2Z/BxfWmBX5uQBNFgY+Gd222lWB6mo2bSAz/ZxvsAm21HWpZBVZzyYdM7J+Ni//kZGFG0HTPDQEJ/cDtu7rF8vF6npZeiiszCR3KJqEHlr4d3UTaIdx6lfXAf/l13rl9MK1POFlGeXRvaoTldXJxnT+zP9GENAi1w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) by GVXPR04MB10826.eurprd04.prod.outlook.com (2603:10a6:150:226::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.13; Fri, 29 Nov 2024 11:33:15 +0000 Received: from DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7]) by DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7%6]) with mapi id 15.20.8207.014; Fri, 29 Nov 2024 11:33:15 +0000 From: Xu Yang To: peter.chen@kernel.org, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, imx@lists.linux.dev, jun.li@nxp.com Subject: [PATCH] usb: chipidea: host: Improve port index sanitizing Date: Fri, 29 Nov 2024 19:33:18 +0800 Message-Id: <20241129113318.296073-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2P153CA0025.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::12) To DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8822:EE_|GVXPR04MB10826:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ce5f502-18ea-4015-6ead-08dd10699d4c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: /6aJIkczYaJxr6XG3LXChmDsXiwoEa7h6WE18eNXM50w0o9GQPKEqPij82/0w2zHSe2Y0UkCHZ6DxFeU5/k3CBOVK02UMG9httkDvHJvAubl1/t5KCMkjcJ3O64JfEBpyO+YzHKRysNLUFHFzBcK8SkwNU6ijK+L01a5mYTU3mW95FlZyahgCmdBy9xc5pMmzF5hLodWMonOt1MmyzJRzU+2i6wc1tX3qpCCITn6XfFPQhUjBe5sA6jiAMSnsteYxAaVWulrCdS6wASILJZkDpWFGaUGSkarZEQGwn47XTqLFtwo7igqsArYiIBsqYhU/AbsDX3o5etVdl5aPEkWiI+5DchpGR4O6BERoqqDq344BqWyjUM5efsR5k0xkXAfGwzJGggXwLbunhlwN8KkMZeg1bBQULU2hTFfm12UjAlMJw+0Loanmytosw9kaPqeEnoHRAEwWvrxIOoszYpowIwgguv1+qd25Tv5YwnvE5g7v/KLDgEMz4uJY+QEUyapH2YUgIhtfJBkXpLR1OT2pXiuD5cnejN3IDGlxrLFnD9ObuqykUyHemI17NWZq5X7FrsU5jmoCrm8XoSNTdvl1/qIdsnCEqy717jUGczB0MXZWb4BQbR7mc4ATM23QOcpJt5TBbF8cTdV7O0CFlD5QR5rwEiHISm9anwLZeedqqRmtCWs0r9tzErGOyisvexPtorRPkEC75NIhtmIYEYUh5AZ3JfFux1hWX49AuUBGwBU9VnLWW9l34nq6N0/1kysotdE/5EZbIbVXFcuWwanIqiXspBh4cgUmPnGpBUYtKoWvUvMAFNj/Avr7mFIbdU2lO225SvQjzApgfXYD43LtXtmazsT7r8fr5vGnjzdoTQoUR4Tj6xyJojLSMzciFhtOW/JecZrcAyecTFGLZUk/ZFyV3XMitfFKhMbWsrgeiyD5kcVb1ETyslgj8SDF8RlVZk0HbHMOP38d1IuPywTWEuCvZ31B6G+1mLN6pY1V0l5/m8oECCDLCv5TEiy16Ge1Y6z7Zd2bBE0XM8ov0+ccAJKucPrqukeitjP6GJxbh14SPUQIYb/rwJPGcEF4gnqtHBxHVjdsbSJJldTO3VWOoO0eTAuJck+JT6nNHgcD0yDO6ZNsXMdchIiQxluFBhrP3agkFRoFnUMxvMWevWIcIsMqGXhx4QRp3aLM+P3sE8d/dFhHwMwoZe1WIwA4yd1BhzHq9iA3/1QJ4dg2LuOWtG1eWEsN4+QQGe7Iy22h74vytO5rpPszBnPlcLQrqtT2tznNZbbadTTLBgzzamVkoK7lDAHLVdMgTWrDHBEBSJe7EvSQtC4MsmClNYqJa9j5ZzGZ7Cyc8MoeeH9kIgLhmALIc6tfRsCWXXs9lThe1Ca11SzmjIar9OfhYRf51okk+8JeD6Wo2T98UfJb4MtGw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8822.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSp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+w32IBpQbH7Cx8DOjxGYCO+GjGq6g7zpC/r9zXE4mbCVNqhJhN/RWuZi+GKO9f9y+ygJ73U8oQu9iCKbX+3c44nvNy3PB/r/i4frSQU4cbSmo9Cf4kEVTgIFO5Q2wwZRB8sYiQMDexjr4XfTCsdNyD3pxPJAsofqGwzbYvcOQdshGsVHi4wccnn9AlsDA5RuACezPd4OVZ47UqtIydtQm8PXltueTZGZ/ZYMHaSaqqxzeuSjN/zDvzKeG7SZ/8Hm+voXKCENaJXRoHBoqF/ZJirbbPjRFN5J49dAuDi6oMUsiC5jceyxqtZ9g6Gl9uAyjJgNPhhWGnHa9vGjYjVSIERhrQLGpyCHtP8rlZdgzaZbCYkD9BubJOwd0gQQfzlqNQj1GYZOz4sfhFOb+J5u8VJPIiiezKuBh4CcW2zW0yVfPcvySCsgNo1CflRUZVx6ZsdauQtSLu9/zKb5kqcFyxhzxHplZJK6kzjlU8beB4ao1fRDdE2IYpOyvylBP9OPIYsC3rkiEhWaH X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ce5f502-18ea-4015-6ead-08dd10699d4c X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8822.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2024 11:33:15.6766 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lEET14COpLVnhb60efFtVKC7rpJ0D8j1aiMZi9kw4xQ1pOUz75GpGgjNhsR77+5fkCwAcWE4MkgJ0x9Zt0IRog== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB10826 Coverity complains "Illegal address computation (OVERRUN)" on status_reg. This will follow "846cbf98cbef USB: EHCI: Improve port index sanitizing" to improve port index sanitizing. Signed-off-by: Xu Yang --- drivers/usb/chipidea/host.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 0cce19208370..442d79e32a65 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -256,8 +256,14 @@ static int ci_ehci_hub_control( struct device *dev = hcd->self.controller; struct ci_hdrc *ci = dev_get_drvdata(dev); - port_index = wIndex & 0xff; - port_index -= (port_index > 0); + /* + * Avoid out-of-bounds values while calculating the port index + * from wIndex. The compiler doesn't like pointers to invalid + * addresses, even if they are never used. + */ + port_index = (wIndex - 1) & 0xff; + if (port_index >= HCS_N_PORTS_MAX) + port_index = 0; status_reg = &ehci->regs->port_status[port_index]; spin_lock_irqsave(&ehci->lock, flags);