Advisory Database
  • Advisories
  • Dependency Scanning
  1. cargo
  2. ›
  3. rand
  4. ›
  5. GHSA-cq8v-f236-94qc

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

April 14, 2026

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.

Affected versions of rand are >= 0.7, < 0.9.3 and 0.10.0.

References

  • github.com/advisories/GHSA-cq8v-f236-94qc
  • github.com/rust-random/rand
  • github.com/rust-random/rand/pull/1763
  • rustsec.org/advisories/RUSTSEC-2026-0097.html

Code Behaviors & Features

Detect and mitigate GHSA-cq8v-f236-94qc with GitLab Dependency Scanning

Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →

Affected versions

All versions starting from 0.7.0 before 0.9.3, all versions starting from 0.10.0 before 0.10.1, version 0.10.0

Fixed versions

  • 0.9.3
  • 0.10.1

Solution

Upgrade to versions 0.10.1, 0.9.3 or above.

Weakness

  • CWE-20: Improper Input Validation

Source file

cargo/rand/GHSA-cq8v-f236-94qc.yml

Spotted a mistake? Edit the file on GitLab.

  • Site Repo
  • About GitLab
  • Terms
  • Privacy Statement
  • Contact

Page generated Sat, 18 Apr 2026 00:19:17 +0000.