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

trm_action bcopy of user-controlled cdb_len into 12-byte CmdBlock overflows the SRB struct (pass(4)-reachable heap corruption)

Summary

trm_action copies pcsio->cdb_len bytes from CCB CDB into pSRB->CmdBlock fixed u_int8_t[12]. cdb_len u_int8_t max 255 propagated verbatim from userland. With CAM_CDB_POINTER source is attacker-controlled user buffer arbitrary size. cdb_len>16 (or >12 32-bit) writes past CmdBlock into Segment0/Segment1/pNextSRB/pSRBDCB/SgSenseTemp/pSRBSGL corrupting SRB-list and DMA pointers with attacker bytes. Even legitimate 16-byte CDBs at edge of CmdBlock only LP64 padding saves them. pass(4) lets userland set cdb_len=255 fully corrupting pNextSRB pSRBDCB pSRBSGL with attacker data.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-2521 Β· 6 files
FileTypeDescriptionSize
VERDICT.md verdict Source trace confirming DF-2521 bug is real but HW-gated 1.3 KB ↓ raw
fix.diff suggested-fix Cap cdb_len to sizeof(CmdBlock)=12 before bcopy 574 B view raw
env.txt environment Guest gate proof: kldstat, pciconf, camcontrol (no target HBA) 1.1 KB view raw
build.sh build-script No buildable PoC (HW-gated) 384 B view raw
run.sh run-script Gate verification commands 411 B view raw
README.md readme Overview of HW-gated finding 791 B ↓ raw
README.md readme Overview of HW-gated finding
↓ download raw

HW-gated SCSI/FC HBA driver finding

This finding targets a SCSI/FC/SATA HBA driver that is not present in this QEMU/KVM guest (only PIIX3 IDE + virtio). The driver cannot attach and the cited code path is unreachable at runtime.

Reproduction status: NOT REPRODUCED (HW-gated)

  • The source bug is confirmed real by line-by-line source trace (see VERDICT.md).
  • It cannot be triggered because the HBA hardware/driver does not exist on this guest.
  • A defense-in-depth fix.diff has been authored and validated with git apply --check.

Evidence

  • VERDICT.md β€” full source trace and analysis
  • env.txt β€” guest environment (kldstat, pciconf, camcontrol gate proof)
  • fix.diff β€” git-apply-able defense-in-depth fix
  • manifest.json β€” machine-readable catalog
VERDICT.md verdict Source trace confirming DF-2521 bug is real but HW-gated
↓ download raw

DF-2521 β€” trm_action bcopy of user-controlled cdb_len into 12-byte CmdBlock

Verdict: NOT REPRODUCED (HW-gated) β€” source bug CONFIRMED

Hardware gate

No Tekram DC395 SCSI HBA in guest: kldstat shows only kernel/ehci/xhci; pciconf -l shows no Tekram PCI device.

Source trace (confirmed real bug)

File: sys/dev/disk/trm/trm.c:591-610 (trm_action)

pSRB->ScsiCmdLen = pcsio->cdb_len;                          // line 591
...
if ((pccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
    bcopy(pcsio->cdb_io.cdb_ptr, pSRB->CmdBlock, pcsio->cdb_len);   // line 598-599
} else
    bcopy(pcsio->cdb_io.cdb_bytes, pSRB->CmdBlock, pcsio->cdb_len); // line 609-610

CmdBlock is u_int8_t[12] (trm.h:145). cdb_len is u_int8_t (max 255) propagated verbatim from userland. With CAM_CDB_POINTER, the source is an attacker-controlled user buffer. cdb_len > 12 writes past CmdBlock into Segment0, Segment1, pNextSRB, pSRBDCB, SgSenseTemp, pSRBSGL β€” corrupting SRB-list and DMA pointers with attacker data.

Fix

Added if (pcsio->cdb_len > sizeof(pSRB->CmdBlock)) early-return check before the bcopy. See fix.diff.

Impact (on HW that has the HBA)

High β€” heap corruption of SRB struct via pass(4) with cdb_len=255. Operator-group /dev/passN access suffices.

Fix verification

not_testable
baseline no→ patch + rebuild →patched clean

not_testable: target driver cannot attach (no target HBA). fix.diff validated with git apply --check (EXIT=0); fix is correct by source trace.

git apply --check findings/poc/DF-2521/fix.diff => EXIT=0. No runtime test possible (no target HBA).
↓ fix.diffDragonFly 6.5-DEVELOPMENT #0 (unpatched with-src baseline β€” target driver not loadable on this guest)

Confirmed kernel references

Detail

Exploit chain

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

Evidence (decisive lines)

kldstat -> kernel/ehci/xhci only (no target driver); pciconf -l -> PIIX3 IDE + virtio only (no target HBA); camcontrol devlist -> only <QEMU QEMU DVD-ROM>. Source confirmed at cited lines.

PoC changes

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

Verified recommended fix

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

Verdict

NOT REPRODUCED (HW-gated). The bug is REAL in source (traced line-by-line): trm_action bcopy of user-controlled cdb_len into 12-byte CmdBlock (needs Tekram DC395 HBA). Gate confirmed: kldstat (only kernel+ehci+xhci; no isp/mpt/sili/trm/sbp module loaded), pciconf -l (no QLogic ISP/LSI MPT/SiliconImage/Tekram/FireWire HBA β€” only PIIX3 IDE atapci0 + virtio), camcontrol devlist (only QEMU DVD-ROM). The target driver cannot attach so the cited code path is dead at runtime on this guest.