* [PATCH v5 01/19] rust: drm: ioctl: fix unbounded lifetimes in ioctl handler arguments
[not found] <20260628145406.2107056-1-dakr@kernel.org>
@ 2026-06-28 14:53 ` Danilo Krummrich
2026-06-29 21:32 ` lyude
2026-07-01 11:29 ` Alexandre Courbot
2026-06-28 14:53 ` [PATCH v5 16/19] drm: fix race between partial drm_dev_register() failure and ioctl Danilo Krummrich
1 sibling, 2 replies; 6+ messages in thread
From: Danilo Krummrich @ 2026-06-28 14:53 UTC (permalink / raw)
To: dakr, aliceryhl, daniel.almeida, acourbot, ecourtney, ojeda,
boqun, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
deborah.brouwer, boris.brezillon, lyude
Cc: driver-core, linux-kernel, nova-gpu, dri-devel, rust-for-linux,
stable, sashiko-bot
References to dev, data, and file in the declare_drm_ioctls! macro are
created via unsafe pointer dereferences, producing unbounded lifetimes.
If an ioctl handler explicitly annotates its parameters with 'static,
the compiler accepts this, allowing the handler to stash references that
outlive the ioctl call.
Fix this by adding a higher-ranked function pointer coercion that
enforces the handler accepts universally quantified lifetimes:
let _: for<'a> fn(&'a _, &'a mut _, &'a _) -> _ = $func;
Since the handler must be coercible to a function pointer accepting any
lifetime 'a, it can no longer demand 'static on any parameter.
Cc: stable@vger.kernel.org
Fixes: 9a69570682b1 ("rust: drm: ioctl: Add DRM ioctl abstraction")
Reported-by: sashiko-bot@kernel.org
Closes: https://lore.kernel.org/all/20260620011346.A47D01F000E9@smtp.kernel.org/
Suggested-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
rust/kernel/drm/ioctl.rs | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
index cf328101dde4..ccf4150d83b6 100644
--- a/rust/kernel/drm/ioctl.rs
+++ b/rust/kernel/drm/ioctl.rs
@@ -135,6 +135,12 @@ macro_rules! declare_drm_ioctls {
// dev/file match the current driver these ioctls are being declared
// for, and it's not clear how to enforce this within the type system.
let dev = $crate::drm::device::Device::from_raw(raw_dev);
+
+ // Enforce that the handler accepts higher-ranked
+ // lifetimes, preventing it from requiring 'static
+ // references that could escape this scope.
+ let _: for<'a> fn(&'a _, &'a mut _, &'a _) -> _ = $func;
+
// SAFETY: The ioctl argument has size `_IOC_SIZE(cmd)`, which we
// asserted above matches the size of this type, and all bit patterns of
// UAPI structs must be valid.
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 16/19] drm: fix race between partial drm_dev_register() failure and ioctl
[not found] <20260628145406.2107056-1-dakr@kernel.org>
2026-06-28 14:53 ` [PATCH v5 01/19] rust: drm: ioctl: fix unbounded lifetimes in ioctl handler arguments Danilo Krummrich
@ 2026-06-28 14:53 ` Danilo Krummrich
2026-06-29 21:37 ` lyude
2026-07-02 6:48 ` Alexandre Courbot
1 sibling, 2 replies; 6+ messages in thread
From: Danilo Krummrich @ 2026-06-28 14:53 UTC (permalink / raw)
To: dakr, aliceryhl, daniel.almeida, acourbot, ecourtney, ojeda,
boqun, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
deborah.brouwer, boris.brezillon, lyude
Cc: driver-core, linux-kernel, nova-gpu, dri-devel, rust-for-linux,
stable, sashiko-bot
If drm_dev_register() fails after registering a minor (e.g. render minor
registered, primary minor fails), userspace could have opened the first
minor and entered a drm_dev_enter() critical section. Since the
unplugged flag was never set, the ioctl proceeds while the error path
tears down device resources.
Fix this by introducing drm_dev_synchronize_unplug(), which sets the
unplugged flag and waits for the SRCU barrier, ensuring all in-flight
drm_dev_enter() critical sections complete before cleanup proceeds; call
it on the error path of drm_dev_register().
Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
Cc: stable@vger.kernel.org
Reported-by: sashiko-bot@kernel.org
Closes: https://lore.kernel.org/all/20260620190648.2E9F61F000E9@smtp.kernel.org/
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
drivers/gpu/drm/drm_drv.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 675675480da4..e890052061f3 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -473,6 +473,22 @@ void drm_dev_exit(int idx)
}
EXPORT_SYMBOL(drm_dev_exit);
+/*
+ * Mark the device as unplugged and wait for any in-flight drm_dev_enter()
+ * critical sections to complete.
+ */
+static void drm_dev_synchronize_unplug(struct drm_device *dev)
+{
+ /*
+ * After synchronizing any critical read section is guaranteed to see
+ * the new value of ->unplugged, and any critical section which might
+ * still have seen the old value of ->unplugged is guaranteed to have
+ * finished.
+ */
+ dev->unplugged = true;
+ synchronize_srcu(&drm_unplug_srcu);
+}
+
/**
* drm_dev_unplug - unplug a DRM device
* @dev: DRM device
@@ -485,15 +501,7 @@ EXPORT_SYMBOL(drm_dev_exit);
*/
void drm_dev_unplug(struct drm_device *dev)
{
- /*
- * After synchronizing any critical read section is guaranteed to see
- * the new value of ->unplugged, and any critical section which might
- * still have seen the old value of ->unplugged is guaranteed to have
- * finished.
- */
- dev->unplugged = true;
- synchronize_srcu(&drm_unplug_srcu);
-
+ drm_dev_synchronize_unplug(dev);
drm_dev_unregister(dev);
/* Clear all CPU mappings pointing to this device */
@@ -1091,6 +1099,7 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
goto err_minors;
dev->registered = true;
+ dev->unplugged = false;
if (driver->load) {
ret = driver->load(dev, flags);
@@ -1118,6 +1127,13 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
if (dev->driver->unload)
dev->driver->unload(dev);
err_minors:
+ /*
+ * If a minor was registered before the failure, userspace could have
+ * opened it and entered a drm_dev_enter() critical section. Ensure all
+ * such sections complete before we clean up.
+ */
+ drm_dev_synchronize_unplug(dev);
+
remove_compat_control_link(dev);
drm_minor_unregister(dev, DRM_MINOR_ACCEL);
drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v5 01/19] rust: drm: ioctl: fix unbounded lifetimes in ioctl handler arguments
2026-06-28 14:53 ` [PATCH v5 01/19] rust: drm: ioctl: fix unbounded lifetimes in ioctl handler arguments Danilo Krummrich
@ 2026-06-29 21:32 ` lyude
2026-07-01 11:29 ` Alexandre Courbot
1 sibling, 0 replies; 6+ messages in thread
From: lyude @ 2026-06-29 21:32 UTC (permalink / raw)
To: Danilo Krummrich, aliceryhl, daniel.almeida, acourbot, ecourtney,
ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
deborah.brouwer, boris.brezillon
Cc: driver-core, linux-kernel, nova-gpu, dri-devel, rust-for-linux,
stable, sashiko-bot
this macro is wild.
Reviewed-by: Lyude Paul <lyude@redhat.com>
On Sun, 2026-06-28 at 16:53 +0200, Danilo Krummrich wrote:
> References to dev, data, and file in the declare_drm_ioctls! macro
> are
> created via unsafe pointer dereferences, producing unbounded
> lifetimes.
> If an ioctl handler explicitly annotates its parameters with 'static,
> the compiler accepts this, allowing the handler to stash references
> that
> outlive the ioctl call.
>
> Fix this by adding a higher-ranked function pointer coercion that
> enforces the handler accepts universally quantified lifetimes:
>
> let _: for<'a> fn(&'a _, &'a mut _, &'a _) -> _ = $func;
>
> Since the handler must be coercible to a function pointer accepting
> any
> lifetime 'a, it can no longer demand 'static on any parameter.
>
> Cc: stable@vger.kernel.org
> Fixes: 9a69570682b1 ("rust: drm: ioctl: Add DRM ioctl abstraction")
> Reported-by: sashiko-bot@kernel.org
> Closes:
> https://lore.kernel.org/all/20260620011346.A47D01F000E9@smtp.kernel.org/
> Suggested-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
> rust/kernel/drm/ioctl.rs | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
> index cf328101dde4..ccf4150d83b6 100644
> --- a/rust/kernel/drm/ioctl.rs
> +++ b/rust/kernel/drm/ioctl.rs
> @@ -135,6 +135,12 @@ macro_rules! declare_drm_ioctls {
> // dev/file match the current driver
> these ioctls are being declared
> // for, and it's not clear how to
> enforce this within the type system.
> let dev =
> $crate::drm::device::Device::from_raw(raw_dev);
> +
> + // Enforce that the handler accepts
> higher-ranked
> + // lifetimes, preventing it from
> requiring 'static
> + // references that could escape this
> scope.
> + let _: for<'a> fn(&'a _, &'a mut _, &'a
> _) -> _ = $func;
> +
> // SAFETY: The ioctl argument has size
> `_IOC_SIZE(cmd)`, which we
> // asserted above matches the size of
> this type, and all bit patterns of
> // UAPI structs must be valid.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 16/19] drm: fix race between partial drm_dev_register() failure and ioctl
2026-06-28 14:53 ` [PATCH v5 16/19] drm: fix race between partial drm_dev_register() failure and ioctl Danilo Krummrich
@ 2026-06-29 21:37 ` lyude
2026-07-02 6:48 ` Alexandre Courbot
1 sibling, 0 replies; 6+ messages in thread
From: lyude @ 2026-06-29 21:37 UTC (permalink / raw)
To: Danilo Krummrich, aliceryhl, daniel.almeida, acourbot, ecourtney,
ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
deborah.brouwer, boris.brezillon
Cc: driver-core, linux-kernel, nova-gpu, dri-devel, rust-for-linux,
stable, sashiko-bot
Reviewed-by: Lyude Paul <lyude@redhat.com>
On Sun, 2026-06-28 at 16:53 +0200, Danilo Krummrich wrote:
> If drm_dev_register() fails after registering a minor (e.g. render
> minor
> registered, primary minor fails), userspace could have opened the
> first
> minor and entered a drm_dev_enter() critical section. Since the
> unplugged flag was never set, the ioctl proceeds while the error path
> tears down device resources.
>
> Fix this by introducing drm_dev_synchronize_unplug(), which sets the
> unplugged flag and waits for the SRCU barrier, ensuring all in-flight
> drm_dev_enter() critical sections complete before cleanup proceeds;
> call
> it on the error path of drm_dev_register().
>
> Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
> Cc: stable@vger.kernel.org
> Reported-by: sashiko-bot@kernel.org
> Closes:
> https://lore.kernel.org/all/20260620190648.2E9F61F000E9@smtp.kernel.org/
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
> drivers/gpu/drm/drm_drv.c | 34 +++++++++++++++++++++++++---------
> 1 file changed, 25 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 675675480da4..e890052061f3 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -473,6 +473,22 @@ void drm_dev_exit(int idx)
> }
> EXPORT_SYMBOL(drm_dev_exit);
>
> +/*
> + * Mark the device as unplugged and wait for any in-flight
> drm_dev_enter()
> + * critical sections to complete.
> + */
> +static void drm_dev_synchronize_unplug(struct drm_device *dev)
> +{
> + /*
> + * After synchronizing any critical read section is
> guaranteed to see
> + * the new value of ->unplugged, and any critical section
> which might
> + * still have seen the old value of ->unplugged is
> guaranteed to have
> + * finished.
> + */
> + dev->unplugged = true;
> + synchronize_srcu(&drm_unplug_srcu);
> +}
> +
> /**
> * drm_dev_unplug - unplug a DRM device
> * @dev: DRM device
> @@ -485,15 +501,7 @@ EXPORT_SYMBOL(drm_dev_exit);
> */
> void drm_dev_unplug(struct drm_device *dev)
> {
> - /*
> - * After synchronizing any critical read section is
> guaranteed to see
> - * the new value of ->unplugged, and any critical section
> which might
> - * still have seen the old value of ->unplugged is
> guaranteed to have
> - * finished.
> - */
> - dev->unplugged = true;
> - synchronize_srcu(&drm_unplug_srcu);
> -
> + drm_dev_synchronize_unplug(dev);
> drm_dev_unregister(dev);
>
> /* Clear all CPU mappings pointing to this device */
> @@ -1091,6 +1099,7 @@ int drm_dev_register(struct drm_device *dev,
> unsigned long flags)
> goto err_minors;
>
> dev->registered = true;
> + dev->unplugged = false;
>
> if (driver->load) {
> ret = driver->load(dev, flags);
> @@ -1118,6 +1127,13 @@ int drm_dev_register(struct drm_device *dev,
> unsigned long flags)
> if (dev->driver->unload)
> dev->driver->unload(dev);
> err_minors:
> + /*
> + * If a minor was registered before the failure, userspace
> could have
> + * opened it and entered a drm_dev_enter() critical section.
> Ensure all
> + * such sections complete before we clean up.
> + */
> + drm_dev_synchronize_unplug(dev);
> +
> remove_compat_control_link(dev);
> drm_minor_unregister(dev, DRM_MINOR_ACCEL);
> drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 01/19] rust: drm: ioctl: fix unbounded lifetimes in ioctl handler arguments
2026-06-28 14:53 ` [PATCH v5 01/19] rust: drm: ioctl: fix unbounded lifetimes in ioctl handler arguments Danilo Krummrich
2026-06-29 21:32 ` lyude
@ 2026-07-01 11:29 ` Alexandre Courbot
1 sibling, 0 replies; 6+ messages in thread
From: Alexandre Courbot @ 2026-07-01 11:29 UTC (permalink / raw)
To: Danilo Krummrich
Cc: aliceryhl, daniel.almeida, ecourtney, ojeda, boqun, gary,
bjorn3_gh, lossin, a.hindborg, tmgross, deborah.brouwer,
boris.brezillon, lyude, driver-core, linux-kernel, nova-gpu,
dri-devel, rust-for-linux, stable, sashiko-bot
On Sun Jun 28, 2026 at 11:53 PM JST, Danilo Krummrich wrote:
> References to dev, data, and file in the declare_drm_ioctls! macro are
> created via unsafe pointer dereferences, producing unbounded lifetimes.
> If an ioctl handler explicitly annotates its parameters with 'static,
> the compiler accepts this, allowing the handler to stash references that
> outlive the ioctl call.
>
> Fix this by adding a higher-ranked function pointer coercion that
> enforces the handler accepts universally quantified lifetimes:
>
> let _: for<'a> fn(&'a _, &'a mut _, &'a _) -> _ = $func;
>
> Since the handler must be coercible to a function pointer accepting any
> lifetime 'a, it can no longer demand 'static on any parameter.
>
> Cc: stable@vger.kernel.org
> Fixes: 9a69570682b1 ("rust: drm: ioctl: Add DRM ioctl abstraction")
> Reported-by: sashiko-bot@kernel.org
> Closes: https://lore.kernel.org/all/20260620011346.A47D01F000E9@smtp.kernel.org/
> Suggested-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 16/19] drm: fix race between partial drm_dev_register() failure and ioctl
2026-06-28 14:53 ` [PATCH v5 16/19] drm: fix race between partial drm_dev_register() failure and ioctl Danilo Krummrich
2026-06-29 21:37 ` lyude
@ 2026-07-02 6:48 ` Alexandre Courbot
1 sibling, 0 replies; 6+ messages in thread
From: Alexandre Courbot @ 2026-07-02 6:48 UTC (permalink / raw)
To: Danilo Krummrich
Cc: aliceryhl, daniel.almeida, ecourtney, ojeda, boqun, gary,
bjorn3_gh, lossin, a.hindborg, tmgross, deborah.brouwer,
boris.brezillon, lyude, driver-core, linux-kernel, nova-gpu,
dri-devel, rust-for-linux, stable, sashiko-bot
On Sun Jun 28, 2026 at 11:53 PM JST, Danilo Krummrich wrote:
> If drm_dev_register() fails after registering a minor (e.g. render minor
> registered, primary minor fails), userspace could have opened the first
> minor and entered a drm_dev_enter() critical section. Since the
> unplugged flag was never set, the ioctl proceeds while the error path
> tears down device resources.
>
> Fix this by introducing drm_dev_synchronize_unplug(), which sets the
> unplugged flag and waits for the SRCU barrier, ensuring all in-flight
> drm_dev_enter() critical sections complete before cleanup proceeds; call
> it on the error path of drm_dev_register().
>
> Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
> Cc: stable@vger.kernel.org
> Reported-by: sashiko-bot@kernel.org
> Closes: https://lore.kernel.org/all/20260620190648.2E9F61F000E9@smtp.kernel.org/
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-02 6:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260628145406.2107056-1-dakr@kernel.org>
2026-06-28 14:53 ` [PATCH v5 01/19] rust: drm: ioctl: fix unbounded lifetimes in ioctl handler arguments Danilo Krummrich
2026-06-29 21:32 ` lyude
2026-07-01 11:29 ` Alexandre Courbot
2026-06-28 14:53 ` [PATCH v5 16/19] drm: fix race between partial drm_dev_register() failure and ioctl Danilo Krummrich
2026-06-29 21:37 ` lyude
2026-07-02 6:48 ` Alexandre Courbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox