Skip to content

rust: pin-init: fix incorrect accessor reference lifetime

Gary Guo lkml rust-for-linux stable 2 versions – Applied

Status from this message: Applied to `rust-fixes` (originally, half a day ago) -- thanks!

Get series with b4
b4 am [email protected] change-id 20260423-pin-init-fix-cf469cd6f782

Versions newest first

  1. v3 Latest2 patches 4 repliesApplied
  2. v22 patches 3 repliesSuperseded

Changes in v3 from the cover letter

- Reworked DropGuard to still use pointers and related safety comments (Sashiko).
- Link to v2: https://patch.msgid.link/[email protected]

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/2rust: pin-init: internal: move alignment check to `make_field_check`rust/pin-init/internal/src/init.rs+37 -410 replies
2/2rust: pin-init: fix incorrect accessor reference lifetimerust/pin-init/internal/src/init.rs rust/pin-init/src/__internal.rs+66 -680 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchAlice Ryhl
1/2R-b
2/2

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

Read the v3 thread

Cover letter [PATCH v3 0/2] rust: pin-init: fix incorrect accessor reference lifetime

When a field has been initialized, init!/pin_init! create a reference or pinned reference to the field so it can be accessed later during the initialization of other fields. However, the reference it created is incorrectly &'static rather than just the scope of the initializer.

This means that you can do

    init!(Foo {
        a: 1,
        _: {
            let b: &'static u32 = a;
        }
    })

which is unsound.

This series fix the issue. Details can be found in the second patch.

---
Changes in v3:
- Reworked DropGuard to still use pointers and related safety comments (Sashiko).
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Moved the field alignment check as the current dual-purpose reference taking for guard and for unaligned fields cause trouble when refactoring.
- Use a method instead of DerefMut operator as we don't need the Deref.
- Reworked DropGuard to use a reference to capture the safety invariants (Sashiko)
- Generally improved the safety comments.
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]

---
Gary Guo (2):
rust: pin-init: internal: move alignment check to make_field_check
rust: pin-init: fix incorrect accessor reference lifetime

 rust/pin-init/internal/src/init.rs | 184 +++++++++++++++++--------------------
 rust/pin-init/src/__internal.rs    |  28 ++++--
 2 files changed, 103 insertions(+), 109 deletions(-)

---
base-commit: 97e797263a5e963da3d1e66e743fd518567dfe37
change-id: 20260423-pin-init-fix-cf469cd6f782

Best regards,

Signature · 1 line
Gary Guo <[email protected]>