Hi, thanks for your time to read this issue.
Our static analyzer find a potential unsound issue in SharedMutex, where the drop fuction needs to check if the pthread_mutex is unlocked and destroying a locked pthread_mutex is considered as undefined behaviors in doc.
|
fn drop(&mut self) { |
|
if getpid() == self.owner_pid { |
|
check_libc_err(unsafe { pthread_mutex_destroy(self.mutex.get_mut()) }) |
|
.expect("cannot destroy mutex"); |
|
} |
|
} |
A potentail PoC code is like:
#[deny(unsafe_code)]
use process_sync::SharedMutex;
fn main() {
if let Ok(mut s) = SharedMutex::new(){
if let Ok(_) = s.lock(){
drop(s);
}
}
}
FYI, a good way to handle is like std library:
https://github.com/rust-lang/rust/blob/414482f6a0d4e7290f614300581a0b55442552a3/library/std/src/sys/sync/mutex/pthread.rs#L55-L64
Thanks again for your time.
Hi, thanks for your time to read this issue.
Our static analyzer find a potential unsound issue in
SharedMutex, where thedropfuction needs to check if thepthread_mutexis unlocked and destroying a lockedpthread_mutexis considered as undefined behaviors in doc.process-sync-rs/src/mutex.rs
Lines 123 to 128 in f1a207a
A potentail PoC code is like:
FYI, a good way to handle is like
stdlibrary:https://github.com/rust-lang/rust/blob/414482f6a0d4e7290f614300581a0b55442552a3/library/std/src/sys/sync/mutex/pthread.rs#L55-L64
Thanks again for your time.