-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed that tiny_future implements Send and Sync for all types:
This should probably be bound by T: Send, otherwise this allows non-Send types such as Rc to be sent across thread boundaries which might invoke undefined behavior.
Here's an example of this in action with an Rc segfaulting safe Rust code:
#![forbid(unsafe_code)]
use tiny_future::Future;
use std::{thread, rc::Rc};
fn main() {
let rc = Rc::new(());
let rc_clone = rc.clone();
let f = Future::with_state(());
f.set(rc_clone);
thread::spawn(move || {
let smuggled_rc = f.get().unwrap();
println!("Thread: {:p}", smuggled_rc);
// Race the refcount with the main thread.
for _ in 0..100_000_000 {
smuggled_rc.clone();
}
});
println!("Main: {:p}", rc);
for _ in 0..100_000_000 {
rc.clone();
}
}Output:
Main: 0x5580ab8c1b50
Thread: 0x5580ab8c1b50
Terminated with signal 4 (SIGILL)
Metadata
Metadata
Assignees
Labels
No labels