# DF-0595 — PoC: Michael MIC verification uses non-constant-time memcmp

DF-0595 documents that the DragonFlyBSD kernel's TKIP and CCMP Michael-MIC
verification paths compare the computed 8-byte MIC tag against the received
tag with libc `memcmp`, which short-circuits on the first differing byte.
That short-circuit is the textbook enabling primitive for byte-by-byte
MIC-forcing ("chopchop"-style) attacks against TKIP.

## Files

- `mic_timing_demo.c` — runnable userspace timing-channel demonstration.
  Proves the guest's libc `memcmp` is non-constant-time (clear, repeatable
  last-byte/first-byte timing gap at longer lengths; noisy-but-real at the
  8-byte MIC length, exactly as the finding predicts) and that the constant-
  time idiom DragonFlyBSD already ships (`timingsafe_bcmp`) removes the gap.
- `build.sh` / `run.sh` — exact build & run.
- `build.log`, `run.log`, `run.2.log`, `run.3.log` — full untrimmed output.
- `fix.diff` — the kernel fix: `memcmp` → `timingsafe_bcmp` in both
  `wlan_tkip/ieee80211_crypto_tkip.c:361` and
  `wlan_ccmp/ieee80211_crypto_ccmp.c:642`. `git apply --check` clean.
- `fix_build.log` — full `make nativekernel` output (rc=0).
- `fix_run.log` — userspace demo re-run on the patched kernel (libc control;
  kernel module change verified separately via `nm`/objdump in env.txt).
- `env.txt` — guest environment, before/after kern.version, module symbol audit.
- `VERDICT.md` — full narrative.
- `manifest.json` — artifact catalog for the static site.

## How to reproduce

```
./build.sh && ./run.sh
```

You should see, in Test 1 (256-byte buffers), `memcmp`'s `last/first` ratio
clearly > 1 (≈2–3×) while `timingsafe_bcmp`'s ratio is ≈1.0. Test 2 (the
actual 8-byte MIC tag) is noisy, empirically confirming the Info severity:
the channel is real in principle but dominated by WiFi RTT / softirq jitter
at the real MIC length.

## The fix

The kernel-side fix is a one-token rename in two files: replace `memcmp`
with DragonFlyBSD's existing libkern `timingsafe_bcmp` (already declared in
`<sys/libkern.h>`, already pulled into both files via `<sys/socket.h>`).
See `fix.diff`. Validated by building a single-fix kernel (`#1`), installing
it, rebooting, and confirming via `nm`/objdump that the installed
`/boot/kernel/wlan_tkip.ko` and `wlan_ccmp.ko` reference `timingsafe_bcmp`
(no `memcmp` references remain) and that `_tkip_demic+0xd5` issues
`callq timingsafe_bcmp`.
