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: <174139248373.14745.16712674726296603783.tip-bot2@tip-bot2>
Date: Sat, 08 Mar 2025 00:08:03 -0000
From: "tip-bot2 for Alice Ryhl" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: Alice Ryhl <aliceryhl@...gle.com>, Boqun Feng <boqun.feng@...il.com>,
 Ingo Molnar <mingo@...nel.org>, Fiona Behrens <me@...enk.dev>, x86@...nel.org,
 linux-kernel@...r.kernel.org
Subject: [tip: locking/core] rust: sync: Add accessor for the lock behind a
 given guard

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     8f65291dae0e75941cf76e427088e5612c4d692e
Gitweb:        https://git.kernel.org/tip/8f65291dae0e75941cf76e427088e5612c4d692e
Author:        Alice Ryhl <aliceryhl@...gle.com>
AuthorDate:    Fri, 07 Mar 2025 15:26:57 -08:00
Committer:     Ingo Molnar <mingo@...nel.org>
CommitterDate: Sat, 08 Mar 2025 00:55:04 +01:00

rust: sync: Add accessor for the lock behind a given guard

In order to assert a particular `Guard` is associated with a particular
`Lock`, add an accessor to obtain a reference to the underlying `Lock`
of a `Guard`.

Binder needs this assertion to ensure unsafe list operations are done
with the correct lock held.

[Boqun: Capitalize the title and reword the commit log]

Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
Signed-off-by: Boqun Feng <boqun.feng@...il.com>
Signed-off-by: Ingo Molnar <mingo@...nel.org>
Reviewed-by: Fiona Behrens <me@...enk.dev>
Link: https://lore.kernel.org/r/20250205-guard-get-lock-v2-1-ba32a8c1d5b7@google.com
Link: https://lore.kernel.org/r/20250307232717.1759087-8-boqun.feng@gmail.com
---
 rust/kernel/sync/lock.rs | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
index eb80048..8e7e6d5 100644
--- a/rust/kernel/sync/lock.rs
+++ b/rust/kernel/sync/lock.rs
@@ -199,7 +199,12 @@ pub struct Guard<'a, T: ?Sized, B: Backend> {
 // SAFETY: `Guard` is sync when the data protected by the lock is also sync.
 unsafe impl<T: Sync + ?Sized, B: Backend> Sync for Guard<'_, T, B> {}
 
-impl<T: ?Sized, B: Backend> Guard<'_, T, B> {
+impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> {
+    /// Returns the lock that this guard originates from.
+    pub fn lock_ref(&self) -> &'a Lock<T, B> {
+        self.lock
+    }
+
     pub(crate) fn do_unlocked<U>(&mut self, cb: impl FnOnce() -> U) -> U {
         // SAFETY: The caller owns the lock, so it is safe to unlock it.
         unsafe { B::unlock(self.lock.state.get(), &self.state) };

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ