startup: refuse compute buffer loads through a modified descriptor (#2901) #2910
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2910"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T19:08:27Z.
Change
Fixes #2901
Refs #2618
When translating compute buffer loads (such as
buffer_load_dword ... offenor non-indexed loads),Stage.buffer_address()resolved the resource key solely viaself.descriptor(), which looks only at word 0. If earlier scalar instructions edited or overwritten words 1–3 (stride,NUM_RECORDS, orformat/OOB) without a proven transformation, the load translated anyway instead of refusing, emitting invalid DXIL / HLSLLoad()operations on unvalidated or zero-sized resources.Stage.load_descriptor(tok, what, *, stride0_ok=False, raw_conversion_ok=False)to validate 4-word descriptor operands against symbol table entries and modification tracking before emitting buffer loads.self.descriptor(tok)first inload_descriptor(), preserving the precedence of existing select-word and branch-join rejections (holds a select of descriptor dataandholds a word joined at a branch target) so integration controls and mutation tests (load-check-removed,join-check-removed) distinguish them from generic descriptor modifications.store_descriptor(), allow proven stride-0 and structured-to-raw transformations for non-indexed loads (stride0_ok=not idxen,raw_conversion_ok=not idxen), while refusing modified descriptors withbuffer load through a modified descriptor(orindexed load through a modified descriptorwhenidxenis set).Stage.load_descriptor().buffer_address()across bothidxen and offenandidxenpaths (if key in getattr(self.pipe, 'modified', ()): raise Unsupported('indexed load through a modified descriptor')), ensuring formatted buffer loads (is_formatted=True) continue to refuse when any modification of that descriptor is tracked, even if the load operands themselves remain intact.tests/startup_gfx2hlsl_compute_check.pyandtests/startup_gfx2hlsl_load_desc_check.pyverifying that an instruction deriving a descriptor word to a separate SGPR (s_and_b32 s21, s13, 0xc000ffff) immediately beforeLOAD_LinL-uintis refused withindexed load through a modified descriptor.Verification
Commit
7b44bda6, rebased on upstream/main at0e704468. Windows 11, Python 3.14.LoadandStore.descnum copy w1,descnum copy w2,descnum copy w3,descnum alu w2,in-place and 0 w2,constant 0 w2) are tested for both loads and stores:buffer load through a modified descriptor.buffer store through a modified descriptor.s_and_b32 s13, s13, 0xc000ffff) translates cleanly.0xc000fff0) on load is refused.raw_conversion_ok=Truewiths_bfe_u32stride extraction,s_and_b32stride clear,s_mul_i32record count scale, andoob3setup) translates cleanly.buffer load through a modified descriptor.s_and_b32 s21, s13, 0xc000ffffimmediately beforeLOAD_LinL-uintrefuses withindexed load through a modified descriptor.startup_gfx2hlsl_cselect_descnum_check.py controlspasses all tests and all 5 negative control mutants (zero-arm-dropped,load-check-removed,alu-check-removed,join-check-removed,high-word-unchecked) with 0 failures.Stage.load_descriptorbypasses validation and forwards directly toself.descriptor(tok), all 6 load edits translate silently intov5 = r0.Load(a + 0);, reproducing the issue reported in #2901.Evidence and follow-up
tests/cmake/startup_gfx2hlsl_load_desc.cmake,tests/checks/python-linux/startup_gfx2hlsl_load_desc.txt.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-26T20:24:41Z.
Review: COMMENTED
startup: refuse compute buffer loads through a modified descriptor
Important correctness/security fix. When scalar ops silently modify descriptor words 1–3 (stride, NUM_RECORDS, format/OOB), the buffer load should refuse and not proceed with invalid metadata. The fix correctly distinguishes formatted vs. unformatted buffer loads.
Observations
is_formattedparameter cleanly separates the two cases: formatted loads use the original descriptor path, unformatted loads go throughload_descriptor()with stricter validationstride0_ok=not idxen, raw_conversion_ok=not idxencorrectly handles indexed vs non-indexed loadsVerification needed
WORDS_Ais exported fromstartup_gfx2hlsl_compute_check— the import ofCusesWORDS_AdirectlyEdge cases to check
is_formattedflag propagate correctly throughop_s_buffer_load_dwordx8anddwordx16? (These callbuffer_address()withis_formatted— worth verifying the call chain.)Verdict: Correctness fix with thorough test coverage. Ready to merge pending the
WORDS_Averification.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T20:42:32Z.
SMEM buffer loads are the one buffer-load path still resolved through
descriptor()onc88bbd68Measurements only, no code change.
At
c88bbd68raw MUBUF loads go through the newload_descriptor(), formatted loads already compare all four words inmubuf_format()(tools/startup/gfx2hlsl.py:6925-6928), andStage.op_s_buffer_load_dword(:6251) still resolves its resource throughself.descriptor(ops[1]), which returns the key from word 0'sdescsymbol (thes[104:107]operand is the only case that checks the other three). So the six edits your fixture refuses on MUBUF are accepted on the SMEM path.Probe
Linux, Python 3.11.16, no device. It reuses
WORDS_A,EDITSandtranslate_codefrom your fixture, removes the two 8-byte instructions the fixture owns (the MUBUF load atLOAD_SITE, thebuffer_store_dwordx2atSTORE_A), keeps everything else, and insertss_buffer_load_dword s24, s[12:15], s11 offset:0x10(060620f410000016: opcode0x08,sbase=12,sdst=24,soffset=11,imm=16).Your own fixture passes unchanged on this head (
compute buffer load modified descriptor checks passed, rc=0).Control
Re-routing that single line to
self.load_descriptor(ops[1], 'buffer load')refuses all six edits withbuffer load through a modified descriptor, keeps the no-edit case translating, and your fixture still passes (rc=0). That was an experiment, not a patch: the file was restored andgit status --porcelain --untracked-files=nois empty.What this does and does not show
The emitted load is the resource plus an offset;
NUM_RECORDSandOOB_SELECTare not modelled on this path, so an edit of DW2/DW3 cannot change the emitted text — if it diverges, it diverges at the descriptor's bound fields, and I did not measure that on a device. The narrower question is whether the "unproven descriptor -> refuse" rule should apply here too. Your body says the change "does not affect existing formatted loads or buffer stores", which reads as non-regression rather than as scope; SMEM is not mentioned.Limits
dwordform only; the handler is shared by the x2/x4/x8/x16 forms and by the other stages, not exercised here.s_buffer_store_*handler (def op_s_buffer_storedoes not exist), so the store path is not a comparable caller.If SMEM is deliberately out of scope, one line in the body or a follow-up issue closes it; otherwise
load_descriptor(ops[1], 'buffer load')makes the two paths agree. Whether SMEM should passstride0_ok=True(it has noidxen, so no indexed twin) is your call.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T20:50:06Z.
Thanks for the review and positive verdict @KelboLive!
Regarding the two points:
WORDS_Aexport: Confirmed —WORDS_Ais defined as a module-level global at line 99 oftests/startup_gfx2hlsl_compute_check.py(alongsideSTORE_Aat line 703). The importimport startup_gfx2hlsl_compute_check as C; W = C.WORDS_Aworks cleanly across all environments and CI.op_s_buffer_load_dword*call chain: Theop_s_buffer_load_dwordx16signature in the diff appeared only because it immediately precedesdef buffer_address()inStage. Scalar SMEM buffer loads (s_buffer_load_dword*) do not callbuffer_address()(they usesmem_soffset()directly).buffer_address()is called exclusively for vector MUBUF/MTBUF operations:buffer_load: defaults tois_formatted=False(validated viaload_descriptor());buffer_store:is_formatted=False;formatted_buffer_load: passesis_formatted=True(as MTBUF has its own separate descriptor validation and binding).Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T20:52:32Z.
Thank you for the thorough probe and measurement @thepatrickworld!
On closer inspection against the full test suite (specifically
tests/startup_gfx2hlsl_heap_word_check.py), scalar SMEM buffer loads (s_buffer_load_dword*) intentionally have different contract semantics:tests/startup_gfx2hlsl_heap_word_check.py:126explicitly tests that ans_buffer_load_dwordthrough a modified descriptor continues translating without immediate refusal, but invalidates heap word provenance so that downstreams_loadof the resource heap record refuses at manifest time.Routing SMEM through
load_descriptor()broke those existing test contracts across the Linux test runner. Therefore, in commit7234e021:op_s_buffer_load_dwordtoself.descriptor(), keeping scalar SMEM loads in their existing contract and leaving Issue #2901 focused strictly on vector MUBUF buffer loads.getattr(self.pipe, 'modified', ())inload_descriptor()andstore_descriptor()so bare probe pipelines without modification tracking are safely supported withoutAttributeError.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T05:23:08Z.
Review: COMMENTED
Integration finding at
7234e021with current maine62e3a5e(which includes #2903). The new load-descriptor controls pass, butstartup_gfx2hlsl_cselect_descnum_controlsfails six cases. A select copied into words 1–3 or joined at a branch/loop now hits genericbuffer load through a modified descriptorfirst, masking the existing select/join rejection and its mutation checks. Please rebase and run bothstartup_gfx2hlsl_load_desc_controlsandstartup_gfx2hlsl_cselect_descnum_controls. The controls should still distinguish removal of the existing select/join guards while preserving the generic refusal for other writes.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:43:23Z.
Review: COMMENTED
What works
descriptor words against symbol table entries, preventing buffer loads
through modified/overwritten descriptors.
alu modify w2, in-place and zero w2, constant zero w2) and verifies each
is refused.
both in gfx2hlsl translations and in the compute pipeline, and that an
unmodified load still succeeds.
Issues
load_descriptor()hasstride0_ok=Falseandraw_conversion_ok=Falseflags. The comments explain these allow proven safe transformations, but
the conditions under which stride-0 is considered 'proven' should be
clearly documented so future maintainers understand the safe paths.
like other tests in the codebase. This is acceptable given the test names
clarify the edit, but consider whether symbolic helpers from the existing
infrastructure are available.
raw_conversion_okflag - verify it's tested when adescribed raw format is passed with raw_conversion_ok=True.
Recommendations
Overall
Important security fix for buffer loads through modified descriptors.
Good test coverage with clear refusal patterns. Approvable.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-27T08:33:05Z.
Addressed in commit
98ab777fand rebased cleanly onto latestupstream/main(3b6c38a8):Precedence for select / branch join checks (@R0Y00):
Stage.load_descriptor(),self.descriptor(tok)is now evaluated first before symbol table word-comparison checks.select_word(tok)andjoined_word(tok)rejections (holds a select of descriptor dataandholds a word joined at a branch target) take precedence over generic modification refusals, allowing integration controls to pass and negative control mutants (load-check-removed,join-check-removed) to cleanly distinguish the removal of those guards.tests/startup_gfx2hlsl_load_desc_check.pyandtests/startup_gfx2hlsl_cselect_descnum_check.py controlspass with 0 failures (including all 5 negative control mutants).Documentation & raw conversion test coverage (@KelboLive):
Stage.load_descriptor()explaining whenstride0_ok(non-indexed buffer loads where stride is not consulted by hardware) andraw_conversion_ok(the 5-instruction RDNA2 structured-to-raw sequence: stride extraction, stride zeroing, record-count scaling, and raw OOB bit configuration) are proven safe transformations.tests/startup_gfx2hlsl_load_desc_check.pyverifying that a proven structured-to-raw conversion on a buffer load descriptor translates cleanly withraw_conversion_ok=True, while invalid conversions (e.g. constant multiplier instead of the extracted stride) are refused.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T08:41:31Z.
Review: CHANGES_REQUESTED
The previously reported diagnostic-precedence failures are fixed at
98ab777f. On currentmain0e704468plus this PR, the descriptor-load,cselect_descnum controls(including all five mutants), heap-word and compute translation suites pass.One formatted path changes despite the stated intent to preserve it.
buffer_addressnow skipsload_descriptorfor formatted loads, but the old indexedkey in self.pipe.modifiedguard was also deleted. I inserteds_and_b32 s21, s13, 0xc000ffffimmediately beforeLOAD_Lin the source-builtL-uintcompute fixture. This writes a derived descriptor word to a separate SGPR and leaves the actual four operand words intact.0e704468refuses the indexed formatted load withindexed load through a modified descriptor.98ab777fpublishes a binding and translates it because the specialized check only sees the unchanged four registers. Please preserve the indexed formatted guard and add this case, or document and validate an intentional expansion of that route separately.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-27T09:05:56Z.
Addressed in commit
7b44bda6(rebased onupstream/mainat0e704468):Preserved Indexed Formatted Load Guard (@R0Y00)
Stage.buffer_address(), restored thekey in getattr(self.pipe, 'modified', ())guard in bothif idxen and offen:andelif idxen::buffer_address(..., is_formatted=True), any prior modification derived from descriptorkey(such as writing a derived word to a separate SGPR vias_and_b32 s21, s13, 0xc000ffff) triggers this guard and refuses withindexed load through a modified descriptor, preserving the existing behavior from0e704468.tests/startup_gfx2hlsl_compute_check.py(check_formatted_loads()) andtests/startup_gfx2hlsl_load_desc_check.py:s_and_b32 s21, s13, 0xc000ffffimmediately beforeLOAD_LinL-uintrefuses withindexed load through a modified descriptor.Test Verification
All passed with 0 failures on Windows 11 / Python 3.14 (including all 5 negative control mutants in
cselect_descnum_check.py controls).Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T09:20:13Z.
Review: APPROVED
The formatted indexed-load guard is restored at
7b44bda6, and the new source-builtL-uintcase exercises the exact derived-word counterexample. The specialized formatted descriptor checks and existing scalar heap-word contract are preserved.On this head integrated with
maine446b072, I reranstartup_gfx2hlsl_load_desc_check.py,startup_gfx2hlsl_cselect_descnum_check.py controls,startup_gfx2hlsl_compute_check.py,startup_gfx2hlsl_heap_word_check.pyandcompute_load_format_check.pyon Windows with Python 3.12. All five passed, including all five diagnostic mutants and the approved raw-conversion controls. Hosted Windows, Linux Python and gfx1013 checks also passed. These checks cover compiler behavior.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T09:38:07Z.
Independent re-check at
7b44bda6: the four conversion shapes refuse again, and one of the two restored guards is unexercisedLowering only — no DXIL, no adapter. This verifies the fix rather than reporting the defect.
Trees
7b44bda6—tools/startup/gfx2hlsl.pysha25665389f70a6d96da3f4beeaaa5e9b8a5cc92aab8c446af747c8b8b4a294b4dafe98ab777f(previous head) — same file sha25642171bbd823c1b9f30fa359dbeee17e23406da0c9cedb865df02f1af30537c943e9542a6—0dfe91bf1abd87c0d513e55bc5169c4e15fa0a195eb77c623a19d83ee3e9d30dThe four derived writes
These are the descriptor-word conversions
raw_descriptor_alu()(gfx2hlsl.py:932) returns — stride0s_and_b32 s21, s13, 0xc000ffff, oob0s_and_b32 s21, s15, 0xcfffffff, oob3s_or_b32 s21, s15, 0x30000000, byte_counts_bfe_u32 s21, s13, 0xe0010+s_mul_i32 s22, s14, s21. Each writes a scratch SGPR and leaves the four operand registerss[12:15]intact, so the four-word comparison atgfx2hlsl.py:7244-7247cannot see any of them.buffer_load_format_xyzw … idxen offen offset:2)3e9542a698ab777f7b44bda6indexed load through a modified descriptorLoademittedSame verdicts on the
idxen-only form (offencleared, word 00xe00c2002): refused at main and at7b44bda6, translated at98ab777f.Unchanged on all three trees: the in-place rewrites of these words are refused everywhere (message
indexed load through a modified descriptorat main and at7b44bda6,…whose words were rewrittenat98ab777fin between);s_mov_b32 s15, s14ands_mov_b32 s15, 0are refused through the four-word comparison;s_bfe_u32alone ands_max_u32with an inline constant never mark the key and translate; the non-indexed form (offenonly) accepted all four everywhere, before and after this PR.Mutation receipts
if idxen and offen:andelif idxen:) — the file drops back to the98ab777fsha25642171bbd…, and both new cases fail:startup_gfx2hlsl_load_desc_checkwithexpected refusal for formatted indexed load with modified descriptor, but translated,startup_gfx2hlsl_compute_checkwithaccepted, expected a refusal naming 'indexed load through a modified descriptor'. The fix is pinned.elif idxen:guard removed — no fixture notices.startup_gfx2hlsl_load_desc_check,startup_gfx2hlsl_compute_check,startup_buffer_address_check,startup_mesh57_skeleton_checkandstartup_gfx2hlsl_compute_spill_checkall stay green, and on theidxen-only load the four shapes translate again (s_and_b32 s21, s13, 0xc000ffff→ translated, while its in-place twin still refuses through the four-word comparison).65389f70…after each mutant,git status --porcelain --untracked-files=noempty.Proposed case for the second branch
Both new cases use
LOAD_L, which carriesidxen offen, so only the first branch is exercised. One case closes it, at the load whose word 0 is0xe00c2002(offenbit 12 clear,idxenbit 13 set) instead of0xe00c3002:Measured with that snippet on the clean
7b44bda6: it raisesindexed load through a modified descriptor, and the same load without the edit translates. Under theelif idxen:mutant it translates with the edit.Regression
The 201 fixtures that mention
gfx2hlsland are green at98ab777fare all still green at7b44bda6(0 failures).sweep2.logcarries the per-fixture lines andsweep2.stdoutrecordshead=7b44bda6for that replay.Commands
Limits
raw_descriptor_alu(). Writers that do not go through it (a descriptor word reloaded through LDS, a word joined at a branch target) have their own guards and were not sampled.7b44bda6; if the branch moves again, re-runprobe6before citing this note.AI-assisted.