Skip to content

fix(libSceAmpr): stage command payloads before a buffer expansion - #16623

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
mashingaan:fix/libSceAmpr-stage-payload-before-expansion
Nov 10, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
mashingaan:fix/libSceAmpr-stage-payload-before-expansion

Conversation

@mashingaan

@mashingaan mashingaan commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What

AppendNop, AppendMarker and sceAmprCommandBufferConstructNop copy from a caller-supplied guest pointer after EnsureCommandCapacity has run. That call can expand the command buffer, which frees the previous allocation. A payload, word or marker text that points into the command buffer therefore dangles and is read after the free.

Stage those bytes before the append. AppendNop stages its data dword, AppendMarker stages its text, and sceAmprCommandBufferConstructNop stages its payload and word.

Tested

guest_ampr on Hosted CI. The new TestConstructNopPayloadIntoBuffer grows a small buffer, places a payload inside the expanded allocation, and calls sceAmprCommandBufferConstructNop with a pointer into it so the next append reallocates; the copied bytes are checked. This is an ASan regression test: without the staging, the source read is a use-after-free. All 13 checks passed on Hosted CI for 8fe32e5b50, including the Windows build and test run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs listed
  • No notes, investigation .md files or images added
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none (unreported host-safety bug)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions github-actions Bot added the prx label Nov 7, 2026
@JJenkx

JJenkx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 8fe32e5b50, merged onto main 502288c2cf (bd3eb43460, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_ampr_markers passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@blawesom

blawesom commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Reviewed the staging fix and ran it on Linux. The aliasing hazard is real and the fix is the right shape: AppendNop previously memcpy'd the payload from guest data after EnsureCommandCapacity, which can expand and relocate the buffer — a payload sourced inside the old buffer would then read from moved memory. Staging into the local array first (std::memcpy(staged.data(), data, payloadBytes) before the capacity call) removes the window, and TestConstructNopPayloadIntoBuffer constructs exactly that case (payload pointer into the expanded buffer, verified byte-for-byte after the re-expansion).

The 60-byte bound is safe by construction: the only data-carrying caller is sceAmprCommandBufferNopWithData, which rejects dwords > 15 (Export.cpp), so payloadBytes never exceeds 60; the marker path stages through a std::string, which is self-sizing.

Linux run of head 8fe32e5b50f merged onto main 0cdb9e4a961 (clean): CachyOS x86-64, GCC 16.2.1, Release, guest_ampr passes 4 of 4, including the new payload regression.

AI-assisted: yes

@oneandonlydean oneandonlydean self-assigned this Nov 9, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 10, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 10, 2026
@oneandonlydean
oneandonlydean merged commit 1d4cef3 into boykopovar:main Nov 10, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants