From: sashiko-bot@kernel.org
To: "Alistair Popple" <apopple@nvidia.com>
Cc: ojeda@kernel.org, dri-devel@lists.freedesktop.org,
"Danilo Krummrich" <dakr@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
gary@garyguo.net
Subject: Re: [PATCH v6 01/13] rust: auxiliary: let registration_data_with() closures return covariant sub-fields
Date: Wed, 09 Sep 2026 06:57:33 +0000 [thread overview]
Message-ID: <20260909065733.7F3B51F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909064506.910162-2-apopple@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Safe methods `registration_data_with` and `registration_data` can cause a Use-After-Free because `Registration::drop` frees the registration data but leaves a dangling pointer in the underlying C struct.
--
commit f7dbc67a0cd0bf4fcd048c32f110a8ba459452b3
Author: Alistair Popple <apopple@nvidia.com>
rust: auxiliary: let registration_data_with() closures return covariant sub-fields
The closure passed to registration_data_with() currently receives
Pin<&'a F::Of<'a>> with 'a universally quantified. This prevents the
closure from returning references derived from the registration data,
even for sub-fields that are covariant in their lifetime. By tying the
outer reference to the &self lifetime, the closure can coerce covariant
sub-fields and return them directly.
Link: https://lore.kernel.org/nova-gpu/DL3WPTVM033J.33RWYCZOC67Z1@kernel.org/
> diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs
> index 60dfbec8f3302..06f816420790a 100644
> --- a/rust/kernel/auxiliary.rs
> +++ b/rust/kernel/auxiliary.rs
[ ... ]
> @@ -314,13 +318,14 @@ unsafe fn registration_data_pinned<F: ForLt + 'static>(&self) -> Result<Pin<&F::
> /// Returns [`ENOENT`] if no registration data has been set, e.g. when the device was
> /// registered by a C driver.
> #[inline]
> - pub fn registration_data_with<F: ForLt + 'static, R>(
> - &self,
> - f: impl for<'a> FnOnce(Pin<&'a F::Of<'a>>) -> R,
> + pub fn registration_data_with<'this, F: ForLt + 'static, R>(
> + &'this self,
> + f: impl for<'a> FnOnce(Pin<&'this F::Of<'a>>) -> R,
> ) -> Result<R> {
[Severity: High]
This is a pre-existing issue, but can this safe method cause a use-after-free
if a child driver or a detached kernel thread retains an ARef<Device> after
the parent's unbind event?
Looking at Registration::drop in rust/kernel/auxiliary.rs, it frees the
registration data but does not clear the registration_data_rust pointer in
the underlying C struct:
Registration::drop() {
...
// SAFETY: registration_data was set in new() via into_foreign().
drop(unsafe {
Pin::<KBox<RegistrationData<F::Of<'static>>>>::from_foreign(
(*self.adev.as_ptr()).registration_data_rust,
)
});
...
}
If a safely retained Device is then used to call registration_data_with(), the
internal registration_data_pinned() method will bypass the null check and
read from the dangling pointer:
Device::registration_data_pinned() {
let ptr = unsafe { (*self.as_raw()).registration_data_rust };
if ptr.is_null() {
...
return Err(ENOENT);
}
...
let type_id = unsafe { ptr.cast::<TypeId>().read() };
...
}
Could Registration::drop be updated to clear registration_data_rust to NULL
before freeing the data to prevent this issue? Or does this also need
additional synchronization to handle concurrent access safely?
> - // SAFETY: The HRTB closure prevents the caller from smuggling in references with a
> - // concrete short lifetime, making the round-trip from `'static` sound regardless of
> - // variance.
> + // SAFETY: The HRTB on the inner type prevents the caller from exploiting a specific
> + // choice of `'a`. Covariant sub-fields can be safely coerced to `'this`, while
> + // invariant fields cannot be coerced and thus cannot escape with an incorrect
> + // lifetime.
> let pinned = unsafe { self.registration_data_pinned::<F>()? };
>
> Ok(f(pinned))
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260909064506.910162-1-apopple@nvidia.com?part=1
next prev parent reply other threads:[~2026-09-09 6:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 6:44 [PATCH v6 00/13] gpu: nova: Export parameters from nova-core to nova-drm Alistair Popple
2026-09-09 6:44 ` [PATCH v6 01/13] rust: auxiliary: let registration_data_with() closures return covariant sub-fields Alistair Popple
2026-09-09 6:57 ` sashiko-bot [this message]
2026-09-09 6:44 ` [PATCH v6 02/13] gpu: nova-core: Add public driver API to nova-core Alistair Popple
2026-09-09 6:44 ` [PATCH v6 03/13] drm: nova: Add DRM registration data Alistair Popple
2026-09-09 6:44 ` [PATCH v6 04/13] drm: nova: Add GPU architecture enum to nova-drm UAPI Alistair Popple
2026-09-09 6:44 ` [PATCH v6 05/13] drm: nova: Add chipid " Alistair Popple
2026-09-09 6:44 ` [PATCH v6 06/13] rust: uaccess: add UserSliceWriter::write_truncated() Alistair Popple
2026-09-09 6:56 ` sashiko-bot
2026-09-09 6:45 ` [PATCH v6 07/13] drm: nova: Add an info ioctl Alistair Popple
2026-09-09 6:45 ` [PATCH v6 08/13] drm: nova: Add usable VRAM size to GPU info Alistair Popple
2026-09-09 6:45 ` [PATCH v6 09/13] drm: nova: Use nova-core to read VRAM_BAR_SIZE parameter Alistair Popple
2026-09-09 6:45 ` [PATCH v6 10/13] drm: nova: Expose a render node Alistair Popple
2026-09-09 6:45 ` [PATCH v6 11/13] drm: nova: Report GPU name in GPU info Alistair Popple
2026-09-09 6:45 ` [PATCH v6 12/13] drm: nova: Report GPU short " Alistair Popple
2026-09-09 6:45 ` [PATCH v6 13/13] drm: nova: Report GPU GID " Alistair Popple
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260909065733.7F3B51F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acourbot@nvidia.com \
--cc=apopple@nvidia.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.