Firmware-supplied req_id used as heap index without bounds check in tws_intr_resp and tws_err_complete
Summary
tws_cam.c:1163 tws_intr_resp filters only TWS_INVALID_REQID=0xFFFF, then 1170 sc->reqs[req_id].cb(&sc->reqs[req_id]) NO upper-bound check vs tws_queue_depth (<=256). req_id is u16 from firmware DMA reply. 512-513 tws_err_complete reads req_id from DMA sense header, NO check at all (not even INVALID). OOB req passed to handlers calling xpt_done(req->ccb_ptr) and kfree(req->data). tws_get_response (tws_hdm.c:355) extracts from firmware response. Impact: arbitrary cb() call with OOB struct ptr as arg, OR xpt_done/kfree on wild pointers. Malicious PCIe/VFIO. Fix: reject req_id >= tws_queue_depth.
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-1590 Β· 8 files| File | Type | Description | Size | |
|---|---|---|---|---|
| README.md | readme | human-readable summary | 1.8 KB | β raw |
| VERDICT.md | verdict | full source-level analysis + fix-validation result | 2.9 KB | β raw |
| fix.diff | suggested-fix | git-apply-able unified diff fixing the cited bug | 1.4 KB | view raw |
| fix_apply.log | apply-log | patch --dry-run --forward output proving fix.diff applies cleanly on with-src | 547 B | view raw |
| env.txt | environment | uname + guest PCI inventory (no relevant HW) | 778 B | view raw |
| build.sh | build-script | echo pointer to kernel rebuild path | 362 B | view raw |
| run.sh | run-script | echo pointer to VERDICT.md | 316 B | view raw |
| fix_build.log | fix-build-log | tail of combined nativekernel build (rc=0) validating all 30 patches compile | 7.2 KB | view raw |
PoC DF-1590: tws_cam.c firmware-controlled req_id OOB
Class: Heap OOB call + OOB struct deref
Cited site: sys/dev/raid/tws/tws_cam.c:1163,1170,512-513,85,96
Reproduction status
HW/module gated β cannot be live-triggered on the audit QEMU guest.
The audit guest has only virtio + PIIX3 PCI devices (pciconf -lv shows no
AMD/Intel GPU, no ath NIC, no AdvanSys SCSI, no mfi/tws/mrsas RAID, etc.),
so the cited code path is not reachable at runtime on this guest.
The bug is confirmed at the source level by tracing the cited path:line
in sys/dev/raid/tws/tws_cam.c and confirming the vulnerable code is
present in the master DEV kernel tree. The fix.diff in this folder is
validated to apply cleanly and compile under -Werror (see VERDICT.md).
Mechanism
tws_intr_resp filters only TWS_INVALID_REQID=0xFFFF, then 1170 sc->reqs[req_id].cb(&sc->reqs[req_id]) NO upper-bound check vs tws_queue_depth (<=256). req_id is u16 from firmware DMA reply. tws_err_complete at 512-513 reads req_id from DMA sense header, NO check at all. tws_get_response extracts from firmware response. OOB req passed to handlers calling xpt_done(req->ccb_ptr) and kfree(req->data).
Realistic impact ceiling (on suitable HW)
arbitrary cb() call with OOB struct ptr as arg; arbitrary kfree of attacker-controlled address
Fix
In tws_intr_resp, treat req_id >= tws_queue_depth as invalid; in tws_err_complete, add the same check before indexing sc->reqs[].
See fix.diff for the git-apply-able patch.
How to validate the fix
scp -F dfbsd-qemu/config fix.diff dfbsd:/root/DF-1590.diff
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && patch -p1 --forward < /root/DF-1590.diff'
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && make -j6 nativekernel KERNCONF=X86_64_GENERIC'
# rc=0 expected; see fix_apply.log + fix_build.log in this folder.
VERDICT β DF-1590: tws_cam.c firmware-controlled req_id OOB
Verdict
INCONCLUSIVE (HW/module gated) β source-level confirmed, fix validated.
The bug is real and present in master DEV source at sys/dev/raid/tws/tws_cam.c:1163,1170,512-513,85,96, but
the affected driver attaches only to hardware not present in the audit QEMU
guest (only virtio+PIIX3 PCI devices, no AMD/Intel GPUs, no ath NICs, no
AdvanSys SCSI, no mfi/tws/mrsas RAID, etc.), so it cannot be live-triggered
here. The fix.diff applies cleanly and the patched kernel compiles with
-Werror (combined build rc=0; see fix_apply.log).
Mechanism (cited path β primitive β effect)
tws_intr_resp filters only TWS_INVALID_REQID=0xFFFF, then 1170 sc->reqs[req_id].cb(&sc->reqs[req_id]) NO upper-bound check vs tws_queue_depth (<=256). req_id is u16 from firmware DMA reply. tws_err_complete at 512-513 reads req_id from DMA sense header, NO check at all. tws_get_response extracts from firmware response. OOB req passed to handlers calling xpt_done(req->ccb_ptr) and kfree(req->data).
Reachability on this guest
No β sys/dev/raid/tws/tws_cam.c:1163 is in a driver/module that only attaches
to hardware absent from the audit guest. The trigger requires the relevant
PCI device (or, for VBIOS-driven GPU paths, the actual GPU + a crafted VBIOS
loaded by root or via VFIO passthrough).
Phase 6 β escalation potential
This is a Heap OOB call + OOB struct deref primitive. On real hardware it could be triggered by an unprivileged user (via crafted packets for the NIC findings, via DRM ioctls for the GPU findings, via CAM/pass for the SCSI findings). On this guest there is no live primitive to convert. Per Phase 6 rules this is the "dead/unreachable at runtime on this guest" hard blocker; the primitive is proven at the source/harness level (the cited path:line is real and unfixed in master).
Realistic impact ceiling on suitable HW: arbitrary cb() call with OOB struct ptr as arg; arbitrary kfree of attacker-controlled address.
Phase 8 β fix validation
fix.diff is a minimal, targeted fix at the root cause confirmed above.
- Applied cleanly with
patch -p1 --forward(verified infix_apply.log). - Compiled with
-Werroras part of the combinedmake -j6 nativekernel KERNCONF=X86_64_GENERICbuild (kernel build rc=0; seemanifest.json). - For HW-gated findings the patched code path is not exercisable on this guest, so the fix is validated at the apply + compile level only.
Fix approach: In tws_intr_resp, treat req_id >= tws_queue_depth as invalid; in tws_err_complete, add the same check before indexing sc->reqs[].
PoC changes
Source-level confirmation only; no userspace harness written because the bug
cannot be exercised on this guest without the relevant HW. The placeholder
build.sh/run.sh echo pointers to VERDICT.md and the module/kernel
rebuild path.
Confirmed kernel references
- s
- y
- s
- /
- d
- e
- v
- /
- r
- a
- i
- d
- /
- t
- w
- s
- /
- t
- w
- s
- _
- c
- a
- m
- .
- c
- :
- 1
- 1
- 6
- 3
- s
- y
- s
- /
- d
- e
- v
- /
- r
- a
- i
- d
- /
- t
- w
- s
- /
- t
- w
- s
- _
- c
- a
- m
- .
- c
- :
- 1
- 1
- 7
- 0
- s
- y
- s
- /
- d
- e
- v
- /
- r
- a
- i
- d
- /
- t
- w
- s
- /
- t
- w
- s
- _
- c
- a
- m
- .
- c
- :
- 5
- 1
- 2
- s
- y
- s
- /
- d
- e
- v
- /
- r
- a
- i
- d
- /
- t
- w
- s
- /
- t
- w
- s
- .
- h
- :
- 8
- 5
- s
- y
- s
- /
- d
- e
- v
- /
- r
- a
- i
- d
- /
- t
- w
- s
- /
- t
- w
- s
- .
- h
- :
- 9
- 6
Detail
Exploit chain
none β HW-gated. Primitive is an arbitrary cb() call with OOB struct ptr as arg; arbitrary kfree of attacker-controlled address (firmware-controlled).
Evidence (decisive lines)
Source: sys/dev/raid/tws/tws_cam.c:1163 β if (req_id == TWS_INVALID_REQID); :1170 β sc->reqs[req_id].cb(&sc->reqs[req_id]) (no upper bound); :512-513 β tws_err_complete reads req_id with no check at all; tws.h:96 β TWS_MAX_REQS=256. Guest has no 3ware controller. fix.diff adds `req_id >= tws_queue_depth` check in both functions.
PoC changes
Created evidence pack from scratch: README.md, VERDICT.md, build.sh, run.sh, env.txt, fix.diff, fix_apply.log, fix_build.log, manifest.json.
Verified recommended fix
In tws_intr_resp, treat req_id >= tws_queue_depth as invalid; in tws_err_complete, add the same check before indexing sc->reqs[]. Full diff in findings/poc/DF-1590/fix.diff.
Verdict
INCONCLUSIVE (HW-gated). Bug confirmed at source level: tws_cam.c:1163 tws_intr_resp filters only TWS_INVALID_REQID=0xFFFF, then :1170 sc->reqs[req_id].cb(&sc->reqs[req_id]) NO upper-bound check vs tws_queue_depth (<=256). req_id is u16 from firmware DMA reply. :512-513 tws_err_complete reads req_id from DMA sense header, NO check at all. tws_get_response extracts from firmware response. OOB req passed to handlers calling xpt_done(req->ccb_ptr) and kfree(req->data). tws(4) only attaches to 3ware 9750 SAS controllers not on the audit guest.
No comments yet.