All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: drm: fix GEM object pointer safety docs
@ 2026-07-07 16:02 Yilin Chen
  2026-07-07 16:07 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yilin Chen @ 2026-07-07 16:02 UTC (permalink / raw)
  To: David Airlie, Simona Vetter, dri-devel, rust-for-linux
  Cc: Miguel Ojeda, Danilo Krummrich, linux-kernel, Yilin Chen

IntoGEMObject::from_raw() takes a drm_gem_object pointer.

Its Safety docs described the argument as a pointer to Self, which does
not match the function signature. Update the docs to point to the actual 
pointer type accepted by the API.

Assisted-by: Codex:GPT-5
Signed-off-by: Yilin Chen <1479826151@qq.com>
---
 rust/kernel/drm/gem/mod.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
index c8b66d816..90b256093 100644
--- a/rust/kernel/drm/gem/mod.rs
+++ b/rust/kernel/drm/gem/mod.rs
@@ -118,7 +118,7 @@ pub trait IntoGEMObject: Sized + super::private::Sealed + AlwaysRefCounted {
     ///
     /// # Safety
     ///
-    /// - `self_ptr` must be a valid pointer to `Self`.
+    /// - `self_ptr` must be a valid pointer to `struct drm_gem_object`.
     /// - The caller promises that holding the immutable reference returned by this function does
     ///   not violate rust's data aliasing rules and remains valid throughout the lifetime of `'a`.
     unsafe fn from_raw<'a>(self_ptr: *mut bindings::drm_gem_object) -> &'a Self;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rust: drm: fix GEM object pointer safety docs
  2026-07-07 16:02 [PATCH] rust: drm: fix GEM object pointer safety docs Yilin Chen
@ 2026-07-07 16:07 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-07-07 16:07 UTC (permalink / raw)
  To: Yilin Chen; +Cc: dri-devel, ojeda

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unsound Safety Contract in IntoGEMObject::from_raw
--

--- Patch [1]: [PATCH] rust: drm: fix GEM object pointer safety docs ---
commit 83b1634421cc950ce3b8ca23f3c9ab5c476d4697
Author: Yilin Chen <1479826151@qq.com>

rust: drm: fix GEM object pointer safety docs

This commit updates the Safety documentation for IntoGEMObject::from_raw()
to state that the argument must be a valid pointer to struct drm_gem_object
rather than a pointer to Self.

> diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
> index c8b66d8168719..90b256093e4cb 100644
> --- a/rust/kernel/drm/gem/mod.rs
> +++ b/rust/kernel/drm/gem/mod.rs
> @@ -118,7 +118,7 @@ pub trait IntoGEMObject: Sized + super::private::Sealed + AlwaysRefCounted {
>      ///
>      /// # Safety
>      ///
> -    /// - `self_ptr` must be a valid pointer to `Self`.
> +    /// - `self_ptr` must be a valid pointer to `struct drm_gem_object`.

[Severity: High]
Does this change make the safety contract unsound?

By removing the requirement that the pointer originates from an instance of
Self, the safety contract no longer protects against passing an arbitrary
valid drm_gem_object pointer.

If a caller satisfies this new documentation by passing a valid
drm_gem_object pointer that is not embedded in an instance of Self, won't
the container_of macro in the trait implementation yield an invalid pointer
and cause out-of-bounds memory access when fields of Self are accessed?

>      /// - The caller promises that holding the immutable reference returned by this function does
>      ///   not violate rust's data aliasing rules and remains valid throughout the lifetime of `'a`.
>      unsafe fn from_raw<'a>(self_ptr: *mut bindings::drm_gem_object) -> &'a Self;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_37A376A02B95E3DBE7E5C64882B7A4F90807@qq.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-07 16:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 16:02 [PATCH] rust: drm: fix GEM object pointer safety docs Yilin Chen
2026-07-07 16:07 ` sashiko-bot

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.