lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250919091241.32138-3-boqun.feng@gmail.com>
Date: Fri, 19 Sep 2025 11:12:39 +0200
From: Boqun Feng <boqun.feng@...il.com>
To: "Peter Zijlstra" <peterz@...adead.org>,
	"Ingo Molnar" <mingo@...nel.org>,
	"Thomas Gleixner" <tglx@...utronix.de>
Cc: rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	lkmm@...ts.linux.dev,
	"Will Deacon" <will@...nel.org>,
	"Peter Zijlstra" <peterz@...radead.org>,
	Waiman Long <longman@...hat.com>,
	"Miguel Ojeda" <ojeda@...nel.org>,
	alex.gaynor@...il.com,
	"Gary Guo" <gary@...yguo.net>,
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,
	"Benno Lossin" <lossin@...nel.org>,
	"Alice Ryhl" <aliceryhl@...gle.com>,
	"Trevor Gross" <tmgross@...ch.edu>,
	"Danilo Krummrich" <dakr@...nel.org>,
	"Andreas Hindborg" <a.hindborg@...nel.org>,
	Daniel Almeida <daniel.almeida@...labora.com>,
	Boqun Feng <boqun.feng@...il.com>
Subject: [PATCH 2/4] rust: lock: guard: Add T: Unpin bound to DerefMut

From: Daniel Almeida <daniel.almeida@...labora.com>

A core property of pinned types is not handing a mutable reference to
the inner data in safe code, as this trivially allows that data to be
moved.

Enforce this condition by adding a bound on lock::Guard's DerefMut
implementation, so that it's only implemented for pinning-agnostic
types.

Link: https://github.com/Rust-for-Linux/linux/issues/1181
Suggested-by: Benno Lossin <lossin@...nel.org>
Suggested-by: Boqun Feng <boqun.feng@...il.com>
Reviewed-by: Benno Lossin <lossin@...nel.org>
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
Signed-off-by: Daniel Almeida <daniel.almeida@...labora.com>
Signed-off-by: Boqun Feng <boqun.feng@...il.com>
---

Notes:
    SubmissionLink: https://lore.kernel.org/all/20250828-lock-t-when-t-is-pinned-v2-1-b067c4b93fd6@collabora.com/

 rust/kernel/sync/lock.rs        | 5 ++++-
 rust/kernel/sync/lock/global.rs | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
index 27202beef90c..b482f34bf0ce 100644
--- a/rust/kernel/sync/lock.rs
+++ b/rust/kernel/sync/lock.rs
@@ -251,7 +251,10 @@ fn deref(&self) -> &Self::Target {
     }
 }
 
-impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B> {
+impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B>
+where
+    T: Unpin,
+{
     fn deref_mut(&mut self) -> &mut Self::Target {
         // SAFETY: The caller owns the lock, so it is safe to deref the protected data.
         unsafe { &mut *self.lock.data.get() }
diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs
index d65f94b5caf2..38b448032799 100644
--- a/rust/kernel/sync/lock/global.rs
+++ b/rust/kernel/sync/lock/global.rs
@@ -106,7 +106,10 @@ fn deref(&self) -> &Self::Target {
     }
 }
 
-impl<B: GlobalLockBackend> core::ops::DerefMut for GlobalGuard<B> {
+impl<B: GlobalLockBackend> core::ops::DerefMut for GlobalGuard<B>
+where
+    B::Item: Unpin,
+{
     fn deref_mut(&mut self) -> &mut Self::Target {
         &mut self.inner
     }
-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ