Rand is unsound with a custom logger using rand::rng()
Low severity
GitHub Reviewed
Published
Apr 14, 2026
to the GitHub Advisory Database
•
Updated Apr 22, 2026
Package
Affected versions
= 0.10.0
>= 0.9.0, < 0.9.3
>= 0.7.0, < 0.8.6
Patched versions
0.10.1
0.9.3
0.8.6
Description
Published to the GitHub Advisory Database
Apr 14, 2026
Reviewed
Apr 14, 2026
Last updated
Apr 22, 2026
It has been reported (by @lopopolo) that the
randlibrary is unsound (i.e. that safe code using the public API can cause Undefined Behaviour) when all the following conditions are met:logandthread_rngfeatures are enabledrand::rng()(previouslyrand::thread_rng()) and calls anyTryRng(previouslyRngCore) methods onThreadRngThreadRng(attempts to) reseed while called from the custom logger (this happens every 64 kB of generated data)getrandomcrate) is unable to provide a new seedTryRng(previouslyRngCore) methods forThreadRnguseunsafecode to cast*mut BlockRng<ReseedingCore>to&mut BlockRng<ReseedingCore>. When all the above conditions are met this results in an aliased mutable reference, violating the Stacked Borrows rules. Miri is able to detect this violation in sample code. Since construction of aliased mutable references is Undefined Behaviour, the behaviour of optimized builds is hard to predict.References