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

Provenance GC causes dead_alloc_map ICE when a protector is the last mention of an AllocId #3228

Closed
saethlin opened this issue Dec 16, 2023 · 0 comments · Fixed by #3229
Closed

Comments

@saethlin
Copy link
Member

This program will crash Miri:

extern "Rust" {
    pub fn miri_run_provenance_gc();
}

fn oof(mut b: Box<u8>) {
    drop(b);
    b = Box::new(0u8);
    unsafe { miri_run_provenance_gc() };
}

fn main() {
    oof(Box::new(0u8));
}

We create a Box, and immediately pass it to a function which makes it weakly protected.
This function argument is the only memory with the relevant AllocId.
Then we deallocate the Box, and at the same time overwrite the function argument.
One GC run later

We return from the function and execute this code to check if the allocation is still alive and 💥

// Just because the tag is protected doesn't guarantee that
// the allocation still exists (weak protectors allow deallocations)
// so we must check that the allocation exists.
// If it does exist, then we have the guarantee that the
// pointer is readable, and the implicit read access inserted
// will never cause UB on the pointer itself.
let (_, _, kind) = this.get_alloc_info(*alloc_id);

I'm not entirely sure what the best way to fix this is. The obvious way would be to visit the AllocIds in borrow_tracker::FrameExtra in the GC. But the comments we left around there seemed pretty confident that wouldn't be required, so I'm not totally sure there isn't another sort of design flaw here.

@bors bors closed this as completed in 02880d3 Dec 17, 2023
RalfJung pushed a commit to RalfJung/rust that referenced this issue Dec 17, 2023
Visit the AllocIds and BorTags in borrow state FrameExtra

Fixes rust-lang/miri#3228

I said

> The obvious way would be to visit the AllocIds in borrow_tracker::FrameExtra in the GC.

Since I have had no new ideas, that's what this does.
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.

1 participant