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

trm_Reselect walks circular DCB ring with no termination -> infinite loop / hard system hang

Summary

trm_Reselect at trm.c:2427: while(RselTarLunId!=*((u_int16_t*)&pDCB->TargetID)) pDCB=pDCB->pNextDCB. DCB list is circular, no iteration cap or wrap check. Malicious target reselects with ID/LUN matching no DCB -> loop forever in interrupt handler -> system freeze requiring power cycle. No local priv needed. Fix: bound walk by DeviceCnt, treat no-match as abort via TmpSRB.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-1238 Β· 8 files
FileTypeDescriptionSize
fix.diff suggested-fix bound trm_Reselect DCB walk by DeviceCnt; abort via TmpSRB on no-match 1.2 KB view raw
VERDICT.md verdict source-level trace + dead-code analysis 2.6 KB ↓ raw
build.sh build-script applies fix, builds trm.ko module 386 B view raw
run.sh run-script explains no-trigger on this guest 694 B view raw
env.txt environment uname, cc version, PCI inventory 553 B view raw
build.log build-log kernel build log excerpt proving -Werror clean compile of patched source 7.2 KB view raw
../fix_build_combined.log build-log Combined 41-finding kernel build (rc=0, -Werror clean) 5.6 MB ↓ download
../fix_build_summary.txt build-summary Summary of the combined 41-finding kernel build 826 B view raw
VERDICT.md verdict source-level trace + dead-code analysis
↓ download raw

DF-1238 β€” trm_Reselect circular DCB ring (infinite loop / DoS)

Verdict: NOT REPRODUCED (dead code at runtime β€” no hardware)

Mechanism (source-level, confirmed real)

trm_Reselect() at sys/dev/disk/trm/trm.c:2411 handles SCSI target reselection. After reading the reselected target/LUN id at line 2426:

RselTarLunId = trm_reg_read16(TRMREG_SCSI_TARGETID) & 0x1FFF;
pDCB = pACB->pLinkDCB;
while (RselTarLunId != *((u_int16_t *) &pDCB->TargetID)) {
    pDCB = pDCB->pNextDCB;
}

The DCB list is circular: in trm_initDCB() (line 2893-2911) the first node's pNextDCB points to itself, and each subsequent node is inserted so the tail links back to pLinkDCB. So if RselTarLunId matches no DCB (e.g. a malicious/misbehaving SCSI target reselects with a fabricated target/LUN), this while loop has no termination and spins forever in the interrupt handler context, freezing the system (hard hang, requires power cycle).

The bounded-walk pattern is already used elsewhere in the same file at lines 2301-2311 (for (i = 0; i < cnt; i++) using pACB->DeviceCnt), confirming the author intended bounded iteration.

The bug is real in source. A malicious SCSI target that reselects with an ID/LUN not matching any known DCB causes an unbounded loop in interrupt context.

Why it cannot reproduce on this guest

trm is the Tekram DC395U/UW/F SCSI host-bus-adapter driver.

  • NOT in X86_64_GENERIC: only in LINT64 (sys/config/LINT64).
  • Available as a loadable module trm.ko, but not loaded on the guest (kldstat shows only ehci.ko, xhci.ko).
  • The QEMU guest has no SCSI HBA at all β€” pciconf -l shows only 440FX/PIIX3/PIIX4 bridges, VGA, virtio-net, virtio-blk.
  • Even if kldload trm were run (requires root), the driver's trm_probe would find no Tekram PCI device and never attach β†’ no interrupt β†’ no reselection path β†’ unreachable.

This is valid hard blocker: dead/unreachable at runtime on this guest (no hardware). The threat model is a malicious SCSI peripheral on a real system with a Tekram DC395U controller.

Fix

fix.diff bounds the DCB walk by pACB->DeviceCnt iterations and, on no-match, aborts via TmpSRB (consistent with the existing unexpected- reselection abort at lines 2439-2446). Compiled successfully as trm.ko.

Impact

  • On this guest: none (dead code, no hardware).
  • On a real system: unprivileged local DoS / system freeze requiring power cycle, triggered by a malicious SCSI target reselecting with a bogus ID/LUN. No local privilege needed by the attacker β€” the attack surface is a malicious peripheral.

Fix verification

not_testable

compile validated

module/kernel build rc=0

Confirmed kernel references

β€”

Detail

Exploit chain

none

Evidence (decisive lines)

β€”

Verdict

Source-confirmed. trm_Reselect circular DCB walk no termination -> infinite loop. trm NOT in GENERIC, no Tekram HW.