From patchwork Tue Aug 13 15:15:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13762208 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 520D5C52D7C for ; Tue, 13 Aug 2024 15:15:41 +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=ZKdswmCXlZTFyM0idsvqVj6e7l XimE0qn6WwSAyNA9r/6gkdnYwY0dP6PuMxgx9w06yS2v/jCB0ihDxfgXvtuQRoHAuXjFab/x/0xEl JjeUh5LNxIHemH/jMczL1HQXCKDYk8RcfRkepCr6mrEAGtnbPJ5VP588IMj6aaTtMzgS/7QFk7JbX H5mFMPBQhBXIFXGou17qEyI3s5uelLl+cDxdDVlTm29P6V9l+wIROLHOIIQ80vc+N2bEJ9+QqmLib OOkxakpkurAt4WECKdPqVQkBrjZAQwG+LLxrAFIVh4XJl+d/zhByOkT3cJTfQgR5rAwJvDOjwWwZA adIpX8xg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdtFN-00000004AmN-05Zm; Tue, 13 Aug 2024 15:15:41 +0000 Received: from mail-northeuropeazlp170130004.outbound.protection.outlook.com ([2a01:111:f403:c200::4] helo=DUZPR83CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdtFK-00000004AkB-0mRC for linux-i3c@lists.infradead.org; Tue, 13 Aug 2024 15:15:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TxXzihG7ID8i63Qb4T2n53zqrcIuZcuhjCzPv7akcMRxpNK/RKpRjQCAVp0HF+DnNy4hsvnpswzlYOlBnmE7Nplh8qzq1k31RyE1IN266aQmDiUl+jk1x9I9zzSmjFVAps1CI2rBT/UZh1n9cbPUuc+DtXkFFdLb6UR2j+feei3M2bkR1R9ti1Y9sQLBzVkvbBJiKG8DSXc2nyeuobmpbSwOTzs353rUus5Yxcp2pKtOgRPD7RdRtlVA+dwwORr8L5KXuaQHQveZFSto6SYKuMt494YCMICyx4p1qwXyHE5MDlVhwXzP8ARA/pLA9uXkSe2OIxwvOmftE+4r/r+s7A== 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=VK3PEGAJYXvtRbUb4mRXwD7T6ZwsMgyCFnaMo7HKAVVs+D5b2tRC4Qjau4C/0v7UZbMr7Lui1Up6duHBoZCz8SkjZUnx1Uf8n5btmV0EBsz6Zwp+Y2Mkuc7APcNCQDCWgIO8ev5ZsPOUSRiMJ2f4J7e3Ypv2w5S4YJFbrl1ZfrSiT7kC5S7bN0wmSc1SIBQidfGIH5uAw7fVwoG6ZWQuhxBg4YMoBSS1HUpMvnrv/kNSCQmuB7iHdRQBsKNzfBQZMrWwUhcyO8blEZIuosLOmrId3kRkpxaqtyafnjgt1hbKKOLD1syUJuXYus/Ku63Xk5D3FqmKlSUg/Nsn+J87EQ== 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=mgh+NriZdhkdWQGVszXiFQVjz4gCazZiavTrgqF8zmhkCexMxSIPm5k91DUeJx0pPHwTVLuTi2lj/JR8WsHBxX+IfsRDQU2Csr923Li9WxMkM/DAAyfWuSbwGdBOcHVmEX7ycp6yGibAVY9aHX9bKdrd0TSszN2QMweF/iXK6G/mWSCY2ElqIja0A74GDs+FCMZs+nqqpDQZRwShKPZoZ6IIqDHVvgXYMNRBcmij0nJeUHq3HYryeZQmharMBr3Ctkot9HSaxLHhBitAm7buPz0bckRpqngN3/+8pX8zZaAecB51UpEe7EXB2617ufVz1Oc5o7GZ0W9aFGTZH1Nf7w== 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 AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Tue, 13 Aug 2024 15:15:33 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%3]) with mapi id 15.20.7849.019; Tue, 13 Aug 2024 15:15:32 +0000 From: Frank Li Date: Tue, 13 Aug 2024 11:15:02 -0400 Subject: [PATCH v2 04/11] i3c: master: Fix dynamic address leak when 'assigned-address' is present Message-Id: <20240813-i3c_fix-v2-4-68fe4a050188@nxp.com> References: <20240813-i3c_fix-v2-0-68fe4a050188@nxp.com> In-Reply-To: <20240813-i3c_fix-v2-0-68fe4a050188@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, imx@lists.linux.dev, Frank Li , stable@kernel.org X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1723562115; l=3637; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=phlwJ/9jw9NpeTB7NJPyHYpdTuYWHApnsz953oBcxmA=; b=XkorDuHTQIQc2YaB/J76du/s/4YMDMHc9QxrNWTnndZq4FUTVLhRQHnMxHi9vJrPd+WCNwetc KRTC4kuH2UNAXmVZkFNSDUSYYCEbRPXXFN8Cl6yvWtOmOIFBKYvYXTg X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR05CA0125.namprd05.prod.outlook.com (2603:10b6:a03:33d::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB8404:EE_ X-MS-Office365-Filtering-Correlation-Id: d19db243-70db-488c-5e14-08dcbbaac663 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|366016|7416014|376014|52116014|1800799024|38350700014; X-Microsoft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hjsq4r4uCpJg8yQpBKhhf+hIc1yPkp6?= =?utf-8?q?L+HZgGUweXU1jSL6YH94tUlp8aTLWjP8fXnVOejJKAjREkYDQfYmD0cSA9w/H5QiY?= =?utf-8?q?cO1HRSMzkL1gQbdcRTeoc1YX0Z1b4k/SX4NbNWOxu9n1jCaNjSxznaFC9HkOZH2/K?= =?utf-8?q?8vD7z4mQ/OG12gtRoRKvUlnSAs1e0GTeHk75RW8OlP/LzTW/w1JcotfKbcDaDvZH5?= =?utf-8?q?snllIKbcLLKIXOFn7Hmk7zXOjkYl14gw9HfZPVMFAv97wW7cgqldgATMdcm+5qRlp?= =?utf-8?q?Mn8LlvrdpVKZipbAzOl4sKtinwR7vY3gVG5SAelVe1Kajv1jFzqgyI+631p6+lo4p?= =?utf-8?q?Au8BeTiJ58qLqsss3nbbmUhHKDFxfW8HPCVX3bcCZXZuj9U89xeCUPpAJpnfZIRxj?= =?utf-8?q?8GKq/tR9L98G1I+9IQnLRl1G6xVgg4GZAuDMGfU/hb2P69KY52+2MeGQZzI0qMqcA?= =?utf-8?q?HMxD/SBv3jW8fi1RLWZIGhgMLKbMBCD7/g=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)(366016)(7416014)(376014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?mdXk+KnxO9ezdZ64k9yFJIu6JO25?= =?utf-8?q?mZicaMCUYMpnX/NnV2S1victnWQpcwvzp0BLwPU6nKVh3+brGoeb19gwertnhq0Jm?= =?utf-8?q?Lds/Jo6P4n2JUMcc64DgTXXeNMR566e+J3ckyMwhORSoimR5pl1ZaMqCSN2ny+daP?= =?utf-8?q?lKc61mIcniCMFcSnE1Pw0Gr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1uIfCC5uR1xI2PwKc0d4qWUwNuADoB?= =?utf-8?q?+Ks8Gl/sghQdhczQysBN2geYDO8ZRm1iZuNUn8+1eVBSnG7NuP8fbVAdyWNJNeGA5?= =?utf-8?q?AW4Ok2D21fRjguoRWByyZipLSRiMspMdqcOLGe8RYS6tonIudgtokEElYnsZ0qpVS?= =?utf-8?q?rZMJgZFoQW+ac9oOacijF0GDmqNERVZK6lv1C+1ZkwijvzjAInWqCaBcbM2mSB2U5?= =?utf-8?q?ChohB6BUi9EQ7rUQQ+mKBfyVTgxIeIVhqaaJS5CirnmTEywoTbUNxl6pVGPAsF1Tw?= =?utf-8?q?PQcZzBg/X60sik00xCf6XzCs6mgEQAjhDBVU4BsPlIATe+RnB3/vHiUARLM1nLkBJ?= =?utf-8?q?iH5upeSgBAfROYiMa69RbZDkGICjKosewsLJil7qreoHIKfHMq3KncRe5G9b27AE9?= =?utf-8?q?FRjHanr25lGVbmNdKCyydftx+JfCC4dJ9RROt6hkGOsvtyxyLtZgmEBE=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d19db243-70db-488c-5e14-08dcbbaac663 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2024 15:15:32.8442 (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: O5T3FpzSUd4eWub+nl7NzZ3fkMawjLN9iDKILNeFp9n4A90Rdx/+x4AG0u0ZX1FZfJsj0s2wvyJBcsEjoSDDoA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8404 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240813_081538_285701_F6EDDB8E X-CRM114-Status: GOOD ( 13.15 ) 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.