Security mailing lists by PureSourceCode

RUSTSEC-2026-0097

LOW

Rand is unsound with a custom logger using rand::rng()

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.

Published
9 Apr 2026
Last modified
10 Sep 2026
Weakness
CWE-20
Also known as
GHSA-cq8v-f236-94qc
Sources
OSV GHSA-cq8v-f236-94qcJSONOSVJSON

Affected

SourceVendor / ecosystemProduct / packageAffected versionsFixed in
OSV crates.io rand >= 0.9.0, < 0.9.3 0.9.3
OSV crates.io rand >= 0.10.0, < 0.10.1 0.10.1
OSV crates.io rand >= 0.7.0, < 0.8.6 0.8.6
OSV crates.io rand >= 0.7.0, < 0.8.6; >= 0.9.0, < 0.9.3; >= 0.10.0, < 0.10.1 0.8.6, 0.9.3, 0.10.1

References

History

  • 25 Nov 2026 20:14 UTC · OSV: first stored (published 9 Apr 2026)
  • 25 Nov 2026 20:14 UTC · OSV: first stored (published 14 Apr 2026)
An unhandled error has occurred. Reload ×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.