Commit 966944f3 authored by Mitchell Levy's avatar Mitchell Levy Committed by Ingo Molnar
Browse files

rust: lockdep: Remove support for dynamically allocated LockClassKeys



Currently, dynamically allocated LockCLassKeys can be used from the Rust
side without having them registered. This is a soundness issue, so
remove them.

Fixes: 6ea5aa08 ("rust: sync: introduce `LockClassKey`")
Suggested-by: default avatarAlice Ryhl <aliceryhl@google.com>
Signed-off-by: default avatarMitchell Levy <levymitchell0@gmail.com>
Signed-off-by: default avatarBoqun Feng <boqun.feng@gmail.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Reviewed-by: default avatarBenno Lossin <benno.lossin@proton.me>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20250307232717.1759087-11-boqun.feng@gmail.com
parent 21e4543a
Loading
Loading
Loading
Loading
+4 −12
Original line number Diff line number Diff line
@@ -30,28 +30,20 @@
unsafe impl Sync for LockClassKey {}

impl LockClassKey {
    /// Creates a new lock class key.
    pub const fn new() -> Self {
        Self(Opaque::uninit())
    }

    pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key {
        self.0.get()
    }
}

impl Default for LockClassKey {
    fn default() -> Self {
        Self::new()
    }
}

/// Defines a new static lock class and returns a pointer to it.
#[doc(hidden)]
#[macro_export]
macro_rules! static_lock_class {
    () => {{
        static CLASS: $crate::sync::LockClassKey = $crate::sync::LockClassKey::new();
        static CLASS: $crate::sync::LockClassKey =
            // SAFETY: lockdep expects uninitialized memory when it's handed a statically allocated
            // lock_class_key
            unsafe { ::core::mem::MaybeUninit::uninit().assume_init() };
        &CLASS
    }};
}