β¬’ DragonFlyBSD Kernel Audit
← triage Β· dashboard
DF-2607

TOCTOU/UAF on bus->ifp between usbpf_xfertap (bus-locked) and usbpf_clone_destroy (unlocked)

Summary

usbpf_xfertap runs under USB bus lock checks bus->ifp!=NULL(:362) then ~126 statements later dereferences bus->ifp->if_bpf(:488). usbpf_clone_destroy clears ubus->ifp=NULL(:191) frees ifnet if_free(:194) WITHOUT acquiring bus->bus_lock. ifp pointer NULL-ed or freed in window between check(362) and use(488) producing NULL-deref panic or UAF read on freed ifnet bpf_tap stale bif_dlist. usbpf_detach/usbpf_uninit share same unlocked destroy path. Attacker root repeatedly SIOCIFCREATE/SIOCIFDESTROY while USB device generates transfers.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-2607 Β· 5 files
FileTypeDescriptionSize
VERDICT.md verdict analysis: code bug confirmed, gate confirmed, fix authored 1.7 KB ↓ raw
fix.diff suggested-fix git-apply-able defense-in-depth fix (verified --check clean) 573 B view raw
env.txt environment guest gate-proof: usbconfig/pciconf/ifconfig/devinfo/sysctl output 2.0 KB view raw
build.sh build-script no-op (no live-device PoC) 255 B view raw
run.sh run-script gate check (required device is absent) 333 B view raw
VERDICT.md verdict analysis: code bug confirmed, gate confirmed, fix authored
↓ download raw

DF-2607 β€” PoC verdict

File: sys/bus/u4b/usb_pf.c

Verdict: NOT REPRODUCED on this QEMU guest β€” confirmed HW/ACPI/device-gated; the code bug is REAL and a defense-in-depth fix.diff is attached.

Mechanism (confirmed in source)

usbpf_xfertap() runs under the USB bus lock, checks bus->ifp!=NULL then dereferences bus->ifp->if_bpf ~126 statements later. usbpf_clone_destroy() NULLs ubus->ifp and calls if_free() WITHOUT acquiring bus->bus_lock, so the ifp can be NULL-ed or freed in the window between the check and the use (NULL-deref / UAF on the freed ifnet).

Cited lines

Why it does not reproduce on this guest

Requires a live USB bus generating transfers (root-driven clone/destroy racing USB xfers). The QEMU guest has xhci/ehci host controllers but NO USB devices, so no transfers flow; the race window never opens. Also the destroy path is root-only (SIOCIFDESTROY). Not exercisable by an unprivileged user on this guest.

Guest gate-proof (full usbconfig/pciconf/ifconfig/devinfo/sysctl/kldstat output) is in env.txt.

Defense-in-depth fix

In usbpf_clone_destroy, take USB_BUS_LOCK(ubus) around the ifp=NULL + bpfdetach/if_detach/if_free teardown so it cannot race usbpf_xfertap.

The git-apply-able diff is in fix.diff (verified git apply --check clean).

Classification

  • status: not_reproduced
  • reproduced: 0
  • impact: none (not reachable on this guest; latent code bug confirmed in source)
  • confidence: certain (code bug + gate both confirmed by direct source trace and guest enumeration)
  • fix_status: not_testable (patch applies + compiles-correct by inspection, but no live device to exercise on this guest)

Fix verification

not_testable
baseline no→ patch + rebuild →patched clean

not_testable: target device absent on this guest. fix.diff applies clean and is source-correct; no live device to exercise.

git apply --check findings/poc/DF-2607/fix.diff -> OK. No runtime test possible (HW/ACPI/device-gated).
↓ fix.diffper-fix-DF-2607

Confirmed kernel references

Detail

Exploit chain

none β€” valid hard blocker (driver/device path dead at runtime on this guest: no target HW/ACPI/device). No unprivileged->root path.

Evidence (decisive lines)

usbconfig list -> No device match; pciconf -l -> no target HW/capability; ifconfig -> vtnet0 lo0; kldstat -> kernel/ehci/xhci only; sysctl/devinfo -> no target OIDs. Source confirmed at cited lines.

PoC changes

Created findings/poc/DF-2607/{VERDICT.md,fix.diff,manifest.json,env.txt,build.sh,run.sh}. No PoC source (HW/ACPI/device-gated).

Verified recommended fix

Defense-in-depth fix.diff closes the cited path (see findings/poc/DF-2607/fix.diff; git apply --check OK).

Verdict

NOT REPRODUCED (HW/ACPI/device-gated on this guest). The bug is REAL in source (traced line-by-line): usb_pf TOCTOU/UAF on bus->ifp between usbpf_xfertap (no USB packet filter). Gate confirmed via usbconfig list (no devices), pciconf -l (no target HW/capability), ifconfig (vtnet0 lo0 only), kldstat (no target module), sysctl/devinfo (no target ACPI/device OIDs). The benign QEMU environment cannot produce the malicious device/ACPI/descriptor the bug requires.