Skip to content

remove #[disable_initialized_field_access]#111

Open
BennoLossin wants to merge 1 commit intomainfrom
dev/unsound-fix-packed
Open

remove #[disable_initialized_field_access]#111
BennoLossin wants to merge 1 commit intomainfrom
dev/unsound-fix-packed

Conversation

@BennoLossin
Copy link
Member

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

Thus remove the #[disable_initialized_field_access] attribute from init!, which is the only safe way to create an initializer of a packed struct.

In the future, we can add support for packed structs by changing the trait infrastructure to include UnalignedInit or hopefully another mechanism.

Reported-by: Gary Guo gary@garyguo.net
Link: https://rust-for-linux.zulipchat.com/#narrow/channel/561532-pin-init/topic/initialized.20field.20accessor.20detection/with/576210658 [1]
Fixes: db96c51 ("add references to previously initialized fields")

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

Thus remove the `#[disable_initialized_field_access]` attribute from
`init!`, which is the only safe way to create an initializer of a packed
struct.

In the future, we can add support for packed structs by changing the
trait infrastructure to include `UnalignedInit` or hopefully another
mechanism.

Reported-by: Gary Guo <gary@garyguo.net>
Link: https://rust-for-linux.zulipchat.com/#narrow/channel/561532-pin-init/topic/initialized.20field.20accessor.20detection/with/576210658 [1]
Fixes: db96c51 ("add references to previously initialized fields")
Signed-off-by: Benno Lossin <lossin@kernel.org>
@BennoLossin BennoLossin requested a review from nbdd0121 February 27, 2026 19:25
@nbdd0121
Copy link
Member

The commit that this fixes should be the one that introduced this feature instead? Arguably creating reference is the fix, not the fixed commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants