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 fellow Rustacean,
we (Rust group @sslab-gatech) found a memory-safety/soundness issue in this crate while scanning Rust code on crates.io for potential vulnerabilities.
ShmWriter implements Send trait regardless of the inner type parameter H. This definition allows safe Rust code to send non-Send type across threads, which potentially causes a data race or undefined behavior.
H: Send trait bound should probably be added to ShmWriter's Send implementation. If all handlers are expected to be Send, then Send bound can be added to Handler trait's definition instead.
Reproduction
Below is an example program that shows non-Send type can be sent across threads using safe APIs of kekbit.
Show Detail
#![forbid(unsafe_code)]use std::marker::PhantomData;use std::thread;use kekbit::api::Handler;use kekbit::core::{shm_writer,Metadata,TickUnit::Nanos};// non-Send type that panics when dropped in a wrong threadstructNonSend{created_thread: thread::ThreadId,// Ensure `NonSend` type does not implement `Send` trait_marker:PhantomData<*mut()>,}implNonSend{pubfnnew() -> Self{NonSend{created_thread: thread::current().id(),_marker:PhantomData,}}}implDropforNonSend{fndrop(&mutself){if thread::current().id() != self.created_thread{panic!("NonSend destructor is running on a wrong thread!");}}}implHandlerforNonSend{}fnmain(){// Example code from: https://docs.rs/kekbit/0.3.3/kekbit/core/fn.shm_writer.html#examplesconstFOREVER:u64 = 99_999_999_999;let writer_id = 1850;let channel_id = 42;let capacity = 3000;let max_msg_len = 100;let metadata = Metadata::new(writer_id, channel_id, capacity, max_msg_len,FOREVER,Nanos);let test_tmp_dir = tempdir::TempDir::new("kekbit").unwrap();let writer = shm_writer(&test_tmp_dir.path(),&metadata,NonSend::new()).unwrap();let handle = thread::spawn(move || {// `NonSend` is sent to another thread via `ShmWriter`drop(writer);});
handle.join().unwrap();}
Output:
thread '<unnamed>' panicked at 'NonSend destructor is running on a wrong thread!', src/main.rs:44:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any', src/main.rs:68:19
Return code 101
Once a fix is released to crates.io, please open a pull request to update the advisory with the patched version, or file an issue on the advisory database repository.
Hello fellow Rustacean,
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
kekbit/src/core/writer.rs
Line 82 in 00fc665
ShmWriter
implementsSend
trait regardless of the inner type parameterH
. This definition allows safe Rust code to send non-Send type across threads, which potentially causes a data race or undefined behavior.H: Send
trait bound should probably be added toShmWriter
'sSend
implementation. If all handlers are expected to beSend
, thenSend
bound can be added toHandler
trait's definition instead.Reproduction
Below is an example program that shows non-Send type can be sent across threads using safe APIs of
kekbit
.Show Detail
Output:
Tested Environment
tempdir = { version = "0.3.7" }
The text was updated successfully, but these errors were encountered: