mpt_pci_attach returns success on every failure path causing NULL-deref / linked-list corruption on detach
Summary
The bad: error label of mpt_pci_attach unconditionally returns 0 (success) instead of error code. Newbus believes device DS_ALIVE and invokes mpt_pci_detach on kldunload/hot-unplug even when attach never completed. mpt_pci_detach calls mpt_detach which performs unconditional TAILQ_REMOVE. For disabled-device path (mpt_disable tunable) softc links.tqe_prev stays NULL so TAILQ_REMOVE writes to NULL panic. For inner-mpt_attach-failure path double TAILQ_REMOVE writes stale tqe_prev pointer into global mpt_tailq head silently corrupting list. Root/loader controlled trigger. kldunload mpt or PCIe hot-unplug after failed attach.
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-2483 Β· 6 files| File | Type | Description | Size | |
|---|---|---|---|---|
| VERDICT.md | verdict | Source trace confirming DF-2483 bug is real but HW-gated | 1.2 KB | β raw |
| fix.diff | suggested-fix | Return ENXIO instead of 0 on the bad: error path | 255 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-2483 β mpt_pci_attach returns success on every failure path
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. mpt PCI attach is never called.
Source trace (confirmed real bug)
File: sys/dev/disk/mpt/mpt_pci.c:597-609
The bad: error label unconditionally return (0) (success) at line 609:
bad:
mpt_dma_mem_free(mpt);
mpt_free_bus_resources(mpt);
...
return (0); // β BUG: returns success despite failure
Newbus believes the device is DS_ALIVE and invokes mpt_pci_detach on
kldunload/hot-unplug even when attach never completed. mpt_pci_detach calls
mpt_detach which performs unconditional TAILQ_REMOVE. For the disabled-device
path, softc->links.tqe_prev stays NULL, so TAILQ_REMOVE writes to NULL β panic.
For the inner-attach-failure path, double TAILQ_REMOVE corrupts the global
mpt_tailq head.
Fix
Changed return (0) to return (ENXIO) on the error path. See fix.diff.
Impact (on HW that has the HBA)
Low β panic or list corruption on kldunload/hot-unplug after failed attach.
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-2483/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-2483/{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-2483/fix.diff; git apply --check OK).
Verdict
NOT REPRODUCED (HW-gated). The bug is REAL in source (traced line-by-line): mpt_pci_attach returns 0 on every failure path (DS_ALIVE kept; TAILQ_REMOVE NULL-deref/double-remove on detach; 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.
No comments yet.