-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.Category: This is a bug.F-c_unwind`#![feature(c_unwind)]``#![feature(c_unwind)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessWG-ffi-unwindWorking group: FFI unwindWorking group: FFI unwindrequires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
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
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.Category: This is a bug.F-c_unwind`#![feature(c_unwind)]``#![feature(c_unwind)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessWG-ffi-unwindWorking group: FFI unwindWorking group: FFI unwindrequires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.