# DF-1340 — u32 integer overflow in CB/DB size validation bypasses the BO bounds check

**File:** `sys/dev/drm/radeon/r600_cs.c:429-443 (CB) and 620-623 (DB)`
**Class:** integer overflow -> cross-process GPU memory corruption

## Status: INCONCLUSIVE at runtime — confirmed real source bug, hardware-gated on this guest

The vulnerable code path was traced line-by-line in `sys/` and **confirmed to be a genuine bug**
(missing bounds check / integer overflow / UAF race). However it is **not exercisable on the
DragonFly audit guest** because the guest has neither an AMD GPU nor any audio controller:

- PCI shows only `vgapci0 class=0x030000` (QEMU stdvga, chip `0x11111234`) — no AMD GPU.
- No PCI audio device (class `0x0401`/`0x0403`); `hw.snd` empty; no `/dev/dsp`.
- `radeon.ko` is a loadable module only (NOT in `X86_64_GENERIC`), is not loaded, and cannot be
  `kldload`'d by an unprivileged user — and even if loaded would not attach without the hardware.

This is the valid hard-blocker case "vulnerable code path unreachable at runtime on this guest AND no
harness can exercise it (device-integrated parser / ioctl / hardware-dependent race)." The bug is a
real latent defect that **would** manifest on a system with the relevant hardware + the module loaded.

## Mechanism (confirmed by source trace)
In r600_cs_track_validate_cb(), `tmp` is declared u32 (:353) and computed as nblocksy*nblocksx*blocksize*nsamples (:430). With maximal attacker-chosen surface geometry (8192*8192*8*16 = 2^33) the u32 product wraps to a tiny value, so the check `(tmp + cb_color_bo_offset[i]) > radeon_bo_size(...)` (:443) passes for an undersized BO; the GPU then writes colour-buffer data past the BO into adjacent GTT/VRAM (another process's BO). The tiled branch (:440) multiplies tmp by the slice count, compounding the overflow. r600_cs_track_validate_db() has the identical flaw at :622 (ntiles*bpe*64*nviews*nsamples, also u32 via :520). Both reached from the DRM_AUTH command-submission path.

## Live trigger conditions
Requires an AMD Radeon R600-family GPU with the radeon driver attached and a DRM_AUTH client issuing a crafted CS. The QEMU audit guest has only a QEMU stdvga (0x11111234) — no AMD GPU, no /dev/dri, radeon.ko not loaded — so r600_cs_track_validate_cb/db are unreachable here.

## Fix
A standalone, `git apply`-able fix is in `fix.diff`. **Compile-validated**: applied to in-guest
`/usr/src` and the `radeon` module rebuilt under `-Werror` (rc=0, no warnings/errors in the
patched translation unit). See `build_fix.log`.

Compute the CB size in a new u64 `tmp64` (cast the first operand to u64) and use tmp64 in the bounds comparison and dev_warn; split the DB `tmp` decl to u64 and cast the first operand. This removes the u32 overflow so the bounds check is sound. Supersedes the finding proposal (which only said 'compute in u64').

## Reproduce / validate
```
# 1. Confirm the bug site exists (read-only source trace):
grep -n ... sys/dev/drm/radeon/r600_cs.c

# 2. Validate the fix compiles (on the audit guest):
scp -F dfbsd-qemu/config findings/poc/DF-1340/fix.diff dfbsd:/root/fix.diff
./dfbsd-qemu/vm.sh run_root 'cd /usr/src && patch -p1 --forward < /root/fix.diff'
./dfbsd-qemu/vm.sh run_root 'cd /usr/src/sys/dev/drm/radeon && KERNCONF=X86_64_GENERIC SYSDIR=/usr/src/sys make -m /usr/src/share/mk'

# 3. (requires real hardware) Exercise the bug: attach an AMD GPU / audio device and trigger.
```
