Shaders: LDS accesses past the program's allocation are not bounds-checked (patch + test, run on AMD) #1870
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#1870
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wwwwwwww3333333 on GitHub · 2026-11-24 23:55 UTC · original
lower.rs(main70564ae0) has this shortcut in the DS lowering:On the host, an out-of-bounds index into the group-shared array is undefined behavior. On my card it isn't harmless: the write goes through and can be read back.
What I measured, with a new semantics test on main's lowering. Each thread writes its own dword, then writes
b512 bytes past it. The probe's LDS is 512 bytes, so that write is out of bounds. Reading the out-of-bounds dword back:bon 306 of 340 inputs. The out-of-bounds write was kept.So the hardware adapter and WARP disagree, and neither is guaranteed.
Patch: each LDS dword access now carries "inside the program's LDS".
This covers dword reads and writes, read2/write2, byte/half reads and writes, and atomics. The address stays
addr + offsetwrapping at 32 bits. That matches LLVM, which on GFX7 and later folds a negative base plus an offset into one DS instruction (isDSOffsetLegal; only Southern Islands needs the sign bit clear). A comment now says so.Results on
70564ae0, RX 6750 XT, Windows 11, Rust 1.98.1 MSVC. The new testlds_out_of_bounds_reads_zero_and_drops_writeshas three probes:ds_read_i8at +600.ds_write_b8at +513,ds_read2_b32with offset1 800 bytes,ds_add_rtn_u32at +512, then a read through a base of own - 16 with offset 16 (32-bit wrap back inside).Probes 2 and 3 already pass on main on this card; they pin the behavior. After the patch all three pass on hardware and WARP.
Other results:
lds_bytes_and_halves_match_the_hardwarestill passes.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.Left as is: the alignment part of the shortcut (a b32 access at an address that isn't a multiple of 4). On RDNA2 that depends on whether unaligned mode is set, and I found nothing saying which mode the console runs in, so I didn't guess.
Patch against
70564ae0Unit tests only, no game files. AI-assisted (Claude wrote the patch; I ran it on my machine).
@wwwwwwww3333333 on GitHub · 2026-11-25 01:00 UTC · original
Update: main has moved to
42363ab6, and the patch above still applies cleanly there (no changes needed). Re-run on that main, same card (RX 6750 XT, Windows 11, Rust 1.98.1 MSVC):lds_out_of_bounds_reads_zero_and_drops_writes: passes.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.@jules47800 on GitHub · 2026-11-25 01:25 UTC · original
Same fix as PR #1769 (opened earlier, mergeable). I ran your test on it. On RX 6600 XT + WARP it passes on #1769's head and on #1769 merged into main
42363ab. On main alone it fails with the same 306/340 you measured on the RX 6750 XT. Details are on #1769. Once #1769 lands this issue can close, ideally with your test added there.@YaBulochka on GitHub · 2026-11-25 05:02 UTC · original
RADV/RDNA3 data point: the out-of-bounds LDS write is kept here on every workgroup, so the clamp in this patch is needed on Linux too.
Setup. Linux, Vulkan 1.4, RADV, Radeon RX 7600 (NAVI33, gfx1102). Minimal compute test:
shared uint smem[128](512 B, the program's allocation), 64 lanes per workgroup. Each lane writes its own dword,barrier(), then writesbatsmem[128 + lane](512..764 B, past the allocation),barrier(), and reads it back into an SSBO. 340 workgroups, each with its ownb(0xDEAD0000 + wg).Result:
So on this host the out-of-bounds store lands and is read back, the same shape as the RX 6750 XT measurement (306/340), and not the WARP answer (0). Every one of the 340 kept it here, so it is not a flaky race in this run.
Compared with the report: same outcome as RDNA2 under the Windows driver, i.e. the "reads 0, drops writes" console shortcut is wrong on a second AMD platform, and the per-access "inside the program's LDS" guard this patch adds is what makes it defined.
Caveat, in fairness: this is a raw SPIR-V
sharedarray with a dynamic index, not the exact lowering inlower.rs; a driver is free to change this, and none of it is guaranteed by the spec. But it is what the hardware does today, and the patch removes the dependence on it.Harness is a ~150-line Vulkan compute program plus a 16-line GLSL shader; no title run. I can rerun it on the iGPU or on
R16_SNORM-style variants if useful.@Marvisak on GitHub · 2026-11-25 12:50 UTC · original
Automated triage for the maintainers.
Confirmed in
main(940d32f): the DS lowering incrates/victory-shader/src/emit/lower.rs(thedwordhelper of the LDS path) still takes LDS addresses as in bounds and indexes the group-shared array with no check, so an out-of-bounds console access is undefined behaviour on the host. The measurements agree: RX 6750 XT (306/340 kept), RX 6600 XT and RADV on an RX 7600 (340/340) keep the out-of-bounds write, while WARP reads 0.The patch in the body is carried by open PRs: #1949 (this issue's change) and #1769 (opened earlier, same fix; your test passes on it). Please settle on one of them and add the
lds_out_of_bounds_reads_zero_and_drops_writestest to it.Generated by Claude Code