Skip to content

Commit 50b22a9

Browse files
chessturogregkh
authored andcommitted
rust: lockdep: Remove support for dynamically allocated LockClassKeys
commit 966944f upstream. Currently, dynamically allocated LockCLassKeys can be used from the Rust side without having them registered. This is a soundness issue, so remove them. Fixes: 6ea5aa0 ("rust: sync: introduce `LockClassKey`") Suggested-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Mitchell Levy <levymitchell0@gmail.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250307232717.1759087-11-boqun.feng@gmail.com Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 812080b commit 50b22a9

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

rust/kernel/sync.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ pub struct LockClassKey(Opaque<bindings::lock_class_key>);
2626
unsafe impl Sync for LockClassKey {}
2727

2828
impl LockClassKey {
29-
/// Creates a new lock class key.
30-
pub const fn new() -> Self {
31-
Self(Opaque::uninit())
32-
}
33-
3429
pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key {
3530
self.0.get()
3631
}
@@ -41,7 +36,10 @@ impl LockClassKey {
4136
#[macro_export]
4237
macro_rules! static_lock_class {
4338
() => {{
44-
static CLASS: $crate::sync::LockClassKey = $crate::sync::LockClassKey::new();
39+
static CLASS: $crate::sync::LockClassKey =
40+
// SAFETY: lockdep expects uninitialized memory when it's handed a statically allocated
41+
// lock_class_key
42+
unsafe { ::core::mem::MaybeUninit::uninit().assume_init() };
4543
&CLASS
4644
}};
4745
}

0 commit comments

Comments
 (0)