* [PATCH] i3c: master: Fix info leak and UAF in device unregister path
@ 2026-07-23 7:57 Adrian Hunter
2026-07-23 18:25 ` Frank Li
2026-07-30 14:42 ` Alexandre Belloni
0 siblings, 2 replies; 3+ messages in thread
From: Adrian Hunter @ 2026-07-23 7:57 UTC (permalink / raw)
To: alexandre.belloni; +Cc: Frank.Li, linux-i3c, linux-kernel
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 <adrian.hunter@intel.com>
---
drivers/i3c/master.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 659c14c2c192..433dc7531701 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -3083,11 +3083,12 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
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;
}
}
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] i3c: master: Fix info leak and UAF in device unregister path
2026-07-23 7:57 [PATCH] i3c: master: Fix info leak and UAF in device unregister path Adrian Hunter
@ 2026-07-23 18:25 ` Frank Li
2026-07-30 14:42 ` Alexandre Belloni
1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-07-23 18:25 UTC (permalink / raw)
To: Adrian Hunter; +Cc: alexandre.belloni, Frank.Li, linux-i3c, linux-kernel
On Thu, Jul 23, 2026 at 10:57:47AM +0300, Adrian Hunter wrote:
> 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 <adrian.hunter@intel.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/i3c/master.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 659c14c2c192..433dc7531701 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -3083,11 +3083,12 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
> 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;
> }
> }
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] i3c: master: Fix info leak and UAF in device unregister path
2026-07-23 7:57 [PATCH] i3c: master: Fix info leak and UAF in device unregister path Adrian Hunter
2026-07-23 18:25 ` Frank Li
@ 2026-07-30 14:42 ` Alexandre Belloni
1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2026-07-30 14:42 UTC (permalink / raw)
To: Adrian Hunter; +Cc: Frank.Li, linux-i3c, linux-kernel
On Thu, 23 Jul 2026 10:57:47 +0300, Adrian Hunter wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] i3c: master: Fix info leak and UAF in device unregister path
https://git.kernel.org/i3c/c/6f056a769b9f
Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-30 14:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-23 7:57 [PATCH] i3c: master: Fix info leak and UAF in device unregister path Adrian Hunter
2026-07-23 18:25 ` Frank Li
2026-07-30 14:42 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®