From mboxrd@z Thu Jan 1 00:00:00 1970 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 12C79C55822 for ; Tue, 4 Aug 2026 13:38:34 +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:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OeTtFx/+m9k5WnFlOb4+G/WtMko6Xxzu8w9u91R1nd4=; b=HKxczaA2asOhoK atjZm9um3HCT/PySPMxI9/ABPiuybbre8YFqRri0MV5bZb0Xfb1Sc5snLFoRICqCC8LgbYRmGRVC/ iJR6mg0GECdOPJYgGeB+oobhWsoebBcX1HadZcO6RGe9zrV0uhVtcN4Co2szABbjYdFryZ3zisRaw E6R2BJPWediejdHIxU1L344av9BPOhsVU3LGl2fJJnOHSpOx9IcyyBkCfz70HYtq6sKDrmKREHb8P P2lxZWmKNswVkKgdXCRLGwFmnQ2IMkdMvY+z2HWmVzTMF6Y3VUF3iUmC1/te1Ft+850Fq2vq+alKC wk9BwN5bDswNxY2SgT5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wrFLl-00000001wT5-3HSs; Tue, 04 Aug 2026 13:38:33 +0000 Received: from mgamail.intel.com ([198.175.65.17]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wrFLj-00000001wP5-2uGw for linux-i3c@lists.infradead.org; Tue, 04 Aug 2026 13:38:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785850712; x=1817386712; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LKC0QMMd/XJevryXpaROjCj9xdLCE4mgoSSaTfBGOkw=; b=NVv3AVg3e020crnsEVP2jDT8vB5YIOaltOYi+WYpApzckqZLuk90BNN5 uKn+NMvTuDaTG8qWRppQbwHCKdCUL2Q5SUQPvrVbmPwhQ1Da69QpkDpEb qXPpNmmORWYQwjmL2+qzsMdYC02LfvBud9p9wgFPXNrpwzJZQ9NAr0+O+ MGij1/Feo9crgpltPbgx3XutyQZRGdgOIfcJ66CbD7WW6TwGUTlIjakAL hojtu6BSFceVhIxwBse+vj8UkwHI94FhqnlEWJNjTjmINetkYMjkFjCv8 XiC6g0DdGcwliMdVm5aka12PyvKSXfnbicP+YLP7RIAIyDESBdVHRqxJc A==; X-CSE-ConnectionGUID: DLWjX1LrTaCYbV5Shp+Afg== X-CSE-MsgGUID: umEVvGbnS4GIjGn7vbSL+A== X-IronPort-AV: E=McAfee;i="6800,10657,11864"; a="86410108" X-IronPort-AV: E=Sophos;i="6.25,204,1779174000"; d="scan'208";a="86410108" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2026 06:38:31 -0700 X-CSE-ConnectionGUID: YYbXWcnOQa6ckgQl8WVVmQ== X-CSE-MsgGUID: uFswiDBTSTqxPCk+c6eisw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,204,1779174000"; d="scan'208";a="263501013" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.132]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2026 06:38:29 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, akhilrajeev@nvidia.com, rafael@kernel.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH V3 04/14] i3c: master: Fix use-after-free of master->this Date: Tue, 4 Aug 2026 16:38:00 +0300 Message-ID: <20260804133810.184905-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260804133810.184905-1-adrian.hunter@intel.com> References: <20260804133810.184905-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260804_063831_779491_2F7D3DD9 X-CRM114-Status: UNSURE ( 9.64 ) X-CRM114-Notice: Please train this message. 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org sysfs attribute callbacks for the master controller device dereference master->this. However, master->this is currently freed in i3c_master_detach_free_devs(), before the master device itself is released. As a result, sysfs accesses can dereference a freed master->this pointer, leading to a use-after-free. Keep master->this alive until i3c_masterdev_release(), where all users of the master device have gone away and the associated sysfs state is being torn down. Do not free master->this as part of the normal device detach path. Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter --- Changes in V3: New patch drivers/i3c/master.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index abb582645a2e..4839c1c186eb 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -842,6 +842,11 @@ static struct attribute *i3c_masterdev_attrs[] = { }; ATTRIBUTE_GROUPS(i3c_masterdev); +static void i3c_master_free_i3c_dev(struct i3c_dev_desc *dev) +{ + kfree(dev); +} + static void i3c_masterdev_release(struct device *dev) { struct i3c_master_controller *master = dev_to_i3cmaster(dev); @@ -854,6 +859,8 @@ static void i3c_masterdev_release(struct device *dev) i3c_bus_cleanup(bus); fwnode_handle_put(dev->fwnode); + + i3c_master_free_i3c_dev(master->this); } static const struct device_type i3c_masterdev_type = { @@ -1125,11 +1132,6 @@ static void i3c_device_release(struct device *dev) kfree(i3cdev); } -static void i3c_master_free_i3c_dev(struct i3c_dev_desc *dev) -{ - kfree(dev); -} - static struct i3c_dev_desc * i3c_master_alloc_i3c_dev(struct i3c_master_controller *master, const struct i3c_device_info *info) @@ -2286,7 +2288,8 @@ static void i3c_master_detach_free_devs(struct i3c_master_controller *master) i3cdev->boardinfo->init_dyn_addr, I3C_ADDR_SLOT_FREE); - i3c_master_free_i3c_dev(i3cdev); + if (i3cdev != master->this) + i3c_master_free_i3c_dev(i3cdev); } list_for_each_entry_safe(i2cdev, i2ctmp, &master->bus.devs.i2c, -- 2.53.0 -- linux-i3c mailing list linux-i3c@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-i3c