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

Sense-data bcopy length not capped to 32-byte sense buffer kernel heap overflow into CCB and info leak of request-frame memory

Summary

mpt_scsi_reply_frame_handler autosense copy uses length min(ccb->csio.sense_len sense_returned) where sense_returned is IOC-supplied 32-bit SenseCount. Neither capped to MPT_SENSE_SIZE(32). If IOC reports SenseCount>32 bcopy reads up to 255 bytes from 32-byte req->sense_vbuf (leaking adjacent request-frame kernel memory CDB SGL entries MsgContext) and writes up to 255 bytes into 32-byte ccb->csio.sense_data (heap overflow into rest of CCB). Driver tells IOC max 32 bytes sense wanted but SenseCount in reply never validated. Target returning descriptor-format sense (up to 252 bytes) triggers. Reachable default initiator role autosense enabled.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-2536 Β· 6 files
FileTypeDescriptionSize
VERDICT.md verdict Source trace confirming DF-2536 bug is real but HW-gated 1.5 KB ↓ raw
fix.diff suggested-fix Cap sense_returned to MPT_SENSE_SIZE before bcopy 453 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-2536 bug is real but HW-gated
↓ download raw

DF-2536 β€” Sense-data bcopy length not capped to 32-byte sense buffer

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

Hardware gate

No LSI Logic MPT HBA in guest: kldstat shows only kernel/ehci/xhci; pciconf -l shows no LSI device. No SCSI I/O completions with autosense occur.

Source trace (confirmed real bug)

File: sys/dev/disk/mpt/mpt_cam.c:3141-3150

sense_returned = le32toh(scsi_io_reply->SenseCount);  // line 3141: IOC-supplied U32
...
bcopy(req->sense_vbuf, &ccb->csio.sense_data,
    min(ccb->csio.sense_len, sense_returned));        // line 3149-3150

MPT_SENSE_SIZE is 32 (mpt.h:823). The driver tells the IOC max 32 bytes of sense wanted, but SenseCount in the reply is a 32-bit IOC-supplied value that is never validated against 32. If the IOC reports SenseCount > 32, the bcopy reads up to 255 bytes from the 32-byte req->sense_vbuf (leaking adjacent request-frame kernel memory: CDB, SGL entries, MsgContext) and writes up to 255 bytes into the 32-byte ccb->csio.sense_data (heap overflow into the rest of the CCB). Other code paths correctly cap to MPT_SENSE_SIZE (lines 2119-2120, 4527-4528).

Fix

Added if (sense_returned > MPT_SENSE_SIZE) sense_returned = MPT_SENSE_SIZE; before the bcopy. See fix.diff.

Impact (on HW that has the HBA)

Medium β€” heap overflow into CCB + info leak of request-frame kernel memory via malicious/faulty IOC returning descriptor-format sense (up to 252 bytes).

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-2536/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-2536/{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-2536/fix.diff; git apply --check OK).

Verdict

NOT REPRODUCED (HW-gated). The bug is REAL in source (traced line-by-line): mpt_cam sense-data bcopy length not capped to 32-byte sense buffer (IOC SenseCount unvalidated; needs LSI MPT). 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.