From patchwork Wed Jul 24 15:45:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13741126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59EBFC3DA61 for ; Wed, 24 Jul 2024 15:46:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7AI6/H7SBpYEXJZDstCYiDrkAz7aOHj8mZS6LynlF9g=; b=GGtyj00G9zGT8i826al8/0QWR2 2FCDx9D+b1MLxMGDqTnGGAdbcfieyYGSi2Ybn3q7/VA56j+Wjh0D3a0tuzf1+HQTXOL4x937X4QRn GNgJ0T6Jfj7xn23Z7el4h5VnDKxP5vaHR2aJDpvyIJJvCM9CLg39rjtheer+tlwJwdpfcXJN1rLHt 2I496/NZK3BAupUucY+VH0Ou2jnLLh4O+ECJ11FMNB5dLa4AURB8BAAnKQRzZ/cRsSdy98PK3Jqt5 CBUsgsYIrCQGXWUJsheG6tVNFGdijLyka0D1jaD8hnSHGbYjunJJhFhKT7Rko9rCOje+aH0bxK6lR 3rf02ToA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWeC9-0000000FoxX-3jNx; Wed, 24 Jul 2024 15:46:25 +0000 Received: from mail-am6eur05on20627.outbound.protection.outlook.com ([2a01:111:f403:2612::627] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWeC7-0000000Fouy-27xG for linux-i3c@lists.infradead.org; Wed, 24 Jul 2024 15:46:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QuS6vfRobAMe7ErioX4SAqCZG4KGuoRDl4R1hj5/BjaO6qCBXDhFRgJSqH6xLuY7m2mfX280EqHDhB9Vx8Yp6blxevTypxPD+ETrzuxdV5jdl7UB3+Ttu5reKOJbbrd671jF7C0gPoT0K7naZThJ2Uu+5oMgawg2nKMLHCtQGYvrdLgcAaeF6ysUyjn2jEYRstmtJvKSXhYE6ORNtoAAgf3ENzeSe7Fj4vTyM8F2eXT9y35WpskVRVlO6ldDJgGGTf+NbJKaBEmg17AA44xsRTvAbVoLDLQ/OF9PdqryGhREjPhpj3JE55Y82X2zDkedxyHkGsFK2RIJvSkyli4L5Q== 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=khB9K849nl/MU67dxO7G2LRxt5J+Bs0EnkTKFa+J0gI=; b=GguIrD33wfZVOlWx0Wf6FlX4el4py3JlynM2di3srKwKfhhGRd81u5DG3/DdmWvPe6lWU9kgpd0dnKnNHX9CCAuh/AymJE5JBgef/bDtKVZebTRHM5C6rzSYR+vnH/n4mnCOdpK/ZdgubulUSF5XQ9yVVGyh8DdJiK1PVkLoJosgf4iUITOT26iHVwtoaRxKrUPOucRE0CzdKQIeZ5VSM43zsZYiuWFfq7WWOjM0sBQ/OHOMyQFEJSLpR3dHYL5eA7coxSvaHymkKXnfHQCh7+YvuoKr/+n83Va/2fhGGNWhm4LmZaUqZmOmVjvhRrlzrSUqduxP3uXOKS+hA/AO8A== 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=khB9K849nl/MU67dxO7G2LRxt5J+Bs0EnkTKFa+J0gI=; b=CxXCMnv03TqgWktSBg1A+7x3Wf8DNLctSeAjyfiLm3O1R2YBwysXjXw9Jyf3D3CY5Mci6AigIqvvg8qQonyfM9P8FkRN9hIrLD09a3wvtXiHu31NjBNY56kKIf4IAPgtmIG1GCEaje93rAfTaSUPO8q4/isxGca55ndfTQforAunaY0yDgZg48R2xEiqgaH1wP0iSG5HTA1e8hb3a7fXdSRNq5o+k/5wACrTjF45qxKd5jQa6jyI/4AdS6xQ/V8rjcbWFatX94OqK45Qa5p/+Oq52RbqDVXg3CPvAu06+8NRLSvNj0FawlqQ4JoRWk8SBw/5QTsXN+4z3ZPR7QqSMw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Wed, 24 Jul 2024 15:46:18 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.7784.017; Wed, 24 Jul 2024 15:46:18 +0000 From: Frank Li Date: Wed, 24 Jul 2024 11:45:49 -0400 Subject: [PATCH 4/7] i3c: master: Fix dynamic address leak when 'assigned-address' is present Message-Id: <20240724-i3c_fix-v1-4-bfa500b023d6@nxp.com> References: <20240724-i3c_fix-v1-0-bfa500b023d6@nxp.com> In-Reply-To: <20240724-i3c_fix-v1-0-bfa500b023d6@nxp.com> To: Alexandre Belloni , Boris Brezillon , Parshuram Thombare , Greg Kroah-Hartman , Boris Brezillon , Arnd Bergmann , Miquel Raynal , Conor Culhane Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Frank Li , stable@kernel.org X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1721835962; l=3637; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=phlwJ/9jw9NpeTB7NJPyHYpdTuYWHApnsz953oBcxmA=; b=bFam1yY7BeGLoVc3lylUfnBvI0dojbpBk9GROZZaVWtnPAY0urR9VS5sJ0CzXLcUYp/FN6Z6r AqzW7pFiOXCApRF9lwBMPP7wBPBbgsfPv6QoV3bH0gT1OdPR21aEPW5 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0008.namprd17.prod.outlook.com (2603:10b6:a03:1b8::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DU2PR04MB8599:EE_ X-MS-Office365-Filtering-Correlation-Id: 245238aa-7814-4c7f-1404-08dcabf7c1fe X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?ut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ehB4LZGokZxPf2XHx9sDTl+a02X1gA+WphBr7Y?= =?utf-8?q?VIXpnXglt0EDCwzyYVtt3alP0BeLcSvhhN86HyGuMcocRuygZy7bUs/Cye26MquHd?= =?utf-8?q?smcO9h7tsX4Hb13X7skJuE560lB1BxaAYsDIh2wHNxKtUWQMamBGOJRKucnd8aDNB?= =?utf-8?q?9pDolWeDy2caaYtyjwTawZ7nR3zyBSRyUEy8asasQKx4l4yxQAoXPxLxLu+BLMprd?= =?utf-8?q?7S3LX51fdP7356V28bO+VUCaMfmnYwFnTStRU41+bnwQ5QWYgqJIFqa4WnSCwhDxC?= =?utf-8?q?fXpBDYxCwCoMtlhAtm38lts2eR6qa1GzKTAFY3GSgF/bdtJZzIkxC6BNr0Nz4W1wi?= =?utf-8?q?Q5mPAveTQW6ogZUXLgJ07jcBOqCVUXK8OqNLiXDfd0SOB3eoYJWufhVDy2vhC/UZw?= =?utf-8?q?yV4p0vK7kWnLNtKGlV+hWLk94m3NxvUg+Ig87IBYnpJUp9kiSlG3aUXYDm3TXbVLg?= =?utf-8?q?172uvD/6Pwlu1kUyDmMCJstmzubB6bUDMw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(52116014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?qiPsUc+WKTMDgv+XRRQHvakT3XYN?= =?utf-8?q?5RbMFuR6m+nZ4AfnD4A25yOD0y1BvtYB55n1rAGS+Sj9cA/KMKrIT4r1r9opjA5lT?= =?utf-8?q?vF2YSqcT0Nbq13jLEaAB4lj4AmxViXQU/01xpdk+oH0/3IyQ/BKJ0jNuQ7GzV6f8i?= =?utf-8?q?kHP7Hqypy2n2XGH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T2l106yl3FPp3Y4SjPfzvBctz4WjhhKy3ofMFl3h?= =?utf-8?q?RRriYw3j5g5VdqsS4+foDrad3uX+c/CBiZHTD9Qa2WE5KLfB4jG55MPcki01DffLx?= =?utf-8?q?P/VVEHKc6KSd22cP49CvD8rqHmJDMHengZpSWnOayX3iOcER0u2OoWBrgdHvOSJjG?= =?utf-8?q?AcD1L57pDm4qWGzct0AX8ZkKranSGEJqwnewykqO7wzTqeTl8+TJGn9DGB4du1Pu8?= =?utf-8?q?SJQKrmOt6f4CiiN45qzK8Bqmu0XJ+b1WWd9GWLSR3gPLgfEkwjOg6IK+BEJW3FpUr?= =?utf-8?q?pVuAqk25Iz1EjGqGhh5/vCYR4LIDyFnVAehx3E5MmZX16xpnqphAF5Rfz2sIkIs1M?= =?utf-8?q?vozqFQWujjeZl84BNZlLyX0+gyNjSiwsRS39lmiiChTcocz/L8rl71wfy8Fh5Yool?= =?utf-8?q?q9gwcr1lb8UndUM8LckTXLjRMVR0gQ+tLPWNZfBz5nW/U5EZb+jDn3eHau2X76pdm?= =?utf-8?q?y6KG1SvaGj0O?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 245238aa-7814-4c7f-1404-08dcabf7c1fe X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2024 15:46:18.0751 (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: dZ8Dms9LO55cyO0YVZc/zaLhzO8f71rYPTmRbm2bnPIRWOjEFB03YV/gPYqjyWkz7McShbdfTM4x/Fy5VLk7WA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8599 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240724_084623_588903_6FE786CD X-CRM114-Status: GOOD ( 13.11 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org If the DTS contains 'assigned-address', a dynamic address leak occurs during hotjoin events. Assume a device have assigned-address 0xb. - Device issue Hotjoin - Call i3c_master_do_daa() - Call driver xxx_do_daa() - Call i3c_master_get_free_addr() to get dynamic address 0x9 - i3c_master_add_i3c_dev_locked(0x9) - expected_dyn_addr = newdev->boardinfo->init_dyn_addr (0xb); - i3c_master_reattach_i3c_dev(newdev(0xb), old_dyn_addr(0x9)); - if (dev->info.dyn_addr != old_dyn_addr && ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0xb != 0x9 -> TRUE (!dev->boardinfo || ^^^^^^^^^^^^^^^ -> FALSE dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0xb != 0xb -> FALSE ... i3c_bus_set_addr_slot_status(&master->bus, old_dyn_addr, I3C_ADDR_SLOT_FREE); ^^^ This will be skipped. So old_dyn_addr never free } - i3c_master_get_free_addr() will return increased sequence number. Remove dev->info.dyn_addr != dev->boardinfo->init_dyn_addr condition check. dev->info.dyn_addr should be checked before calling this function because i3c_master_setnewda_locked() has already been called and the target device has already accepted dyn_addr. It is too late to check if dyn_addr is free in i3c_master_reattach_i3c_dev(). Add check to ensure expected_dyn_addr is free before i3c_master_setnewda_locked(). Fixes: cc3a392d69b6 ("i3c: master: fix for SETDASA and DAA process") Cc: stable@kernel.org Signed-off-by: Frank Li --- drivers/i3c/master.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 4281f673e08d8..c8eaeada54781 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1531,16 +1531,9 @@ static int i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev, u8 old_dyn_addr) { struct i3c_master_controller *master = i3c_dev_get_master(dev); - enum i3c_addr_slot_status status; int ret; - if (dev->info.dyn_addr != old_dyn_addr && - (!dev->boardinfo || - dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) { - status = i3c_bus_get_addr_slot_status(&master->bus, - dev->info.dyn_addr); - if (status != I3C_ADDR_SLOT_FREE) - return -EBUSY; + if (dev->info.dyn_addr != old_dyn_addr) { i3c_bus_set_addr_slot_status(&master->bus, dev->info.dyn_addr, I3C_ADDR_SLOT_I3C_DEV); @@ -1931,9 +1924,10 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) goto err_rstdaa; } + /* Not mark as occupied until real device exist in bus */ i3c_bus_set_addr_slot_status_ext(&master->bus, i3cboardinfo->init_dyn_addr, - I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT); + I3C_ADDR_SLOT_EXT_INIT); /* * Only try to create/attach devices that have a static @@ -2094,7 +2088,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, else expected_dyn_addr = newdev->info.dyn_addr; - if (newdev->info.dyn_addr != expected_dyn_addr) { + if (newdev->info.dyn_addr != expected_dyn_addr && + i3c_bus_get_addr_slot_status(&master->bus, expected_dyn_addr) == I3C_ADDR_SLOT_FREE) { /* * Try to apply the expected dynamic address. If it fails, keep * the address assigned by the master.