Closed
Description
Rust code might be able to catch foreign Rust code through FFI unwind.
a.rs:
#![crate_type = "cdylib"]
#![feature(c_unwind)]
#[no_mangle]
extern "C-unwind" fn panic() {
panic!();
}
b.rs:
#![feature(c_unwind)]
#[link(name = "a")]
extern "C-unwind" {
fn panic();
}
fn main() {
let err = std::panic::catch_unwind(|| {
unsafe { panic() };
});
match err {
Err(v) => {
// Able to access `Box<dyn Any>` generated by another
// compiler; we can't guarantee that typeid does not conflict
// across Rust versions, nor that the vtable format is
// stable.
// EDIT: Also this will result a `Box` allocated in one allocator
// from being deallocated in another, which is more obviously unsound.
}
_ => (),
}
}
These two crates could be compiled with different Rust versions, or same version with different flags (e.g. struct layout randomisation), and this will create unsoundness because we couldn't guarantee the ABI for separate compilations.
Currently we just use the exception class in the unwind runtime ("MOZ\0RUST") to tell apart Rust exceptions from foreign exceptions, but for soundness we need to treat Rust exception from another compilation as foreign exception as well.
Metadata
Metadata
Assignees
Labels
Area: Foreign function interface (FFI)Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsCategory: This is a bug.`#![feature(c_unwind)]`Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessWorking group: FFI unwindThis issue requires a nightly compiler in some way.