Open
Conversation
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>
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gary noticed [1] that the initializer macros as well as the
[Pin]Inittraits 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 frominit!, 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
UnalignedInitor 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")