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

Undefined behavior in servo_arc HeaderSlice #26357

Open
brson opened this issue Apr 30, 2020 · 3 comments
Open

Undefined behavior in servo_arc HeaderSlice #26357

brson opened this issue Apr 30, 2020 · 3 comments
Labels
I-safety Some piece of code violates memory safety guarantees.

Comments

@brson
Copy link
Contributor

brson commented Apr 30, 2020

HeaderSlice constructs and dereferences invalid pointers created from non-pointer integers in from_header_and_iter_alloc.

Here's what miri has to say about it:

error: Undefined Behavior: invalid use of 8 as a pointer
    --> components/servo_arc/lib.rs:716:69
     |                                                                                                                                       
716  |             let fake_ref: &ArcInner<HeaderSlice<H, [T]>> = unsafe { &*fake_ptr };
     |                                                                     ^^^^^^^^^^ invalid use of 8 as a pointer                                |
     = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior                                 = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information                            = note: inside `Arc::<HeaderSlice<HeaderWithLength<u32>, [i32]>>::from_header_and_iter_alloc::<[closure@components/servo_arc/lib.rs:815:1
3: 826:14], std::iter::Empty<i32>>` at components/servo_arc/lib.rs:716:69     
@brson
Copy link
Contributor Author

brson commented Apr 30, 2020

Repro by running:

cargo +nightly-2020-04-10 miri test -p servo_arc -- -Zmiri-disable-isolation

inside the servo_arc directory.

@jdm jdm added the I-safety Some piece of code violates memory safety guarantees. label Apr 30, 2020
@brson
Copy link
Contributor Author

brson commented Apr 30, 2020

miri has at least one other issue with this block of code that can be repro'd the same way.

@RalfJung
Copy link

Yeah, ArcInner is definitely not a ZST, so this code is creating a dangling shared reference, which is UB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-safety Some piece of code violates memory safety guarantees.
Projects
None yet
Development

No branches or pull requests

3 participants