MutexGuard::map can cause a data race in safe code
Moderate severity
GitHub Reviewed
Published
May 24, 2022
to the GitHub Advisory Database
•
Updated Jun 13, 2023
Description
Published by the National Vulnerability Database
Dec 31, 2020
Published to the GitHub Advisory Database
May 24, 2022
Reviewed
Jun 16, 2022
Last updated
Jun 13, 2023
Affected versions of the crate had a Send/Sync implementation for MappedMutexGuard that only considered variance on T, while MappedMutexGuard dereferenced to U.
This could of led to data races in safe Rust code when a closure used in MutexGuard::map() returns U that is unrelated to T.
The issue was fixed by fixing Send and Sync implementations, and by adding a PhantomData<&'a mut U> marker to the MappedMutexGuard type to tell the compiler that the guard is over U too.
References