RGB-Tools / RGB-Tools/rust-lightning
RUSTSEC-2026-0097: Rand is unsound with a custom logger using `rand::rng()`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
Rand is unsound with a custom logger using
rand::rng()
| Details | |
|---|---|
| Status | unsound |
| Package | rand |
| Version | 0.8.5 |
| URL | https://github.com/rust-random/rand/pull/1763 |
| Date | 2026-04-09 |
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
logandthread_rngfeatures are enabled - A custom logger is defined
- The custom logger accesses
rand::rng()(previouslyrand::thread_rng()) and calls anyTryRng(previouslyRngCore) methods onThreadRng - 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
getrandomcrate) 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.
See advisory page for additional details.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue identifies rand as the affected package and links the upstream rand pull request and RustSec advisory. Review those references first, then determine the repository change needed to stop using an affected rand version and verify that the vulnerability is no longer present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100