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

- Severity: Low (rating, scored by GitHub)
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Published: 2026-04-09T12:00:00.000Z
- Modified: 2026-09-10T03:50:43.958Z
- Also known as: RUSTSEC-2026-0097
- Weaknesses: CWE-20

## Description

It has been reported (by @lopopolo) that the `rand` library is [unsound](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#soundness-of-code--of-a-library) (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](https://docs.rs/log/latest/log/#implementing-a-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](https://doc.rust-lang.org/stable/nomicon/references.html), the behaviour of optimized builds is hard to predict.

(As written by GitHub Advisory Database.)

## Affected

- rand (crates.io): from 0.9.0 before 0.9.3; from 0.10.0 before 0.10.1; from 0.7.0 before 0.8.6

## References

- <https://github.com/rust-random/rand/pull/1763> (web)
- <https://github.com/rust-random/rand> (package)
- <https://rustsec.org/advisories/RUSTSEC-2026-0097.html> (advisory, web)
- <https://crates.io/crates/rand> (package)

## Sources

- GitHub Advisory Database: [GHSA-cq8v-f236-94qc](https://github.com/advisories/GHSA-cq8v-f236-94qc), CC-BY-4.0, modified 2026-09-10
- RustSec Advisory Database: [RUSTSEC-2026-0097](https://rustsec.org/advisories/RUSTSEC-2026-0097.html), CC0-1.0, modified 2026-07-17

---

Page: https://cve.day/GHSA-cq8v-f236-94qc · Whole record: https://cve.day/GHSA-cq8v-f236-94qc.json · Rebuilt by cve.day 2026-11-25T22:56:43.336Z
