fix(libSceAgc): copy end-of-pipe patch guest pointers safely #22184
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22184"
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 boykopovar/AnyPS5. Originally posted by domx4q on 2026-11-17T07:44:59Z.
What
sceAgcQueueEndOfPipeActionPatchAddress,sceAgcQueueEndOfPipeActionPatchData,sceAgcQueueEndOfPipeActionPatchGcrCntlandsceAgcQueueEndOfPipeActionPatchTyperead and wrote the RELEASE_MEM / EVENT_WRITE_EOP packet straight through the guest command pointer, so an unmapped or read-only packet crashed the process. The command buffer is guest memory that the title allocates, not a handle allocated on the host, so every function is a real finding. Theaddressargument of...PatchAddressis only stored as a value and never dereferenced.Each export now:
GuestCopyIn_nid_no_patchand validates it with the existingAgc::Command::ValidatePacketon the host copy, as before,GuestCopyOut_nid_no_patch.An unreadable or unwritable packet throws through
Agc::Command::Require("packet is not readable" / "packet is not writable"). This follows how the libSceAgc packet info exports (#20051) handle an unwritable output. The checks and their order are unchanged, and a packet that is readable and writable is patched to the same bytes as before.No debt fragment: no
libSceAgc.mdentry describes how these exports handle the packet memory.Overlap
python3 tools/pr_overlap.py --names sceAgcQueueEndOfPipeActionPatchAddress sceAgcQueueEndOfPipeActionPatchData sceAgcQueueEndOfPipeActionPatchGcrCntl sceAgcQueueEndOfPipeActionPatchType: every function ismain: core/libs/prx/libSceAgc (implemented),open: none.python3 tools/pr_overlap.py --branch fix/agc-eop-patch-guest-pointers: "No overlap with open pull requests."Tested
Arch Linux, GCC 16.2.1, Release,
-DBUILD_TESTING=ON.ctest --test-dir build -R '^(agc_commands|agc_end_of_pipe_type_patch|public_headers)$': 3/3 passed.core/libs/prx/libSceAgc/tests/Commands.cpp:0x10as the packet to all four exports,static const(read-only.rodata) RELEASE_MEM packet to all four exports and an EVENT_WRITE_EOP packet to...PatchAddress, then check that the packets are unchanged.mainone at a time. Each timeagc_command_testsdied withfatal SIGSEGV ... at address 0x10(rc 139).GuestCopyOut_nid_no_patchwrite-back with direct stores. The test then died withfatal SIGSEGV (code 2)on the read-only packet.python3 tools/guest_pointer_audit.py libSceAgcno longer lists anything inQueueEndOfPipeAction.cpp.python3 tools/check_conventions.py --base origin/mainpasses.python3 tools/debt_fold.py --checkfails only ondocs/dev/debt/changes/docs-nkwebkit-drop-readded-count-lines.md, which is already onmainand is not touched here.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -R '^(agc_commands|agc_end_of_pipe_type_patch)$' -V, once onmain(e4caa07950) and once on this branch. Both runs passed 2/2 with 0VUID-lines and nowas not found but was requested by env var VK_INSTANCE_LAYERS. These CPU-only packet tests never create a Vulkan instance, so neither log has anInsert instance layerline. To show the layer setup works,vulkaninfo --summarywith the same environment logsInsert instance layer "VK_LAYER_KHRONOS_validation" (/usr/lib/libVkLayer_khronos_validation.so), layer 1.4.363.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T09:33:30Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix the EVENT_WRITE_EOP address validation path so a non-RELEASE_MEM header cannot bypass validation and proceed as an event packet.
What I ran
Reviewed head
16c9f509ea44a66bc6ba38aafcb5910f16da2938. Readdescription.md,commits.md,manifest.json,diff.patch,QueueEndOfPipeAction.cpp,Commands.cpplines 330–390 and 920–970, andPacket.hpp. The suppliedfiles.jsonwas not available through the review reader; manifest reports both changed files included. No tests or builds were run.Results
Findings
Blocking
core/libs/prx/libSceAgc/Patch/src/QueueEndOfPipeAction.cpp:48-49: Every header whose opcode is not0x49falls into the event branch, wherereadPacket<6>(cmd, 0x47u, ...)validates only the copied header. This changes the previous behavior, which rejected any opcode other than0x47or0x49; an unrelated packet with a six-dword count can now be patched as EVENT_WRITE_EOP. Check explicitly for0x47and reject other opcodes before reading the event packet.Non-blocking
None.
Not verified
files.jsonwas not available through the reader, so its reviewed/excluded inventory could not be confirmed.To get this to a good state
Reject opcodes other than
0x47and0x49insceAgcQueueEndOfPipeActionPatchAddress, then rerun the reported targeted tests and build checks.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T10:25:59Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation safely copies packet data through guest memory helpers and preserves the intended opcode handling.
What I ran
Reviewed head
05282cc713aca29eb96b286a938d8d93f9f92cb7. No commands or tests were run; the PR description reports test results that I did not independently reproduce.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not independently verify reported tests, mutation checks, guest pointer audit, convention checks, debt check, or GPU/Vulkan runs. Read
core/libs/prx/libSceAgc/Patch/src/QueueEndOfPipeAction.cppand the changed test ranges incore/libs/prx/libSceAgc/tests/Commands.cpp; also readcore/libs/prx/libSceAgc/Command/include/Packet.hppandcore/libs/prx/libSceAgc/Command/include/Memory.hppfor context. No files were excluded inmanifest.json.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T16:17:01Z.
Review: APPROVED
I read the diff at
05282cc713. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), applied ontomainatc1593e4e1ddtogether with other open PRs (so not an isolated build).agc_commands,agc_initializationandagc_initialization_zero: pass on both.main's):agc_commandscrashes on a read of address 0x10.Not checked: a GPU run (these tests do not use one), and the cost of the copies for a title that patches many packets per frame.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:30:58Z.
Review: COMMENTED
sceAgcQueueEndOfPipeActionPatchAddressnow returns0x8a6c000cfor other opcodes. At the merge base those packets fall through toValidatePacketas EVENT_WRITE_EOP and throw on a mismatched header. The new NOP and foreign-packet tests lock in the changed return behavior. Please cite the console measurement for that change or retain the existing failure path in this pointer-hardening PR.Source review at
05282cc713. The Linux packet comparison is queued.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T19:58:02Z.
Review: COMMENTED
Actionable comments
c3403d35-f2da-47e8-b7ba-6665c744a2d4Reviewing files that changed from the base of the PR and between
422923d68dand6e686255e3.core/libs/prx/libSceAgc/Patch/src/QueueEndOfPipeAction.cppcore/libs/prx/libSceAgc/tests/Commands.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:58:49Z.
Review: COMMENTED
The new head routes foreign packet headers through
ValidatePacket, which reads only the captured header. The updated command fixtures expect that failure and check the packets remain unchanged. The trial merge with currentmainis clean. On the prior head, the pairedagc_commandsand scalar Vulkan controls passed on lavapipe with validation layer 1.4.369 and noVUID-errors. I omitted the dedicated end-of-pipe test executable from that build, so that test did not run. The dedicated target is queued with the current head.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T23:52:31Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
6e686255e34ed3d6830a6691e85d2ff36e91d3c0. No tests or builds were run; the PR description’s test results are author-reported. No merged-preview check was run.Results
Negative control
Not run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Read the complete changed implementation and the relevant test ranges. The rest of
core/libs/prx/libSceAgc/tests/Commands.cppwas not read;files.jsonlists no excluded files. Tests, builds, GPU behavior, and the author-reported mutation checks were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T16:13:50Z.
Review: APPROVED
Re-verified head
6e686255e3on Windows 11 with GCC 15.2, applied alone to main484b0368d3. The new commit keeps rejecting address patches of other packets and adds those cases toCommands.cpp.agc_commands,agc_initializationandagc_initialization_zero: 3 of 3 pass, as on main.QueueEndOfPipeAction.cppreverted to main and the tests kept:agc_commandscrashes on a read of0x10.Not run: Linux on this head, or a title.
AI-assisted: yes (Claude Code)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.