-
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
interpret: Fix writing uninit to an allocation #96162
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
r? @oli-obk |
@@ -599,6 +605,9 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> { | |||
/// Applies a relocation copy. | |||
/// The affected range, as defined in the parameters to `prepare_relocation_copy` is expected | |||
/// to be clear of relocations. | |||
/// | |||
/// This is dangerous to use as it can violate internal `Allocation` invariants! | |||
/// It only exists to support an efficient implementation of `mem_copy_repeatedly`. |
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.
I tried finding a nice safe API we could add here to support mem_copy_repeatedly
and make all this "compressed range" stuff private, but couldn't come up with anything good.
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.
The warnings are there now, so we can look at it again in the future
This comment has been minimized.
This comment has been minimized.
@bors r+ |
📌 Commit 05489e7 has been approved by |
interpret: Fix writing uninit to an allocation When calling `mark_init`, we need to also be mindful of what happens with the relocations! Specifically, when we de-init memory, we need to clear relocations in that range as well or else strange things will happen (and printing will not show the de-init, since relocations take precedence there). Fixes rust-lang/miri#2068. Here's the Miri testcase that this fixes (requires `-Zmiri-disable-validation`): ```rust use std::mem::MaybeUninit; fn main() { unsafe { let mut x = MaybeUninit::<i64>::uninit(); // Put in a ptr. x.as_mut_ptr().cast::<&i32>().write_unaligned(&0); // Overwrite parts of that pointer with 'uninit' through a Scalar. let ptr = x.as_mut_ptr().cast::<i32>(); *ptr = MaybeUninit::uninit().assume_init(); // Reading this back should hence work fine. let _c = *ptr; } } ``` Previously this failed with ``` error: unsupported operation: unable to turn pointer into raw bytes --> ../miri/uninit.rs:11:14 | 11 | let _c = *ptr; | ^^^^ unable to turn pointer into raw bytes | = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support = note: inside `main` at ../miri/uninit.rs:11:14 ```
Rollup of 6 pull requests Successful merges: - rust-lang#95740 (asm: Add a kreg0 register class on x86 which includes k0) - rust-lang#95813 (Remove extra space before a where clause) - rust-lang#96029 (Refactor loop into iterator; simplify negation logic.) - rust-lang#96162 (interpret: Fix writing uninit to an allocation) - rust-lang#96165 (Miri provenance cleanup) - rust-lang#96205 (Use futex locks on emscripten.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
When calling
mark_init
, we need to also be mindful of what happens with the relocations! Specifically, when we de-init memory, we need to clear relocations in that range as well or else strange things will happen (and printing will not show the de-init, since relocations take precedence there).Fixes rust-lang/miri#2068.
Here's the Miri testcase that this fixes (requires
-Zmiri-disable-validation
):Previously this failed with