Skip to content

Commit 966944f

Browse files
chessturoIngo Molnar
authored andcommitted
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: 6ea5aa0 ("rust: sync: introduce `LockClassKey`") Suggested-by: Alice Ryhl <[email protected]> Signed-off-by: Mitchell Levy <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 21e4543 commit 966944f

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

rust/kernel/sync.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,20 @@ pub struct LockClassKey(Opaque<bindings::lock_class_key>);
3030
unsafe impl Sync for LockClassKey {}
3131

3232
impl LockClassKey {
33-
/// Creates a new lock class key.
34-
pub const fn new() -> Self {
35-
Self(Opaque::uninit())
36-
}
37-
3833
pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key {
3934
self.0.get()
4035
}
4136
}
4237

43-
impl Default for LockClassKey {
44-
fn default() -> Self {
45-
Self::new()
46-
}
47-
}
48-
4938
/// Defines a new static lock class and returns a pointer to it.
5039
#[doc(hidden)]
5140
#[macro_export]
5241
macro_rules! static_lock_class {
5342
() => {{
54-
static CLASS: $crate::sync::LockClassKey = $crate::sync::LockClassKey::new();
43+
static CLASS: $crate::sync::LockClassKey =
44+
// SAFETY: lockdep expects uninitialized memory when it's handed a statically allocated
45+
// lock_class_key
46+
unsafe { ::core::mem::MaybeUninit::uninit().assume_init() };
5547
&CLASS
5648
}};
5749
}

0 commit comments

Comments
 (0)