Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E4CB63B95FD for ; Fri, 4 Sep 2026 04:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788496684; cv=none; b=u9BFFY6sB5K6NxXZosozW3IT28+ft2PCys3MSKL7yp3rQChxiBsPCiOEOo0u4ht6f4hPzzrE6d8YfW4rYwk866C3uWwQu3Vv5s/hgSONcDGAS2si+AV+SVa8EyfiEOZL6xD38NfJi/K4ZO8yoebZHr4bdJQaabmj6Dmk6y6si6k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788496684; c=relaxed/simple; bh=PWerOLX6GE7xgfj77/DZCtUh/VRALFt058q2ex6kpNQ=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=ak/YXROiSpl3Z4xr3pfNqaweycTcgW/zGxvVXGr9C21sRsfw49KoKP38TL6cWOBPy/+ojgHI4ZSHIwBodrSlSBnvm7QcQBJ1/FzdTaKSM0xDM8oscUK+BNQVJHGzO8pUjvVVKYH1LhDKhABz+9qha+jsJYFIQwlIjs/wwDcGBvs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qaU5WCoV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qaU5WCoV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74E221F00A3D; Fri, 4 Sep 2026 04:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788496682; bh=5tUb7otrqr0jTyYuMLxIkV5jwkgZ3FFfImQy8DxwY7g=; h=Subject:To:Cc:From:Date; b=qaU5WCoVB5WR6qvHKknFVtlZ+shX+PjN5HqL29jn0ze+xsj8ceNvoZLFxG1ZBb9VL mfby9ESezVP1qJtmZlBasd4D5QlYiBfKOkOw1hr/M9Zcnjo3D5ldVQypO2j5thP2Jw L6HxjYLdl32HGLSiQhqddaHQ/t7EJJzrz8Zaoe0g= Subject: FAILED: patch "[PATCH] i3c: master: Fix use-after-free of master->this" failed to apply to 6.12-stable tree To: adrian.hunter@intel.com,Frank.Li@nxp.com,alexandre.belloni@bootlin.com Cc: From: Date: Fri, 04 Sep 2026 06:37:30 +0200 Message-ID: <2026090430-specks-lisp-beb4@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.12-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y git checkout FETCH_HEAD git cherry-pick -x feb0ed76601f3c2f91f08688c5a7d8b9d382f720 # git commit -s git send-email --to '' --in-reply-to '2026090430-specks-lisp-beb4@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ From feb0ed76601f3c2f91f08688c5a7d8b9d382f720 Mon Sep 17 00:00:00 2001 From: Adrian Hunter Date: Fri, 7 Aug 2026 17:56:28 +0300 Subject: [PATCH] i3c: master: Fix use-after-free of master->this sysfs attribute callbacks for the master controller device dereference master->this. However, master->this is 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(), which is called after the master device and its sysfs state are being torn down. Do not free master->this as part of the normal device detach path. On the error path in i3c_master_set_info(), reset master->this and bus.cur_master to NULL before freeing the allocated device. Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Reviewed-by: Frank Li Link: https://patch.msgid.link/20260807145638.168865-5-adrian.hunter@intel.com Signed-off-by: Alexandre Belloni diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index abb582645a2e..2357874bb9d6 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) @@ -2266,6 +2268,8 @@ int i3c_master_set_info(struct i3c_master_controller *master, return 0; err_free_dev: + master->bus.cur_master = NULL; + master->this = NULL; i3c_master_free_i3c_dev(i3cdev); return ret; @@ -2286,7 +2290,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,