Direct DXIL: 32-bit unsigned wraparound in raw-buffer bounds checks bypasses OOB clamping into adjacent UMA windows #1893
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#1893
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?
@microwave805 on GitHub · 2026-11-24 22:37 UTC · original
Static audit on
main @ 689f2dbfound 32-bit unsigned integer wraparound in Direct DXIL's raw-buffer bounds checks (s_buffer_load_*,mubuf, andbuffer_atomic_*), which lets out-of-bounds accesses pass the check and — combined with 64-bitbuffer_window()address arithmetic — hit adjacent 4 GiB UMA windows instead of returning0/ dropping writes.Where
crates/xcl/src/gpu/dxil/lower_mem.rs:1054-1082(smem/s_buffer_load_*)crates/xcl/src/gpu/dxil/lower_mem.rs:1156-1170(mubufraw-bufferin_range)crates/xcl/src/gpu/dxil/lower_mem.rs:1699-1710(buffer_atomic)Root cause
mubuf(lower_mem.rs:1156-1169) andbuffer_atomic(lower_mem.rs:1699-1710):Both
off = voff + OFFSETande = off + byteswrap modulo2^{32}.stride == 0,d2 = 0x100,voff = 0xFFFF_FFFC,OFFSET = 0,bytes = 4:off = 0xFFFF_FFFCe = off.wrapping_add(4) = 0 <= d2→ok == true!voff = 0xFFFF_FFF0,OFFSET = 0x20,bytes = 4:off = 0x10,e = 0x14 <= d2→ok == true!buffer_window(d0, d1, &[Ea::U(soff), Ea::U(voff), Ea::K(OFFSET), ...], ...)adds the components in 64-bit unsigned arithmetic, carrying+1into the upper 32 bits and selecting the next 4 GiB UMA window, so an OOB buffer store or atomic writes into an adjacent UMA window instead of being masked off!mubufalso does not checkoff + soffwhensoffis used (RDNA2 hardware OOB compares the unsigned byte offsetvoff + OFFSET + soffagainstnum_recordswhenstride == 0;soffis omitted fromin_rangehere too).s_buffer_load_*(lower_mem.rs:1054-1082):off = imm + soffando = off + 4 * iboth wrap in 32 bits beforecmp(Pred::ULt, o, lim)(whilebuffer_windowcomputes the window in 64 bits).st != 0,lim = d2 * stalso wraps in 32 bits ifd2 * st >= 2^32.Fix direction
Compute raw-buffer offset checks without 32-bit wraparound — e.g. check overflow/carry on
voff + OFFSET(andsoffwhere applicable) andoff <= d2 && d2 - off >= bytes(or compare ini64/u64when already widened, or carry-check ini32to avoid requiringInt64Opsneedlessly:sum >= afor additions andoff < d2 && bytes <= d2 - off). Add unit/GPU tests withvoff = 0xFFFF_FFFCandvoff = 0xFFFF_FFF0, OFFSET = 0x20verifying OOB reads return0and OOB stores/atomics are dropped.AI use
main @ 689f2dband issue drafting.@LucasHoepfner on GitHub · 2026-11-24 23:53 UTC · original
Confirmed on a GPU with two memory windows, where the wrapped access lands 4 GiB above the buffer. The HLSL path gets every case right, so this is a difference between the two translators. #1933 fixes the MUBUF and atomic cases here; the
s_buffer_loadcase it leaves out is one line (below).What happens on
main20cf130. One kernel-mode program, a raw V# (stride 0) of 0x100 bytes at window 0 + 0x1000, markers at the same low addresses in window 1:buffer_load_dword, voff0xFFFF_FFFCbuffer_load_dword, voff0xFFFF_FFF0, OFFSET 0x20buffer_store_dword, voff0xFFFF_FFF0, OFFSET 0x40buffer_atomic_add(GLC), voff0xFFFF_FFF0, OFFSET 0x60s_buffer_load_dword, OFFSET 0x20, soff0xFFFF_FFF0The same with the windows as a switch and from the heap. The range check passes on the wrapped 32-bit offset, the low address wraps, and
buffer_windowtakes the window from the 64-bit sum. The HLSL path has the MUBUF offset and its end in 64 bits with several windows (emit.rs:1706,1724, since #792).#1933 (@PracticalStudios, head
bb5e0b7): with itslower_mem.rson20cf130, the first four rows come out as on the HLSL path, in both window forms. Its own test runs with one window, so this adds the two-window case.What is left:
s_buffer_load. The HLSL path uses the 32-bitOFFSET + sofffor the check, the address and the window (emit.rs:1498–1504). The direct path takes the window from the two added in 64 bits, so a sum that wraps reads the right low address in the next window. This makes it agree:I have it with a GPU test (
s_buffer_load_dwordanddwordx4through both translators and both window forms; fails onmainfor the direct path, passes with the line). @PracticalStudios, take the line into #1933 if you like, so one smoke pair covers the issue, and I'll send you the test. Otherwise I'll open it as its own small PR; I have no retail title, so it would need someone's smoke run.Not confirmed, and left alone
soffis not part of the MUBUF check;num_records * stridecan wrap): the HLSL path does the same, and I don't know what the console does there.Tested
AI use: Claude Code (Claude Fable 5.2) ran the experiments and wrote the fix, the test and this comment.