⬢ DragonFlyBSD Kernel Audit
DF-2371 / verdict.json
← back to finding ↓ download raw
{
 "finding_id": "DF-2371",
 "status": "reproduced",
 "reproduced": 1,
 "impact": "none",
 "confidence": "certain",
 "verdict": "Real in-kernel twofish_set_key with out-of-range key_len_bits: 320 (k_len=5) writes s_key[4] into mk_tab[0] (struct order l_key, s_key, mk_tab) - observed as the magic mk_tab[0] changing while gen_mk_tab switch(5) falls through leaving the rest stale - and 0 leaves the previous key schedule in place (k_len=0, mk_tab from keyA) while l_key is re-derived from uninitialized me_key/mo_key stack. The userspace twin of the verbatim file shows the harder primitives directly: key_len_bits=2048 walks in_key reads 256 bytes into a guard page (SIGSEGV) and k_len=16 smashes the callee frame (SIGBUS on return). With the length check both kernel scenarios leave the ctx untouched (k_len stays 4, magic intact) and the twin stops faulting. All in-tree callers (twofish_cbc_setkey/twofish_xts_setkey in cryptoapi.c:670/:770) pre-validate, so this is a latent API landmine - as filed.",
 "exploit_chain": "",
 "evidence": "session baseline + run_fixed_kernel.log (setkey320: mk_tab[0]=ce22885b vs cafebabe, mk_tab[1] stale; setkey0: k_len=0, stale schedule), run.log + run_fixed.log (twin: keyread/stacksmash fault then clean), fix.diff",
 "kernel_refs": [
  "sys/crypto/twofish/twofish.c:425",
  "sys/crypto/twofish/twofish.c:433",
  "sys/crypto/twofish/twofish.c:435"
 ],
 "poc_changes": "none; kernel KAT digest 57ff739d4dc92c1b... cross-checked between kernel and userspace twin (identical), the quoted 256-bit KAT suffix in the rig comment was from memory and is superseded by the twin comparison",
 "attempts": 3,
 "guest_uname": "DragonFly dfbsd 6.5-DEVELOPMENT #5 DFBATCH Wed Oct 21 21:27:34 UTC 2026 root:/usr/obj/usr/src/sys/DFBATCH x86_64 (rig kernel); stock baseline #0 X86_64_GENERIC",
 "runtime_sec": 420,
 "guest_dirty": 0,
 "build_cmd": "sh build.sh (twin) + kernel rig",
 "run_cmd": "./run.sh (twin) + sysctl debug.dfbatch.cmd=\"crypto 2371:<kat|setkey0|setkey320>\"",
 "code_hash": "c872cf8f02a063d7e322cc53b4bf4154de47b7e3ebfae04a72e8b297023c5746",
 "notes": "fix validated A/B on the same rig: baseline behavior gone post-patch (see run_fixed* logs); rig kernel = X86_64_GENERIC + device dfbatch, INVARIANTS kept",
 "recommended_fix": "refuse key_len_bits outside {128,192,256} at the top of twofish_set_key"
}