From mboxrd@z Thu Jan 1 00:00:00 1970 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 8206235C6B2; Sat, 12 Sep 2026 09:35:54 +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=1789205755; cv=none; b=JhKC8+cPETlYBJ4sfcduknWwZInGmvZv1HntuiALRrC1DbqRkgYF9SKng6EfZgl7fdr8sH748DJHoLrbwU2Ap3h6HW9nklGqUSckaQ6mEewWhot74Tsf6BRWL6HiWiHIzM3KuHxCB9gkJ07G11cYt5LVVn0maUqPZlviftLR330= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789205755; c=relaxed/simple; bh=zPaN761FjFjxlLnwKCPUJN1z5EyMntDzope9OOjqz8M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zc+Vs65bFVKg9gIMZtUzyBBTS0g3ZbK6amALpG3yNtqvwxshVczGiAfnG0tS0FnbAbBzP9iNy9h8oZv0VWGbablK+nT/9Cwo7GRn2Fzb03AeHBYzkLzNtTakinfX5XZoH/XZIjBSPUl9/0h0d4U6ywZb1JXq6nFzwfsfUbvTGFY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kupqfDaY; 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="kupqfDaY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C835D1F000FF; Sat, 12 Sep 2026 09:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789205754; bh=N2bCj5FG3fZ88OpdoDdO5JMzWgCxCj/l6HyK0jtyrKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kupqfDaYpeJgWW1y1ZuyxF3ClUqjwXw4S+3hdf9cgtFVPMdAzuWBkTTOPdjShhQda c7tC9QRptW4+/9DEi79A5zQqM/LwzavAG4zwZ+qggukgT0YTh7EMMFY0KG8MLAZaiT j3qco3FGTHa+t41kk6YD1PgrgFSUU9Al0x7Gy/8I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Adrian Hunter , Frank Li , Alexandre Belloni , Sasha Levin Subject: [PATCH 6.18 0066/1518] i3c: master: Fix use-after-free of master->this Date: Sat, 12 Sep 2026 08:37:15 +0200 Message-ID: <20260912065624.949416479@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065623.398859879@linuxfoundation.org> References: <20260912065623.398859879@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Adrian Hunter [ Upstream commit feb0ed76601f3c2f91f08688c5a7d8b9d382f720 ] 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 [ retained of_node_put(dev->of_node) instead of upstream’s fwnode_handle_put(dev->fwnode). ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/i3c/master.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -799,6 +799,11 @@ static struct attribute *i3c_masterdev_a }; 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); @@ -811,6 +816,8 @@ static void i3c_masterdev_release(struct i3c_bus_cleanup(bus); of_node_put(dev->of_node); + + i3c_master_free_i3c_dev(master->this); } static const struct device_type i3c_masterdev_type = { @@ -1023,11 +1030,6 @@ static void i3c_device_release(struct de 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) @@ -2046,6 +2048,8 @@ int i3c_master_set_info(struct i3c_maste return 0; err_free_dev: + master->bus.cur_master = NULL; + master->this = NULL; i3c_master_free_i3c_dev(i3cdev); return ret; @@ -2066,7 +2070,8 @@ static void i3c_master_detach_free_devs( 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,