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.
Issue Description
Intern<T> unconditionally implements Sync. This allows users to create data races on T: !Sync.
Such data races can lead to undefined behavior.
Below is an example program that exhibits undefined behavior (memory corruption) using safe APIs of internment.
Show Detail
#![forbid(unsafe_code)]use internment::Intern;use std::borrow::Borrow;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(Debug,PartialEq,Eq,Clone)]structFoo(Cell<RefOrInt>);implHashforFoo{fnhash<H:Hasher>(&self,state:&mutH){self.0.get().hash(state);}}implFoo{fnset(&self,v:RefOrInt){self.0.set(v);}fnget(&self) -> RefOrInt{self.0.get()}}fnmain(){let non_sync = Foo(Cell::new(RefOrInt::Ref(&SOME_INT)));let i0 = Arc::new(Intern::new(non_sync));let i1 = i0.clone();
std::thread::spawn(move || {let i1 = i1;loop{// Repeatedly write Ref(&addr) and Int(0xdeadbeef) into the cell.
i1.set(RefOrInt::Ref(&SOME_INT));
i1.set(RefOrInt::Int(0xdeadbeef));}});loop{ifletRefOrInt::Ref(addr) = i0.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
Intern<T>
unconditionally implementsSync
. This allows users to create data races onT: !Sync
.Such data races can lead to undefined behavior.
internment/src/lib.rs
Line 150 in 863dbc0
Reproduction
Below is an example program that exhibits undefined behavior (memory corruption) using safe APIs of
internment
.Show Detail
Output:
Tested Environment
The text was updated successfully, but these errors were encountered: