You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
we (Rust group @sslab-gatech) found a memory-safety/soundness issue in this crate while scanning Rust code on crates.io for potential vulnerabilities.
Inner<K> implements Sync for all K: EventKey, even when K: !Sync.
It is possible to create a data race to K: !Sync using ParallelEventEmitter::event_names_visitor(), which may lead to undefined behavior.
Reproduction
Below is an example program that exhibits undefined behavior using safe APIs of parallel-event-emitter.
Show Detail
#![forbid(unsafe_code)]use parallel_event_emitter::ParallelEventEmitter;use std::cell::Cell;use std::hash::{Hash,Hasher};use std::sync::Arc;// A simple tagged union used to demonstrate problems with data races in Cell.#[derive(Debug,Hash,PartialEq,Eq,Clone,Copy)]enumRefOrInt{Ref(&'static u64),Int(u64),}staticSOME_INT:u64 = 123;#[derive(PartialEq,Eq,Clone)]structFoo(Cell<RefOrInt>);implHashforFoo{fnhash<H:Hasher>(&self,state:&mutH){self.0.get().hash(state);}}fnmain(){let non_sync_key = Foo(Cell::new(RefOrInt::Ref(&SOME_INT)));letmut emit0 = ParallelEventEmitter::new();
emit0.add_listener(
non_sync_key,
|| Ok(())// dummy listener);let emit0 = Arc::new(emit0);let emit1 = emit0.clone();
std::thread::spawn(move || {let emit1 = emit1;
emit1.event_names_visitor(|key:&Foo| {loop{// Repeatedly write Ref(&addr) and Int(0xdeadbeef) into the cell.
key.0.set(RefOrInt::Ref(&SOME_INT));
key.0.set(RefOrInt::Int(0xdeadbeef));}});});
emit0.event_names_visitor(|key:&Foo| {loop{ifletRefOrInt::Ref(addr) = key.0.get(){// Hope that between the time we pattern match the object as a// `Ref`, it gets written to by the other thread.if addr as*constu64 == &SOME_INTas*constu64{continue;}println!("Pointer is now: {:p}", addr);println!("Dereferencing addr will now segfault: {}",*addr);}}});}
Output:
Pointer is now: 0xdeadbeef
Terminated with signal 11 (SIGSEGV)
Hello,
we (Rust group @sslab-gatech) found a memory-safety/soundness issue in this crate while scanning Rust code on crates.io for potential vulnerabilities.
Issue Description
parallel-event-emitter/src/lib.rs
Line 237 in e9e2a75
Inner<K>
implementsSync
for allK: EventKey
, even whenK: !Sync
.It is possible to create a data race to
K: !Sync
usingParallelEventEmitter::event_names_visitor()
, which may lead to undefined behavior.Reproduction
Below is an example program that exhibits undefined behavior using safe APIs of
parallel-event-emitter
.Show Detail
Output:
Tested Environment
The text was updated successfully, but these errors were encountered: