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 A8C92318ED6; Fri, 4 Sep 2026 06:02:23 +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=1788501744; cv=none; b=m2ud6PvvCJoi8DaxKpgf3w4+Qkqi42xVn5Sc4yZ5P4mS/MyQgEtzH9j8fWtxrW5iMtcdacyTBJB9IcGhhw/0y42lk3rBuNYMUgS0XVhlrL81b694L/wvwfq6VlbHaFZTYBSC3Ttu9RtmsQLqQzvti3kwaAXHhsmdF92sdvbNwZ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788501744; c=relaxed/simple; bh=hR5Y2+WWxSrQ/or/DQqwRRbFB+aJlofUCOQSlndV93c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NOV0TSWBS38oGXBfLG/m/be9EVLBliPLh/ju/gS6WGGMtWxrrlO9xHWEi87SJ/p5CqdNemsySqwirp6FOky2ZrfQukotJLNCn+9A6knQ1m8HTvNf4CoNJrUypGyaxHnIe62tiFVNSHfbV7PyeICkv/hg/XfR0tX86evitT8GAsI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YjZPdUVO; 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="YjZPdUVO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 063AC1F00A3E; Fri, 4 Sep 2026 06:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788501743; bh=ZFA+hr/Qn0fv7wW0IIpa66ZTZHptFTpxNPqXCBH/g20=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YjZPdUVOFLK0XtywfPCFrbICC1CgfwnZZbIbvjk3UvZQ9hO7aKhB5lRTEqcy2SJr+ lRdC3nGKS+la7xuu6Ab0wuyr6xdrjXouSbFzlrRZZDQzuIobw/RnfsozERWXXmuk/I xbpNvp0QBmuup9caeMDOLTOXW9FB8wyZPcCXeqXA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot@kernel.org, Adrian Hunter , Frank Li , Alexandre Belloni Subject: [PATCH 6.18 516/552] i3c: master: Fix info leak and UAF in device unregister path Date: Fri, 4 Sep 2026 07:01:13 +0200 Message-ID: <20260904045802.328556896@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045747.813364717@linuxfoundation.org> References: <20260904045747.813364717@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-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Adrian Hunter commit d2c743efd2d1ee64e94324664808f623dd865872 upstream. i3c_master_unregister_i3c_devs() clears i3cdev->dev->desc before calling device_unregister(). During device_unregister(), device_del() emits a KOBJ_REMOVE uevent and unbinds the driver while the device descriptor is still expected to be valid. As a result, i3c_device_uevent() and a racing modalias_show() can observe a NULL desc and fall back to an uninitialized stack struct i3c_device_info, leaking kernel stack contents in the generated modalias. Driver .remove() callbacks may also encounter an unexpected NULL desc during unbind. Keep desc valid until device_unregister() has completed. Since device_unregister() drops the device reference and may free the device, take an extra reference with get_device() before unregistering. Clear desc afterwards and release the extra reference with put_device(). This preserves the release-time invariant that desc must be NULL while avoiding both the information leak and a potential use-after-free from writing desc after the device has been released. Reported-by: sashiko-bot@kernel.org Link: https://lore.kernel.org/linux-i3c/20260702190003.8BF741F000E9@smtp.kernel.org/ 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/20260723075747.34049-1-adrian.hunter@intel.com Signed-off-by: Alexandre Belloni Signed-off-by: Greg Kroah-Hartman --- drivers/i3c/master.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2808,11 +2808,12 @@ static void i3c_master_unregister_i3c_de if (!i3cdev->dev) continue; - i3cdev->dev->desc = NULL; - if (device_is_registered(&i3cdev->dev->dev)) + if (device_is_registered(&i3cdev->dev->dev)) { + get_device(&i3cdev->dev->dev); device_unregister(&i3cdev->dev->dev); - else - put_device(&i3cdev->dev->dev); + } + i3cdev->dev->desc = NULL; + put_device(&i3cdev->dev->dev); i3cdev->dev = NULL; } }