Range checking misses soffset-addressed accesses: the argument-writer atomic that broke the transient pool is still unbounded #3
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ThatRecompDev--five-star-recomp#3
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?
@RubAway on GitHub · 2026-11-24 13:59 UTC · original
Range checking misses soffset-addressed accesses — the argument-writer atomic that broke the transient pool is still unbounded
First:
ccc277fand thebuf_limitrewrite in8b97849encode exactly the semantics the title relies on ("append and argument writers run past their allocation, loops read zeros past an end") — great fix direction. I statically inspected the translator and two named kernels from a locally-owned 1.0.2.1 dump (no game code or content beyond five instruction lines quoted below), and I believe the writer your commit message blames ("an argument writer ran past its allocation … into the game's transient pool and broke its block-end nodes") still walks free past the new checks.Evidence.
fivestar shader extractofshaders.rpf+ the exe (26,515 records, 25,908 programs, 0 failed — matching your numbers) andfivestar shader disasmofmeshlet_culling~CS_AllocBatchCSCullOutput(sgd1_0c3dd3da…fssm), the slot allocator for the cull argument buffer:The hole. This atomic addresses entirely through soffset:
vaddr = off, noidxen, nooffen.BufferAddress.Range(as of8b97849, docstring still says "VGPR offset + instruction offset, not soffset") then returns offset =0u + instruction offset, sooffset < buf_limit(...)is vacuously true: the one instruction class whose runahead your commit message identified as the corruption mechanism is precisely the class the range check does not bound. The dependentidxenstore is checked, but its slot index comes from the unbounded atomic, so a stale or wrongly-strided counter still marches records through memory — thebuffer_store_format_xyzw/idxenpair above is exactly the 20-byte indirect-argument record pattern. With the prelude comment acknowledging "soffset is not checked", this may be a known limitation, but it changes what a retranslate is expected to fix: the allocator atomics need the check folded in before the transient-pool corruption can be expected to disappear.Fix shape (as small as the current rewrite makes it comfortable): fold soffset into the checked offset in
Range—bytes += operands.Read(soffset)— for MUBUF/MTBUF/sBUF forms whose addressing includes an SGPR offset; console OOB_SELECT checks the final address including soffset. TheCS_AllocBatchCSCullOutputcase above would then be the reference test case.Secondary, all acknowledged in your own comments, ranked: (1) structured sel 0/1 omits the offset-vs-stride check — a store at offset ≥ stride inside record N silently overwrites the first dword of record N+1 (e.g.
InstanceCountof the following indirect-arg record); (2) shim-built V#s leave OOB_SELECT at 0, so raw byte-indexed views get structured semantics — both false drops and missed drops; (3) V#s over the address map (root-descriptor-built, "through the address map" per theccc277fmessage) have nonum_recordsto check against unless the game itself wrote them — the address map knows each committed range's extent, and cappingnum_recordsat the distance to the end of that range is a sound upper bound for free.Reproduce:
fivestar shader extract <dump>/shaders.rpf <out> --exe <dump>/game_scarlett_master.exe; open<out>/fssm/*CS_AllocBatchCSCullOutput*.fssmwithfivestar shader disasm; readBufferAddress.Rangeatec72819. Happy to run a fuller static pass over the cull chain (there are sibling kernelsCS_CullMeshletsInitArgs,CS_BatchCullInitArgs,CS_InitVisibleCount,CS_CountVisibleMeshletsBatchCSetc. in the same pack) and report per-kernel addressing forms if useful.Analysis from a neutral third party on request; all claims above are static disassembly + source reading, no runtime involved.
@ThatRecompDev on GitHub · 2026-11-24 14:32 UTC · original
Thanks, this is a really useful read. We're checking it against the RDNA2 ISA now: as far as I know the hardware leaves soffset out of the range check, in which case the console relies on that counter being correct and our bug is the counter's value (a missing reset, or the init pass not running) rather than the check. Either way your third point (capping num_records at the committed range for address-map views) is a sound safety net and we're adding it. A heap corruption with INT_MAX/INT_MIN-like values still shows up occasionally, so this lines up with what we see. Will post what we find.
@ThatRecompDev on GitHub · 2026-11-24 14:38 UTC · original
Update: you were right about soffset, and my GCN-era recollection was wrong. Measured RDNA hardware (gfx1036 and gfx1011) checks raw buffers as offset + soffset + 4 > num_records, with the index not checked in raw mode; structured mode 0 also checks offset against stride. The translator now follows that table, buffer records carry a realistic OOB_SELECT per view kind (raw 3, structured 0, typed/CBV 1), and a WARP case with a soffset-only load fails without the fix (
83572fc). One correction to the kernel name: the soffset-only slot atomic is in CS_BatchCullBatchCSMeshlets (and _Prev), plus eight sibling culling kernels. Thanks for the careful analysis.@RubAway on GitHub · 2026-11-24 15:22 UTC · original
Thanks — glad it landed, and the correction is taken:
CS_BatchCullBatchCSMeshlets(+_Prevand the siblings) fits what we saw around the allocator chain; the soffset-only atomic we quoted sits in the same addressing family.Two things from our side that might help with the INT_MAX/INT_MIN-shaped corruption that still shows up occasionally:
A wraparound note on the measured raw rule: with
offset + soffset + 4 > num_recordsevaluated inu32, a negative byte offset (two's complement, e.g.0xFFFFFFxxfrom a signedslot = idx - countunderflow) wraps the sum back undernum_recordsand passes the check while aiming far below the buffer base. The hardware agrees with that wrap, so matching the console is still right — but it means the range check cannot catch signed underflow in the slot computation itself, and INT_MIN-like written values smell exactly like that underflow propagating through records rather than a bounds miss. If the log of dropped accesses is cheap, it may be worth also logging, per argument-writing kernel, the atomic return values that fall outside[0, capacity)— a slot index assert rather than a byte bounds check.We are re-running a full ahead-of-time translate of the 25,908 programs on the current main with your
83572fcsemantics (soffset-inclusive raw checks, per-kind OOB_SELECT). When it finishes we can post a static listing fromshader disasm: every program that contains soffset-only buffer writes and every one that writes the 20-byte indirect-argument record pattern — a map of which kernels the new checks actually bound, versus which rely on their counters being correct. Useful, say the word; otherwise we'll just keep watching main.@ThatRecompDev on GitHub · 2026-11-25 08:10 UTC · original
closing this one: soffset now counts in the range check for raw buffers (that's what the hardware measurements showed), and we audited every buffer access form the game uses against the GFX10 rules, with a WARP test per rule. if you still see the argument-writer atomic go out of range on current main, reopen