-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[EXPERIMENT] Record an allowed byte range in pointer provenance for miri #105264
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
The job Click to see the possible cause of the failure (guessed by this bot)
|
May I ask what the goal is of this experiment? Note that Stacked Borrows already has subobject provenance, and does not put a So -- I appreciate the desire to perform experiment, but I think we need to discuss a bit more whether we even want something like this before considering landing the patch and doing a proper review for that. Right now I am inclined against that. Subobject provenance should be part of the aliasing model, not a separate component that risks causing surprising interactions. Stacked Borrows already has subobject provenance so this shouldn't even change anything for Miri. And the new aliasing model we are working on (Tree Borrows) deliberately does not have subobject provenance. It would not be part to add subobject provenance to Tree Borrows, and it would not look anything like this patch. Miri will support both Stacked Borrows and Tree Borrows in parallel for some time, while T-opsem figures out which aspects of which model they want to see adopted into the final model for Rust. |
|
||
let bad_y = unsafe { *xpp1 }; //~ ERROR: only permits access to offsets 0..1 | ||
println!("{}", bad_y); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all raw pointer code. There should not be any UB here, in my opinion. Our stanza generally always was -- if you use the correct offsets, you get to do what you want with the fields of a struct. And if code uses offset_of, that is guaranteed to work even with repr(Rust)
. (This code happens to not use offset_of
, but with your patch the testcase would fail even if it did use offset_of
.)
☔ The latest upstream changes (presumably #105328) made this pull request unmergeable. Please resolve the merge conflicts. |
This is an experiment to have miri disallow accessing one struct field using a pointer to another.
See the test
src/tools/miri/tests/fail/field-access.rs
The idea is to annotate each
PlaceElem::Field
with aProjectionMode
.ProjectionMode
has 2 possible values:ProjectionMode::Weak
: the projected place has the same provenance;ProjectionMode::Strong
: the projected place cannot be used to access memory outside of the field.The provenance for miri is completed to have the byte range of allowed access.
(There is probably a better way to encode this than directly in
Provenance::Concrete
.)The main knob is
compiler/rustc_mir_build/src/build/expr/as_place.rs
, to chose when we put aStrong
/Weak
mode.This draft puts as much
Strong
as for the demonstration.cc @RalfJung