GHSA-cq8v-f236-94qc Rand is unsound with a custom logger using `rand::rng()`
The rand library causes undefined behavior via aliased mutable references when a custom logger accesses the RNG during reseeding, potentially leading to crashes or code execution.
- Exploited in the wild
- Not known
- Login needed
- Not needed
- Attackable
- Not stated
- Victim action needed
- Not needed
- Fix
- Available
What is GHSA-cq8v-f236-94qc?
GHSA-cq8v-f236-94qc is a memory corruption vulnerability in rand, published on 9 Apr 2026.
Official description
It has been reported (by @lopopolo) that the rand library is unsound (i.e. that safe code using the public API can cause Undefined Behaviour) when all the following conditions are met:
- The
logandthread_rngfeatures are enabled - A custom logger is defined
- The custom logger accesses
rand::rng()(previouslyrand::thread_rng()) and calls anyTryRng(previouslyRngCore) methods onThreadRng - The
ThreadRng(attempts to) reseed while called from the custom logger (this happens every 64 kB of generated data) - Trace-level logging is enabled or warn-level logging is enabled and the random source (the
getrandomcrate) is unable to provide a new seed
TryRng (previously RngCore) methods for ThreadRng use unsafe code 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.
Which versions are affected by GHSA-cq8v-f236-94qc?
7 open source packages ship an affected version, including rand.
| Package | Affected | Fixed in |
|---|---|---|
rand crates.io | From 0.10.0 | 0.10.1 |
rand crates.io | From 0.10.0 | 0.10.1 |
rand crates.io | From 0.7.0 | 0.8.6, 0.9.3, 0.10.1 |
rand crates.io | From 0.7.0 | 0.8.6 |
rand crates.io | From 0.7.0 | 0.8.6 |
rand crates.io | From 0.9.0 | 0.9.3 |
1 more packages
rand crates.io | From 0.9.0 | 0.9.3 |
How do I fix GHSA-cq8v-f236-94qc?
Upgrade rand to a fixed version for your release line: 0.10.1, 0.8.6 or 0.9.3.
Upgrade to the fixed version. Memory-safe languages, compiler hardening and fuzzing prevent most new cases. More about Memory corruption.
Is GHSA-cq8v-f236-94qc being exploited?
There is no known exploitation of GHSA-cq8v-f236-94qc in the wild and no public exploit code.
Sources
Also known as RUSTSEC-2026-0097.