From patchwork Mon Oct 21 15:45:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13844350 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2087.outbound.protection.outlook.com [40.107.20.87]) (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 416631C5794 for ; Mon, 21 Oct 2024 15:45:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729525538; cv=fail; b=U4dQtdRUTX8QLa7uPEzX5VcD0B9iLHt0iULbH7e5LmZuO049dkT64Z7IXexoSZDly7f+4FeX42jthasm7ZptLueZPaOyEzhaQ6LJH+3SrnDmZEoQXjztLCRwoFQIivICorP4Ny4wsbInoGk5nThrQRX4sUpNQ6/6okjib1zvdFg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729525538; c=relaxed/simple; bh=Tya2XmHY6NH6zMFyqVEsaXc69z5sFxx57Xl7UdOsNx0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=aGMZLFnbA/RnbMJnaGxOy3L6z0ttv0VtlJJA8dgw8Yr83UYyguJ5QhFvjrRTbbg+hwskUlj+A05/OnthYB0ccRB7Yokr/f7k5ZqRTIrUhzeF1OcOoaGKLykBkq6FnPz8vaZhK5k2989eF6VkX1RltQhQTU/2eBrqr4D353IP8yI= 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=G2fWNOls; arc=fail smtp.client-ip=40.107.20.87 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="G2fWNOls" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iZcII9FCjwEP1qJSybE1NGLzIEGTQpUhbQlu5I63NmQCIpzO/QakS7upxUaIEq1QZdERXQqtTqqBD4Djo5nMTHuRqepBfaY+D6hk5KAcY8OUW2RfU3M/lmJvJbR+07ZNsS7+lwDVJJs603xkhaSz5EPy+M53jf//DkrT664EAdw5tZn0pFfBUNJ23EvFzRnGBcg3tyHhCs5E38NW4WLIMRiBUpcVeao1rQvbH9bPhWFpiDZ3XmiOMsQEnYWE1jbt5RbnABnibi8TD1bRkTBmWa9wkS/HGgIwbQJkL47Pyq34P7tHABJuS0l555reLdtSOZxKZSTz14e1aYL9AMbI7Q== 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=dKVFTv98vNzXpRySipXp/ftAZEd9KVV6pcUGJ8L1bP8=; b=AKqYkbbL88IwnXDO6FQqLk68ZFhOkJqzCZlqufAUQZG/cnO6A0go/Xp2LhIjUmRG8IMhDLBt5dDfHCkB/+aVVUyISpAiO/f3vmGemrABl1XoQTPyKGWZWotjj6YPTaMNv1RIoxxlngC0b8eS0dS4u9hc1iwWMVYZdEQ3SLaYGbDhov2SLBZ51QDJrWqhHGe1j2mHBWHT7hC+TOrn5Y7z/L+friuQJiKIpl67Rz/4KxeCo51GYWGxOQIpgikn6pZa/CW0diQdXaJiyEvz2HXTN5q/HDy2HG783MvnQ7zXpTGBU8rNH9XGHIwRUKkIk/qeNKtpglR+bbVEzBWcQDKOeQ== 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=dKVFTv98vNzXpRySipXp/ftAZEd9KVV6pcUGJ8L1bP8=; b=G2fWNOlsNlgzshf7J6CNrViCxpF/aPO1y4YqrZkioT6UxG+Y7LbNQI974nyBfg+l2fHGZ/01obqmpbuWDHQnIlweyyg37s0m2GnQVD1G/O3wrGYODUVtmpI36AXMseHyaxsoJEyn8PutRYbxQN9gJLfPBb4h0cGQbSVzBTohx9ZuAnGPrzV2omBwbjk36mY3njxx/jAUYzbGujZdo8jR9GA9IZ5gEk8J9W5pXZ5bu9imYwH/byU6Xuerxvzfhc+yfs2TqV9BPHdpx0kOc/iw9Mpj8aaTFhB4s1wBZHrHfBwr+hITBm5mzmSQUP47w7yTSQddFNBbI4fOPoED1ppd0g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB9PR04MB9626.eurprd04.prod.outlook.com (2603:10a6:10:309::18) by AS8PR04MB8417.eurprd04.prod.outlook.com (2603:10a6:20b:3f9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Mon, 21 Oct 2024 15:45:33 +0000 Received: from DB9PR04MB9626.eurprd04.prod.outlook.com ([fe80::e81:b393:ebc5:bc3d]) by DB9PR04MB9626.eurprd04.prod.outlook.com ([fe80::e81:b393:ebc5:bc3d%3]) with mapi id 15.20.8069.018; Mon, 21 Oct 2024 15:45:33 +0000 From: Frank Li Date: Mon, 21 Oct 2024 11:45:08 -0400 Subject: [PATCH v8 3/3] i3c: master: Fix dynamic address leak when 'assigned-address' is present Message-Id: <20241021-i3c_dts_assign-v8-3-4098b8bde01e@nxp.com> References: <20241021-i3c_dts_assign-v8-0-4098b8bde01e@nxp.com> In-Reply-To: <20241021-i3c_dts_assign-v8-0-4098b8bde01e@nxp.com> To: Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, bbrezillon@kernel.org, boris.brezillon@collabora.com, conor.culhane@silvaco.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, miquel.raynal@bootlin.com, pthombar@cadence.com, ravindra.yashvant.shinde@nxp.com, Frank Li , stable@kernel.org X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1729525518; l=3908; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=Tya2XmHY6NH6zMFyqVEsaXc69z5sFxx57Xl7UdOsNx0=; b=t6uTeFEwP7Ozw7qXtZDcbwHfNdOoyijvYI/e8WeP5EgRYpwboouO+X2Yg5vOjfl/Rj351bRPB mvO5kv1BAwnCaW1CB1zFqBO1KRBqRgauMiCn7Cigk7cglFeDN+nG6xu X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0006.namprd08.prod.outlook.com (2603:10b6:a03:100::19) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) 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: DB9PR04MB9626:EE_|AS8PR04MB8417:EE_ X-MS-Office365-Filtering-Correlation-Id: bcc3e037-4722-4d2f-7751-08dcf1e76642 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|1800799024|366016|376014|7416014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?imFkCXxzJLYhiltL0oV1WOeH6OVnhqK?= =?utf-8?q?bbfjOTYMeZRG1BSzmelePE9mJB/LLnfNbGBhbAW7/UuKNkOVpIXjFPvDh+wIIQtQd?= =?utf-8?q?GXD5wW32RIcQD02PdNBW2UW5n+D0a5d1h5NMI3i2K3RlHsJDr1bWhiPyTItptRmez?= =?utf-8?q?dZwIelG3RfWC2ZCUz/470PxwgF9FUKTMiY6W6RF05qEpCARQk7Ld5aYUdIY65tv++?= =?utf-8?q?1ajONyCJnyhl6WOqwNpVRHL17EF5npEVfRYeA+pP4g7gJeoC1saDfEeAV5fDifgXF?= =?utf-8?q?Xco+6qwSyT4JiocEA9ywzpBNN3wrl4DkQ5JOxbZ3tR/WnM+BX9sEL0O70SWhhmdj6?= =?utf-8?q?c7uQ5qDl//CeSnbOY8HNL9cNNXDeBv/RynFOstwSk105Vs9Bp8ax1PGODFdbiNOSt?= =?utf-8?q?btFa2fOof2syaG+F48o8Bi2LlgFUkFp6wjc0XMonBLoNOoa94RNQvuHnuOo0Z1jnU?= =?utf-8?q?TCyyQrcLylMH3Ty66ARdDiAE7N3zg4SbHplgZraVKXQCYzXSBnz183ufJCUnn4U66?= =?utf-8?q?lOE5HZxXjE91aegehPXW11DHLj3MRQmb5g295I2k9aoVgkQYHkvGa5ferkyRGDxII?= =?utf-8?q?/C4BZyF5JCEl1T+bh3Dhz+zwqFtVadf8TybOcEqjY+EZzdFay5ydp3Bcs1eheKg8A?= =?utf-8?q?DEXXjRiFs4YIsUMt2oCO1f4LA1GyiRfYL+am/nRUm+ZYTZFZpNr11cMu5i2ROq+km?= =?utf-8?q?K6mNv5HMrCZg5J55+TxiNnnr9xqCK3Jo7deJhVE38/tS9QV628VgM3KMOijEi/KAw?= =?utf-8?q?Q9QLtOjnNUL2jsgvODE7g5UGfNcQNF2ijsPF6xlVNPKq/HJaoLOLzOk7erGtPZmb7?= =?utf-8?q?DFMHX9bG55ujBrektl+3SPdxsd4lk+vG+XdiqvNaSVeYp5gfaOlPf+4EN3ZL7x23d?= =?utf-8?q?IETUV04qAeje4veINNjCxiH+InoLWvhc7XzwHaVBN5DIbSrqBITJzJqirX9WDe/dE?= =?utf-8?q?2VAETOcBSC0FEEG/JSn0yMR+KsyhRa7ATwiDLJei8sjS/93ipBXzcEpthRKpseT9R?= =?utf-8?q?sHPIPwO0eLxmnTaHLUpQDmEJbt640B9ZhUAw6GLTyu159+icTsrhFjRURYedBpF+f?= =?utf-8?q?ax6/rZ2EGbvP/xk9gz+jgtlCgV3cEvusxpTSj52NRbwiaVyE/TiPc9TnGGCuqGkjJ?= =?utf-8?q?SGzDfA+PIAN9ieXMryDiY7R1+LFzE9O+43j42LYo4PpHOb3UeF59p2Z09E/O7xTkt?= =?utf-8?q?2K95ACoNrfe/XSot6HRXeFA8uGDRoJf8b44FsBvPaf9wTb1qAG9VV7iFQm2pgUeBS?= =?utf-8?q?1i/oI3bVim4WL0wux7Imc5yXEzL8GvB3bBHXHor2IqoxkWMd51gyk8/Q=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR04MB9626.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?zxJetwm4VtglkCzRt8pSdRYlm//w?= =?utf-8?q?sL+osij5jWTXJvpQsxI3LG3j8ifoWA74TCMLzIFRstl0q+WHW/eIy15gR2E93lNX2?= =?utf-8?q?tGpMFcCtuJQ5XEyEGraj33FM/ud7vaJRkMaZi/p199F2kFx4JArRn+hZ4pFabdqsw?= =?utf-8?q?T15D5oJkTPAAfShSS3SkkFHYBH4qgfH7dTYh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YinKIAgN9TrLLxxTWufbb6?= =?utf-8?q?BIr8gLT2STKYU5NI7D8cdqZmHxuDEvR4p/j5v9+HQ06lSLU4Z/uwheqE5dZ6ohRes?= =?utf-8?q?ng31bpq5+kYXWrcAC/kboiBeox3eRPH9+JVUjd5pr9GUrEVnAYOZQcPLamTQW1UyG?= =?utf-8?q?BjKKWTI2dDFwV5cGt/bU9yw6ny/KnfZIhO5mRzq++nIrqdORMYVmw5/UvcIdwkioL?= =?utf-8?q?Y9qjHbftbvLlZ7kCTBZ+5+LrJ2haWL8oyoM6Hm0FDYot+S/m0a2q9gZdMw8d8ZXpx?= =?utf-8?q?hlwPdnSoP5y635K0jIF6H867rfULDBKjmpfSkTf3eLntnx0NWdGkVdRiD3k4eGH/f?= =?utf-8?q?XsNv8OASE07h6Ebf1LjOhrreSa19nMXXMyCPBD1OWJijXWyefF4Lp5x8/4/8Ycyr8?= =?utf-8?q?cE24+Q+/4gzBX7lXhNaCJEr6XXzpvjk2s3QAMWA5CCJP08bJIfGaReY2IByWqVgnv?= =?utf-8?q?AMx8ztDsgWV3?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bcc3e037-4722-4d2f-7751-08dcf1e76642 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2024 15:45:33.7812 (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: UvcSn+Fteg0Ld9qCCTMphcg28P9u2NjWLBPSSeS9b5oYXevIy6ikTWgWJeDenIINaqYotn40rw0Ehfqmz1bXcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8417 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 Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- Change from v7 to v8 - Add miquel review tag Chagne v6 to v7 - none Chagne v5 to v6 - fixed version number to v5 - fix merge conflict because change function name and macro name. Change v3 to v4 - none --- 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 1bf9cb138f77f..5a089be7e0728 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1548,16 +1548,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); @@ -1960,9 +1953,10 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) goto err_rstdaa; } + /* Do not mark as occupied until real device exist in bus */ i3c_bus_set_addr_slot_status_mask(&master->bus, i3cboardinfo->init_dyn_addr, - I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_DESIRED, + I3C_ADDR_SLOT_EXT_DESIRED, I3C_ADDR_SLOT_EXT_STATUS_MASK); /* @@ -2126,7 +2120,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.