-
Notifications
You must be signed in to change notification settings - Fork 343
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
Stacked Borrows error can appear during validation, causing an ICE #2123
Comments
Oh, that is fascinating. So even though we just wrote that value to the given location, we still get UB when trying to read it back? Not sure how that can happen. A better stack trace (with all the missing source spans) and a self-contained example reproducing the problem would be really useful. |
This code is metaprogramming and nightly features way beyond my skill as a Rust programmer, but I narrowed down the location of the ICE to this default fn fatten(thin: *mut (), t: Self::Meta) -> *mut Self {
let t: TraitObject = type_coerce(t);
let vtable: *const () = t.vtable;
let vtable = vtable as *mut ();
std::ptr::from_raw_parts_mut(thin, unsafe { transmute_coerce(vtable) })
} |
#![feature(ptr_metadata)]
trait Foo {}
impl Foo for u32 {}
fn uwu(thin: *const (), meta: &'static ()) -> *const dyn Foo {
core::ptr::from_raw_parts(thin, unsafe { core::mem::transmute(meta) })
}
fn main() {
unsafe {
let orig = 1_u32;
let x = &orig as &dyn Foo;
let (ptr, meta) = (x as *const dyn Foo).to_raw_parts();
let _ = uwu(ptr, core::mem::transmute(meta));
}
} Isolated reproduction. Reproduces with pointer tagging enabled as well. |
So what happens here is that This is what I get for doing actual memory accesses during validation in one specific case. ;) Good catch! |
validating the vtable can lead to Stacked Borrows errors Fixes rust-lang/miri#2123
test for Stacked Borrows error during vtable validation Fixes #2123 Needs rust-lang/rust#97761
test for Stacked Borrows error during vtable validation Fixes #2123 Needs rust-lang/rust#97761
I'm really lost on this one, but at least it reproduces
full error with backtrace
The text was updated successfully, but these errors were encountered: