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

enable -Zrandomize-layout for miri tests #229

Closed
hawkw opened this issue Jun 19, 2022 · 0 comments · Fixed by #231
Closed

enable -Zrandomize-layout for miri tests #229

hawkw opened this issue Jun 19, 2022 · 0 comments · Fixed by #231
Assignees

Comments

@hawkw
Copy link
Owner

hawkw commented Jun 19, 2022

we should be running Miri tests with RUSTFLAGS="-Zrandomize-layout". 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)]. i believe that running the Miri tests with this flag would help catch any cases where a layout-dependent cast is inadvertently performed with a type that is not #[repr(C)] (or #[repr(transparent)]?), so we should be enabling it in our Miri CI jobs to catch any potential bugs involving this...

hawkw added a commit that referenced this issue 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]>
hawkw added a commit that referenced this issue 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]>
hawkw added a commit that referenced this issue 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 a pull request may close this issue.

2 participants