GHSA-cq8v-f236-94qc

Suggest an improvement
Source
https://github.com/advisories/GHSA-cq8v-f236-94qc
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/04/GHSA-cq8v-f236-94qc/GHSA-cq8v-f236-94qc.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-cq8v-f236-94qc
Aliases
Downstream
CGA (429)
MINI (28)
Published
2026-04-14T01:03:36Z
Modified
2026-09-10T03:50:43Z
Summary
Rand is unsound with a custom logger using rand::rng()
Details

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.

Database specific
{
    "cwe_ids":  [
        "CWE-20"
    ],
    "github_reviewed":  true,
    "github_reviewed_at":  "2026-04-14T01:03:36Z",
    "nvd_published_at":  null,
    "severity":  "LOW"
}
References

Affected packages

crates.io / rand

Package

Affected ranges

Type
SEMVER
Events
Introduced
0.9.0
Fixed
0.9.3

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/04/GHSA-cq8v-f236-94qc/GHSA-cq8v-f236-94qc.json"

crates.io / rand

Package

Affected ranges

Type
SEMVER
Events
Introduced
0.10.0
Fixed
0.10.1

Affected versions

0.*
0.10.0

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/04/GHSA-cq8v-f236-94qc/GHSA-cq8v-f236-94qc.json"

crates.io / rand

Package

Affected ranges

Type
SEMVER
Events
Introduced
0.7.0
Fixed
0.8.6

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/04/GHSA-cq8v-f236-94qc/GHSA-cq8v-f236-94qc.json"