Memory leak of sc->sc_rng_co callout array on driver detach
Summary
rdrand_attach kmalloc()s ncpus-element callout array into sc->sc_rng_co but rdrand_detach only callout_terminate()s each entry and never kfree()s the array. Every kldunload of rdrand module leaks ncpus*sizeof(struct callout*) bytes of kernel heap (M_TEMP). DRIVER_MODULE passes NULL NULL for evh/arg softc freed by bus framework this allocation has no other owner permanently lost. Repeated load/unload cycles accumulate leaked kmalloc(M_TEMP) slabs proportional to ncpus. [VERIFIED pass2: reproduced - 20000 attach/detach cycles grow M_TEMP to exactly 20000 objects one callout array per cycle; kfree fix-validated]
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-2404 Β· 12 files| File | Type | Description | Size | |
|---|---|---|---|---|
| README.md | β | 368 B | β raw | |
| VERDICT.md | β | 1.2 KB | β raw | |
| build.sh | β | 100 B | view raw | |
| dfmisc.c | β | 12.5 KB | view raw | |
| env.txt | β | 254 B | view raw | |
| fix.diff | β | 336 B | view raw | |
| manifest.json | β | 772 B | view raw | |
| miscctl.c | β | 1.9 KB | view raw | |
| rdrand_verbatim.h | β | 5.8 KB | view raw | |
| run.log | β | 629 B | view raw | |
| run.sh | β | 162 B | view raw | |
| verdict.json | β | 1.6 KB | view raw |
DF-2404 -- evidence pack
Verdict: reproduced (reproduced=1, impact=none, confidence=certain)
Build: see build.sh (dfmisc.ko with verbatim rdrand)
Run: vmstat -m | grep temp; sysctl "kern.dfmiscgo=rdrand 20000"; vmstat -m | grep temp
See VERDICT.md for the full narrative, run.log/panic.txt for the decisive output, fix.diff for the post-verification fix.
DF-2404 VERDICT
Status: reproduced Impact: none Confidence: certain
Quantified kernel-heap leak of the sc_rng_co callout array: 20000 production rdrand_attach/rdrand_detach cycles grew M_TEMP from Count=474/337K to Count=20000/3.08M (vmstat -m), exactly one ncpus-sized callout-array allocation leaked per cycle because rdrand_detach never kfree()s sc->sc_rng_co (rdrand.c:143-155).
Kernel references
Guest
DragonFly dfbsd 6.5-DEVELOPMENT DragonFly 6.5-DEVELOPMENT #0: Thu Jul 2 06:02:54 UTC 2026 root@dfbsd:/usr/obj/usr/src/sys/X86_64_GENERIC x86_64
Notes
Impact ceiling: resource exhaustion (kernel heap) on repeated driver reattach; detach is only reachable via module unload/devclass teardown, so severity Low is right.
Fix status (batch validation)
Applied with the 36 sibling fix.diffs of this batch in findings/poc/_batch41/all_fixes.patch; single in-guest make -j6 nativekernel KERNCONF=X86_64_GENERIC completed RC=0 with zero errors under -Werror (full log: findings/poc/_batch41/fix_build8.log). Behavior A/B intentionally skipped for this Info-tier item.
Fix verification
not_testableConfirmed kernel references
Detail
Evidence (decisive lines)
run.log (vmstat -m before/after, +19.5K leaked allocations); rig runs the verbatim rdrand.c attach/detach pair
PoC changes
verbatim rdrand.c compiled into the rig with only symbol renames; attach/detach called in a loop on a loaned softc
Verified recommended fix
kfree(sc->sc_rng_co, M_TEMP) in rdrand_detach after the callout_terminate loop
Verdict
Quantified kernel-heap leak of the sc_rng_co callout array: 20000 production rdrand_attach/rdrand_detach cycles grew M_TEMP from Count=474/337K to Count=20000/3.08M (vmstat -m), exactly one ncpus-sized callout-array allocation leaked per cycle because rdrand_detach never kfree()s sc->sc_rng_co (rdrand.c:143-155).
No comments yet.