Skip to content
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

test: run Miri with RUSTFLAGS="-Zrandomize-layout" #231

Merged
merged 1 commit into from
Jun 19, 2022

Conversation

hawkw
Copy link
Owner

@hawkw hawkw commented Jun 19, 2022

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]>
@hawkw hawkw requested a review from jamesmunns June 19, 2022 16:52
@hawkw hawkw merged commit 7e97fd2 into main Jun 19, 2022
@hawkw hawkw deleted the eliza/miri-randomize-layout branch June 19, 2022 18:59
hawkw added a commit that referenced this pull request Jun 21, 2022
`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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enable -Zrandomize-layout for miri tests
1 participant