GHSA-cq8v-f236-94qc Rand is unsound with a custom logger using `rand::rng()`

Not scored Published

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 log and thread_rng features are enabled
  • A custom logger is defined
  • The custom logger accesses rand::rng() (previously rand::thread_rng()) and calls any TryRng (previously RngCore) methods on ThreadRng
  • 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 getrandom crate) 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.

PackageAffectedFixed in
rand crates.ioFrom 0.10.00.10.1
rand crates.ioFrom 0.10.00.10.1
rand crates.ioFrom 0.7.00.8.6, 0.9.3, 0.10.1
rand crates.ioFrom 0.7.00.8.6
rand crates.ioFrom 0.7.00.8.6
rand crates.ioFrom 0.9.00.9.3
1 more packages
rand crates.ioFrom 0.9.00.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.

Is GHSA-cq8v-f236-94qc in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free