Skip to content

rust: lockdep: Fix soundness issue affecting LockClassKeys

Mitchell Levy lkml rust-for-linux stable 5 versions – Applied

Status from this message: The following commit has been merged into the locking/core branch of tip:

Get series with b4
b4 am [email protected] change-id 20240905-rust-lockdep-d3e30521c8ba

Versions newest first

  1. v4 Latest2 patches 2 repliesApplied
  2. v32 patches 7 repliesSuperseded
  3. v22 patches 3 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v1 posting 2/22 patches1 replySuperseded
v1 RFC posting 1/21 patch3 repliesSuperseded

Changes in v4 from the cover letter

- Expand the cover letter in the 2nd patch to explain why Pin is used despite being redundant at the moment (Thanks Benno Lossin).
- Include a Fixes tag in the 1st patch (Thanks Miguel Ojeda).
- Link to v3: https://lore.kernel.org/r/[email protected]

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/2rust: lockdep: Remove support for dynamically allocated LockClassKeysrust/kernel/sync.rs+4 -120 replies
2/2rust: lockdep: Use Pin for all LockClassKey usagesrust/helpers/helpers.c rust/helpers/sync.c rust/kernel/sync.rs +5 more+78 -162 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchBenno Lossin
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/2] rust: lockdep: Fix soundness issue affecting LockClassKeys

This series is aimed at fixing a soundness issue with how dynamically allocated LockClassKeys are handled. Currently, LockClassKeys can be used without being Pin'd, which can break lockdep since it relies on address stability. Similarly, these keys are not automatically (de)registered with lockdep.

At the suggestion of Alice Ryhl, this series includes a patch for -stable kernels that disables dynamically allocated keys. This prevents backported patches from using the unsound implementation.

Currently, this series requires that all dynamically allocated LockClassKeys have a lifetime of 'static (i.e., they must be leaked after allocation). This is because Lock does not currently keep a reference to the LockClassKey, instead passing it to C via FFI. This causes a problem because the rust compiler would allow creating a 'static Lock with a 'a LockClassKey (with 'a < 'static) while C would expect the LockClassKey to live as long as the lock. This problem represents an avenue for future work.

---
Changes in v4:
- Expand the cover letter in the 2nd patch to explain why Pin is used despite being redundant at the moment (Thanks Benno Lossin).
- Include a Fixes tag in the 1st patch (Thanks Miguel Ojeda).
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Rebased on rust-next
- Fixed clippy/compiler warninings (Thanks Boqun Feng)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped formatting change that's already fixed upstream (Thanks Dirk Behme).
- Moved safety comment to the right point in the patch series (Thanks
Dirk Behme and Boqun Feng).
- Added an example of dynamic LockClassKey usage (Thanks Boqun Feng).
- Link to v1: https://lore.kernel.org/r/[email protected]

Changes from RFC:
- Split into two commits so that dynamically allocated LockClassKeys are removed from stable kernels. (Thanks Alice Ryhl)
- Extract calls to C lockdep functions into helpers so things build properly when LOCKDEP=n. (Thanks Benno Lossin)
- Remove extraneous get_ref() calls. (Thanks Benno Lossin)
- Provide better documentation for new_dynamic(). (Thanks Benno
Lossin)
- Ran rustfmt to fix formatting and some extraneous changes. (Thanks
Alice Ryhl and Benno Lossin)
- Link to RFC: https://lore.kernel.org/r/[email protected]

---
Mitchell Levy (2):
rust: lockdep: Remove support for dynamically allocated LockClassKeys
rust: lockdep: Use Pin for all LockClassKey usages

 rust/helpers/helpers.c          |  1 +
 rust/helpers/sync.c             | 13 +++++++++
 rust/kernel/sync.rs             | 63 ++++++++++++++++++++++++++++++++++-------
 rust/kernel/sync/condvar.rs     |  5 ++--
 rust/kernel/sync/lock.rs        |  9 ++----
 rust/kernel/sync/lock/global.rs |  5 ++--
 rust/kernel/sync/poll.rs        |  2 +-
 rust/kernel/workqueue.rs        |  2 +-
 8 files changed, 77 insertions(+), 23 deletions(-)

---
base-commit: beeb78d46249cab8b2b8359a2ce8fa5376b5ad2d
change-id: 20240905-rust-lockdep-d3e30521c8ba

Best regards,

Signature · 1 line
Mitchell Levy <[email protected]>