Skip to content

Support dynamically allocated lockdep keys #1102

@fbq

Description

@fbq

Currently, there's a design hole which allows users to pass an unregistered lockdep key to a C function that expects a registered one: example. We can fix this by:

  • Replace &LockClassKey with Pin<&LockClassKey> in all lock APIs to reflect that the lock keys need address stability to work.
  • Introduce pin initializer for LockClassKey, which registers the key at the initialization time.
  • Add pin drop function for LockClassKey, which unregisters the key.
  • Make sure static_lock_class!() still work by creating a Pin<&'static LockClassKey> from a static uninit variable (as long as it's static allocated, lockdep supports the uninitialized key).

Detailed discussions can be found: https://lore.kernel.org/rust-for-linux/2e3bc20e-ca91-45bb-9e35-586620e56d96@proton.me/

Metadata

Metadata

Assignees

Labels

unsoundThe possibility of UB in safe code.• libRelated to the `rust/` library.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions