-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the -Z randomize-layout
flag
#457
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed. cc @rust-lang/compiler @rust-lang/compiler-contributors |
@rustbot second |
@rustbot label -final-comment-period +major-change-accepted |
Add user seed to `-Z randomize-layout` Allows users of -`Z randomize-layout` to provide `-Z layout-seed=<seed>` in order to further randomizing type layout randomization. Extension of [compiler-team/rust-lang#457](rust-lang/compiler-team#457), allows users to change struct layouts without changing code and hoping that item path hashes change, aiding in detecting layout errors
`cordyceps` and `maitake` currently contain code that perform layout-dependent casts (in this case, casting a ptr to struct to a ptr to the struct's first subfield), which would be UB if those structs were not `#[repr(C)]`. the `-Zrandomize-layout` flag tells the Rust compiler to randomize the layout of all `#[repr(Rust)]` structs (see rust-lang/compiler-team#457 for details). if we ever perform a layout-dependent cast on a struct that is not `#[repr(C)]` (or `#[repr(transparent)]`), layout randomization would break that cast. enabling this flag while running the Miri tests will help to catch any bugs introduced by accidentally performing such a cast on a non-layout-dependent type. i also made some changes to the `bin/miri` script. this was primarily to add comments on the individual flags that are added to `$MIRIFLAGS`, so that we can remember what they're doing when we look back at the script. the actual behavior should be identical, but the values added to `$MIRIFLAGS` are now declared in an array so that each flag can have a comment. Closes #229 Signed-off-by: Eliza Weisman <[email protected]>
`cordyceps` and `maitake` currently contain code that perform layout-dependent casts (in this case, casting a ptr to struct to a ptr to the struct's first subfield), which would be UB if those structs were not `#[repr(C)]`. the `-Zrandomize-layout` flag tells the Rust compiler to randomize the layout of all `#[repr(Rust)]` structs (see rust-lang/compiler-team#457 for details). if we ever perform a layout-dependent cast on a struct that is not `#[repr(C)]` (or `#[repr(transparent)]`), layout randomization would break that cast. enabling this flag while running the Miri tests will help to catch any bugs introduced by accidentally performing such a cast on a non-layout-dependent type. i also made some changes to the `bin/miri` script. this was primarily to add comments on the individual flags that are added to `$MIRIFLAGS`, so that we can remember what they're doing when we look back at the script. the actual behavior should be identical, but the values added to `$MIRIFLAGS` are now declared in an array so that each flag can have a comment. Closes #229 Signed-off-by: Eliza Weisman <[email protected]>
`cordyceps` and `maitake` currently contain code that perform layout-dependent casts (in this case, casting a ptr to struct to a ptr to the struct's first subfield), which would be UB if those structs were not `#[repr(C)]`. the `-Zrandomize-layout` flag tells the Rust compiler to randomize the layout of all `#[repr(Rust)]` structs (see rust-lang/compiler-team#457 for details). if we ever perform a layout-dependent cast on a struct that is not `#[repr(C)]` (or `#[repr(transparent)]`), layout randomization would break that cast. enabling this flag while running the Miri tests will help to catch any bugs introduced by accidentally performing such a cast on a non-layout-dependent type. i also made some changes to the `bin/miri` script. this was primarily to add comments on the individual flags that are added to `$MIRIFLAGS`, so that we can remember what they're doing when we look back at the script. the actual behavior should be identical, but the values added to `$MIRIFLAGS` are now declared in an array so that each flag can have a comment. Closes #229 Signed-off-by: Eliza Weisman <[email protected]>
Proposal
Adds the
-Z randomize-layout
flag and infrastructure required for it. The randomize layout flag randomizes/shuffles/otherwise makes unpredictable the layout ofrepr(Rust)
types, which do not have a specified layout. This is to aid in debugging programs, detecting undefined behavior and running crater experiments. This does not affect any types with specified layouts, such as#[repr(C)]
or#[repr(transparent)]
types. This is strictly an opt-in flag and will not affect current stable code unless the end user explicitly uses the-Z randomize-layout
flag with a nightly compiler.Mentors or Reviewers
@eddyb
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: