trm_ExecuteSRB writes user-controlled nseg SG entries into 32-slot pSRBSGL with no bounds check (heap overflow via pass(4) SCATTER_VALID)
Summary
When XPT_SCSI_IO CCB arrives with CAM_SCATTER_VALID trm_action passes pcsio->sglist_cnt (u_int16_t user-controlled max 65535) directly to trm_ExecuteSRB as nseg. trm_ExecuteSRB loops nseg times writing attacker-controlled SGentry records into pSRB->pSRBSGL fixed-size 32-entry 256-byte DMA-coherent region. sglist_cnt>32 writes attacker-chosen 8-byte records into adjacent SRB SG lists kernel heap overflow consumed as hardware DMA S/G list. xpt_merge_ccb copies user flags verbatim passsendccb lets userland set CAM_SCATTER_VALID|CAM_SG_LIST_PHYS with any sglist_cnt. Operator-group /dev/passN 0600 root:operator.
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-2520 Β· 6 files| File | Type | Description | Size | |
|---|---|---|---|---|
| VERDICT.md | verdict | Source trace confirming DF-2520 bug is real but HW-gated | 1.2 KB | β raw |
| fix.diff | suggested-fix | Add nseg > TRM_MAX_SG_LISTENTRY bounds check in trm_ExecuteSRB | 437 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 |
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.diffhas been authored and validated withgit apply --check.
Evidence
VERDICT.mdβ full source trace and analysisenv.txtβ guest environment (kldstat, pciconf, camcontrol gate proof)fix.diffβ git-apply-able defense-in-depth fixmanifest.jsonβ machine-readable catalog
DF-2520 β trm_ExecuteSRB writes user-controlled nseg SG entries into 32-slot pSRBSGL
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. The trm driver does not attach.
Source trace (confirmed real bug)
File: sys/dev/disk/trm/trm.c:433-440 (trm_ExecuteSRB)
psg = pSRB->pSRBSGL; // DMA-coherent region: TRM_MAX_SG_LISTENTRY(32) * sizeof(SGentry)
while (dm_segs < end_seg) {
psg->address = dm_segs->ds_addr;
psg->length = (u_long)dm_segs->ds_len;
psg++;
dm_segs++;
}
pSRBSGL is allocated as TRM_MAX_SG_LISTENTRY * sizeof(SGentry) = 32 * 8 = 256
bytes (trm.h:92, 3498). The DMA tag buffer_dmat allows TRM_NSEG segments
(btoc(MAXPHYS)+1, typically 33). If nseg > 32, the loop writes past the 32-entry
SG list into adjacent SRB SG lists / kernel heap. There is no bounds check on
nseg before the loop.
Fix
Added if (nseg > TRM_MAX_SG_LISTENTRY) early-return check before the SG fill loop.
See fix.diff.
Impact (on HW that has the HBA)
High β heap overflow via pass(4) SCATTER_VALID with sglist_cnt > 32. Operator-group
/dev/passN access suffices.
Fix verification
not_testablenot_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-2520/fix.diff => EXIT=0. No runtime test possible (no target HBA).
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-2520/{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-2520/fix.diff; git apply --check OK).
Verdict
NOT REPRODUCED (HW-gated). The bug is REAL in source (traced line-by-line): trm_ExecuteSRB writes user-controlled nseg SG entries into 32-slot pSRBSGL (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.
No comments yet.