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

cardbus_cis: UB in decode_tuple_bar 1<<(ffs(0)-1) when masked BAR probe value is zero

Summary

decode_tuple_bar 360-368: pci_write_config(child,bar,0xffffffff,4); pci_bar=pci_read_config(child,bar,4); if(pci_bar!=0x0&&pci_bar!=0xffffffff) { pci_bar&=~0xf or ~0x3; len=1<<(ffs(pci_bar)-1). Bounds check at 362 examines raw pci_bar BEFORE type-bit mask. Masked value can be 0 (probe=0xf for mem, 0x3 for I/O) -> ffs(0)=0 -> 0-1=-1 -> 1<<-1 UB. len corrupted passed to resource_list_add. Malicious PCI BAR returning only low type-encoding bits. Fix: if(pci_bar==0) return EINVAL after mask.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-1811 Β· 5 files
FileTypeDescriptionSize
VERDICT.md verdict Source verification narrative 1.1 KB ↓ raw
fix.diff suggested-fix Fix: Add if(pci_bar==0) return EINVAL after the type-bit mask. 315 B view raw
build.sh build-script Build/validation instructions 366 B view raw
run.sh run-script Run instructions (HW-gated, source-only) 184 B view raw
env.txt environment Guest environment 404 B view raw
VERDICT.md verdict Source verification narrative
↓ download raw

DF-1811 - Source Verification

Verdict: REPRODUCED (source-only confirmation)

Finding: sys/dev/pccard/cardbus/cardbus_cis.c:360-368

Mechanism: decode_tuple_bar checks pci_bar!=0 BEFORE masking type bits. After mask, pci_bar can be 0 β†’ ffs(0)=0 β†’ 1<<(0-1) = 1<<-1 undefined behavior.

Hardware dependency: Requires CardBus PCI device with malicious BAR encoding.

Fix: Add if(pci_bar==0) return EINVAL after the type-bit mask.

Verification method

Source-only confirmation. The cited code path was traced line-by-line in the audited sys/ tree. The bug exists exactly as described. This is a HW-gated driver finding β€” the vulnerable code path requires specific hardware (GPU, controller, PHY, TPM, etc.) not present in the QEMU audit guest. Runtime reproduction on this guest is not possible without the hardware.

Fix validation

fix.diff authored and applied to guest source. All 40 fixes in this batch compile cleanly in a single combined kernel build: make -j6 nativekernel KERNCONF=X86_64_GENERIC β†’ rc=0, zero -Werror violations.

Kernel: DragonFly 6.5-DEVELOPMENT #0: Thu Jul 2 06:02:54 UTC 2026

Fix verification

not_testable
baseline reproduced→ patch + rebuild →patched clean

not_testable: HW-gated. fix.diff applies + compiles in batch build (rc=0 -Werror). Source trace confirms fix closes the path.

Batch build: 40 fix.diffs applied, make nativekernel β†’ rc=0 -Werror. Bug at sys/dev/pccard/cardbus/cardbus_cis.c:360-368 source-confirmed.
↓ fix.diffDragonFly 6.5-DEVELOPMENT #0: Thu Jul 2 06:02:54 UTC 2026

Confirmed kernel references

Detail

Exploit chain

none

Evidence (decisive lines)

Source trace sys/dev/pccard/cardbus/cardbus_cis.c:360-368. HW-gated (no HW in QEMU). Fix compiles in batch build rc=0.

PoC changes

Evidence pack: VERDICT.md, fix.diff, manifest.json. Fix: ffs(0)-1=-1 UB after BAR type-mask. Add pci_bar==0 check after mask.

Verified recommended fix

See fix.diff. ffs(0)-1=-1 UB after BAR type-mask. Add pci_bar==0 check after mask.

Verdict

REPRODUCED (source-only). sys/dev/pccard/cardbus/cardbus_cis.c:360-368: ffs(0)-1=-1 UB after BAR type-mask. Add pci_bar==0 check after mask.