# PoC DF-1561: amd_powerplay num_ps stack OOB

**Class:** Stack buffer overflow
**Cited site:** `sys/dev/drm/amd/powerplay/amd_powerplay.c:619-640, amdgpu_pm.c:332`

## 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/drm/amd/powerplay/amd_powerplay.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

Loop i=0..hwmgr->num_ps-1 writes data->states[i]. struct pp_states_info states[16] fixed. hwmgr->num_ps from VBIOS ucNumEntries u8 (max 255) via processpptables.c:874-880. No clamp. num_ps>16 -> states[16..254] past end of caller amdgpu_pm.c:332 stack struct.

## Realistic impact ceiling (on suitable HW)

stack buffer overflow (up to 239*4 bytes) -> stack smashing / ROP

## Fix

Clamp hwmgr->num_ps to 16 (the states[] array size) at the top of pp_cb_get_state_pool.

See `fix.diff` for the git-apply-able patch.

## How to validate the fix

```sh
scp -F dfbsd-qemu/config fix.diff dfbsd:/root/DF-1561.diff
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && patch -p1 --forward < /root/DF-1561.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.
```
