Unsynchronized read-modify-write race on global PRNG state randseed (SMP)
Summary
Sole kernel PRNG state randseed (random.c:36) is plain static u_long protected by NO lock NO crit section NO atomic operation. krandom() performs non-atomic read-modify-write: reads randseed into x (random.c:60) computes next state writes back (random.c:66). On SMP/LWKT kernel concurrent callers on different CPUs (two filesystems allocating inodes via ffs_alloc.c:642/ext2_vfsops.c:1421 or concurrent network-stack paths) interleave and (a) return identical values (b) can lose state updates. Result: duplicate/correlated random values to security-sensitive consumers. Sibling arc4random.c:149 wraps state in crit_enter/crit_exit. krandom callable from any CPU anytime callers span kern_synch.c scheduler ffs_alloc.c VFS if_spppsubr.c network dummynet ipfw3_nat. Impact 1: duplicate inode generation numbers i_gen collision means stale NFS client filehandle for deleted file can validate against freshly-created unrelated inode (NFS filehandle confusion potential unauthorized access). Impact 2: correlated CHAP challenge words race can duplicate/skip values weakening already-weak challenge. Impact 3: duplicate NAT alias ports duplicate IPv6 fragment IDs. No privilege required beyond local execution. [VERIFIED pass2: reproduced on real krandom of 6-CPU guest - 4.29M/4.03M/4.42M duplicates per 6M SMP draws 67-74 percent vs exactly 0 in pinned control; fix-validated atomic cmpset loop 0/0/0 duplicates; NFS stale-FH gen-equality ceiling at ufs_vfsops.c:217 reasoned line-accurately; NOT privesc - crypto class]
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-2250 Β· 11 files| File | Type | Description | Size | |
|---|---|---|---|---|
| rng_harness.c | β | 10.9 KB | view raw | |
| build.sh | β | 117 B | view raw | |
| run.sh | β | 90 B | view raw | |
| build.log | β | 5.6 MB | β download | |
| install.log | β | 80.4 KB | view raw | |
| run.log | β | 4.1 KB | view raw | |
| fix.diff | β | 786 B | view raw | |
| fix_build.log | β | 5.6 MB | β download | |
| fix_run.log | β | 1.9 KB | view raw | |
| early_session_with_harness_bug.txt | β | 199 B | view raw | |
| env.txt | β | 1.2 KB | view raw |
Fix verification
fixedConfirmed kernel references
Detail
Evidence (decisive lines)
run.log lines RNGRACE mode=SMP duplicates=4294616/4028727/4423068 vs CONTROL duplicates=0 twice; fix_run.log shows duplicates=0/0/0 and 0/0 after fix.diff; duplicate examples attribute identical values to different CPUs; early_session_with_harness_bug.txt documents the first harness revision panic (my harness bug, not the finding)
PoC changes
PoC authored from scratch (no seed pack existed): kernel-compiled harness rng_harness.c (runtime kldload GPFs this guest) with sysctl debug.rng_race (+/- arg = SMP vs pinned control), per-draw CPU attribution, kernel kqsort duplicate counting; first revision had a control-mode buffer sizing bug that panicked the guest (documented), fixed before the clean baseline runs
Verified recommended fix
sys/libkern/random.c: replace the plain read-modify-write of randseed with an atomic_cmpset_long retry loop so concurrent callers always consume distinct chain states
Verdict
Race confirmed on the real krandom() of the stock SMP guest: 6 LWKT threads pinned to CPUs 0..5 hammering krandom() produced 4294616 / 4028727 / 4423068 duplicate values per 3 x 6e6 draws (67-74 percent duplicate-pair rate, cross-CPU and same-CPU), while the single-thread-pinned control over the same 6e6 draws produced exactly 0 duplicates, as a serial MINSTD chain of period 2^31-2 must. randseed (random.c:36) has no lock, crit, or atomic around its read (random.c:60) and write (random.c:66). Fix (atomic_cmpset_long loop) validated on a rebuilt kernel: duplicates 0/0/0 with control 0/0, and the DF-2251 prediction demo still succeeds, proving the findings independent. Impact is degraded uniqueness of security values (i_gen fallbacks, CHAP/LCP, NAT ports, counters seeds), not memory corruption and not one of the five impact buckets, hence impact none with the real ceiling quantified in VERDICT.md.
No comments yet.