Repository navigation
startup: refuse compute buffer loads through a modified descriptor (#2901) - #2910
Conversation
KelboLive
left a comment
There was a problem hiding this comment.
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
- ✅ New
is_formattedparameter cleanly separates the two cases: formatted loads use the original descriptor path, unformatted loads go throughload_descriptor()with stricter validation - ✅
stride0_ok=not idxen, raw_conversion_ok=not idxencorrectly handles indexed vs non-indexed loads - ✅ The test covers 7 descriptor manipulation scenarios — copy to w1/w2/w3, ALU on w2, in-place AND, constant overwrite
- ✅ Test construction is careful: registers are mapped correctly, SOP2/SOP1 encoding matches gfx2hlsl conventions
- ✅ cmake + python-linux CI check files added properly
Verification needed
- Please verify that
WORDS_Ais exported fromstartup_gfx2hlsl_compute_check— the import ofCusesWORDS_Adirectly
Edge cases to check
- Does the
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_A verification.
|
SMEM buffer loads are the one buffer-load path still resolved through Measurements only, no code change. At ProbeLinux, Python 3.11.16, no device. It reuses Your own fixture passes unchanged on this head ( ControlRe-routing that single line to What this does and does not showThe emitted load is the resource plus an offset; Limits
If SMEM is deliberately out of scope, one line in the body or a follow-up issue closes it; otherwise AI-assisted. |
|
Thanks for the review and positive verdict @KelboLive! Regarding the two points:
|
|
Thank you for the thorough probe and measurement @thepatrickworld! On closer inspection against the full test suite (specifically Routing SMEM through
|
R0Y00
left a comment
There was a problem hiding this comment.
Integration finding at 7234e021 with current main e62e3a5e (which includes #2903). The new load-descriptor controls pass, but startup_gfx2hlsl_cselect_descnum_controls fails six cases. A select copied into words 1–3 or joined at a branch/loop now hits generic buffer load through a modified descriptor first, masking the existing select/join rejection and its mutation checks. Please rebase and run both startup_gfx2hlsl_load_desc_controls and startup_gfx2hlsl_cselect_descnum_controls. The controls should still distinguish removal of the existing select/join guards while preserving the generic refusal for other writes.
KelboLive
left a comment
There was a problem hiding this comment.
What works
- Solid defense-in-depth: the new Stage.load_descriptor() validates all 4
descriptor words against symbol table entries, preventing buffer loads
through modified/overwritten descriptors. - The test fixture correctly exercises 6 edit modes (copy to w1/w2/w3,
alu modify w2, in-place and zero w2, constant zero w2) and verifies each
is refused. - The load tests are well-structured - they verify the refusal happens
both in gfx2hlsl translations and in the compute pipeline, and that an
unmodified load still succeeds.
Issues
load_descriptor()hasstride0_ok=Falseandraw_conversion_ok=False
flags. 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.- The tests use hardcoded opcodes (sop2/sop1) rather than symbolic names
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. - No test for the
raw_conversion_okflag - verify it's tested when a
described raw format is passed with raw_conversion_ok=True.
Recommendations
- Add documentation on when stride-0 and raw conversions are 'proven'.
- Consider adding a test case for the raw_conversion_ok=True path.
Overall
Important security fix for buffer loads through modified descriptors.
Good test coverage with clear refusal patterns. Approvable.
7234e02 to
98ab777
Compare
|
Addressed in commit 98ab777 and rebased cleanly onto latest
|
R0Y00
left a comment
There was a problem hiding this comment.
The previously reported diagnostic-precedence failures are fixed at 98ab777f. On current main 0e704468 plus 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_address now skips load_descriptor for formatted loads, but the old indexed key in self.pipe.modified guard was also deleted. I inserted s_and_b32 s21, s13, 0xc000ffff immediately before LOAD_L in the source-built L-uint compute fixture. This writes a derived descriptor word to a separate SGPR and leaves the actual four operand words intact. 0e704468 refuses the indexed formatted load with indexed load through a modified descriptor. 98ab777f publishes 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.
…0Y00#2901) Fixes R0Y00#2901 Refs R0Y00#2618 When translating compute buffer loads (such as buffer_load_dword ... offen or non-indexed loads), Stage.buffer_address() resolved the resource key solely via self.descriptor(), which looks only at word 0. If earlier scalar instructions edited or cleared words 1-3 (stride, NUM_RECORDS, or format/OOB) without a proven transformation, the load translated anyway instead of refusing. Add Stage.load_descriptor() to validate 4-word descriptor operands against symbol table entries and modification tracking before emitting buffer loads. Resolve self.descriptor() first so existing select and branch join checks take precedence. Like 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 other modified descriptors with 'buffer load through a modified descriptor' or 'indexed load through a modified descriptor'. Formatted buffer loads retain their existing specialized validation, preserving the indexed modified-descriptor guard across both idxen and idxen+offen paths. Add tests/startup_gfx2hlsl_load_desc_check.py covering all 6 reproduction variants from R0Y00#2901 for both loads and stores, proven stride-0 raw loads, proven structured-to-raw conversions, unproven stride and raw conversion edits, indexed formatted loads with modified descriptors in L-uint, and negative control mutants. Register the test in CTest and CI check lists.
98ab777 to
7b44bda
Compare
|
Addressed in commit Preserved Indexed Formatted Load Guard (@R0Y00)
Test Verificationpython -B tests/startup_gfx2hlsl_load_desc_check.py
python -B tests/startup_gfx2hlsl_cselect_descnum_check.py controls
python -B tests/startup_gfx2hlsl_compute_check.py
python -B tests/compute_load_format_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
python -B tests/run_checks_parallel_check.pyAll passed with 0 failures on Windows 11 / Python 3.14 (including all 5 negative control mutants in |
R0Y00
left a comment
There was a problem hiding this comment.
The formatted indexed-load guard is restored at 7b44bda6, and the new source-built L-uint case exercises the exact derived-word counterexample. The specialized formatted descriptor checks and existing scalar heap-word contract are preserved.
On this head integrated with main e446b072, I reran startup_gfx2hlsl_load_desc_check.py, startup_gfx2hlsl_cselect_descnum_check.py controls, startup_gfx2hlsl_compute_check.py, startup_gfx2hlsl_heap_word_check.py and compute_load_format_check.py on 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.
|
Independent re-check at Lowering only — no DXIL, no adapter. This verifies the fix rather than reporting the defect. Trees
The four derived writesThese are the descriptor-word conversions
Same verdicts on the Unchanged on all three trees: the in-place rewrites of these words are refused everywhere (message Mutation receipts
Proposed case for the second branchBoth new cases use site = C.WORDS_L.index(C.LOAD_L)
idxen_only = C.WORDS_L.replace(C.LOAD_L, struct.pack('<I', 0xe00c3002 & ~0x1000) + C.LOAD_L[4:])
code = idxen_only[:site] + sop2(0x0e, 21, 13, 255, 0xc000ffff) + idxen_only[site:]
G.ComputePipeline(code, C.root_blob(), C.CASES['L-uint'][2], C.CASES['L-uint'][3]).hlsl_cs() # must raiseMeasured with that snippet on the clean RegressionThe 201 fixtures that mention Commandspython3 -B probe6.py <worktree> <label> # 13 shapes x 4 load forms, verdict + pipe.modified count
python3 -B mutMUT1.py <worktree> # drops the `elif idxen:` guard, then probe6 + 5 fixtures
python3 -B mut8.py <worktree> MUT2 # drops both guards
python3 -B sweep2.py <worktree> sweep.log out.log # replays the 201 green fixturesLimits
AI-assisted. |
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 7b44bda, rebased on upstream/main at 0e70446. 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 startup: a compute buffer load in gfx2hlsl ignores an edit to word 1–3 of its descriptor #2901.Evidence and follow-up
tests/cmake/startup_gfx2hlsl_load_desc.cmake,tests/checks/python-linux/startup_gfx2hlsl_load_desc.txt.AI-assisted.