]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: pin-init: internal: init: remove `#[disable_initialized_field_access]`
authorBenno Lossin <lossin@kernel.org>
Mon, 2 Mar 2026 14:04:14 +0000 (15:04 +0100)
committerMiguel Ojeda <ojeda@kernel.org>
Fri, 6 Mar 2026 01:04:09 +0000 (02:04 +0100)
commita075082a15e7f5c4889d0cbb51a4041c332cb00c
tree162393ed6e76def1d8b43b3c17fbdc208ddcea20
parentdda135077ecc9f15c407f094dcfe7800376be867
rust: pin-init: internal: init: remove `#[disable_initialized_field_access]`

Gary noticed [1] that the initializer macros as well as the `[Pin]Init`
traits cannot support unaligned fields, since they use operations that
require aligned pointers. This means that any code using structs with
unaligned fields in pin-init is unsound.

By default, the `init!` macro generates references to initialized fields,
which makes the compiler check that those fields are aligned.  However,
we added the `#[disable_initialized_field_access]` attribute to avoid
this behavior in commit ceca298c53f9 ("rust: pin-init: internal: init:
add escape hatch for referencing initialized fields"). Thus remove the
`#[disable_initialized_field_access]` attribute from `init!`, which is
the only safe way to create an initializer handling unaligned fields.

If support for in-place initializing structs with unaligned fields is
required in the future, we could figure out a solution. This is tracked
in [2].

Reported-by: Gary Guo <gary@garyguo.net>
Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/561532-pin-init/topic/initialized.20field.20accessor.20detection/with/576210658 [1]
Link: https://github.com/Rust-for-Linux/pin-init/issues/112
Fixes: ceca298c53f9 ("rust: pin-init: internal: init: add escape hatch for referencing initialized fields")
Signed-off-by: Benno Lossin <lossin@kernel.org>
Acked-by: Janne Grunau <j@jannau.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260302140424.4097655-1-lossin@kernel.org
[ Adjusted tags and reworded as discussed. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/pin-init/internal/src/init.rs