Skip to content

fix(libSceAgcDriver): read the RELEASE_MEM interrupt select only from RELEASE_MEM packets - #1587

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
kr4y4:fix/agc-release-mem-int-sel-bounds
Oct 10, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
kr4y4:fix/agc-release-mem-int-sel-bounds

Conversation

@kr4y4

@kr4y4 kr4y4 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What

Driver::preparePacketMemory reads packet[2], the RELEASE_MEM interrupt select, for every packet. The read used to sit behind opcode == 0x49 &&, and #1362 moved it ahead of that check. packet is the packet's own span, and Pm4::Validate accepts 2-dword packets, for example PFP_SYNC_ME (case 0x42: size(2)). So for those, index 2 is one past the end:

  • In a normal build it reads the next packet's header. If the 2-dword packet is the last one in the submission, it reads 4 bytes past the end of the command buffer.
  • The value is only used when the opcode is 0x49, so the result is unaffected, but the read is out of bounds.
  • With _GLIBCXX_ASSERTIONS, the std::span bounds check aborts on the first such packet.

The interrupt select is now read only for RELEASE_MEM, whose packet Validate requires to be 8 dwords.

Tested

Windows 11 (26200), WinLibs GCC 15.2.0 r7.

  • Build with -D_GLIBCXX_ASSERTIONS -fsanitize=undefined -fsanitize-trap=undefined (main at 0596a7a), NVIDIA RTX 4070 Laptop:
    • Without this change, agc_driver and agc_driver_pm4 exit with 0xC0000409: span:302: ... std::span<const unsigned int>::operator[] ... Assertion '__idx < size()' failed, from Driver::preparePacketMemory on a PFP_SYNC_ME packet (header 0xc0004200, size 2).
    • With it, both pass.
    • The same instrumented run has 447 tests. The only other failures are three LibAtrac9 tests that trap on an unrelated shift in the submodule.
  • Normal CI configure, main at 033a463 (rebased on 63c57d2 without changes to this file): agc_driver and agc_driver_pm4 pass with --repeat until-fail:3 on the RTX 4070 and on an Intel Raptor Lake-S iGPU.

Checklist

  • Based on current main; no other open PR implements the same thing
  • One topic per PR
  • No comments in code except technical debt
  • No silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

… RELEASE_MEM packets

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the agc libSceAgc* label Oct 8, 2026
@fisherjoey

Copy link
Copy Markdown
Contributor

Linux results, since this was tested on Windows only. Everything passes here.

Nobara 44 (Linux 7.2), GCC 16.2.1, Release, BUILD_TESTING=ON. This PR merged onto main 29e533a.

main 29e533a main + this PR
RTX 5070 Ti, driver 595.91.07, ctest -R agc_driver -j1 183 / 183 183 / 183
RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1, same 183 / 183 183 / 183
CPU tests (-E agc_driver) 279 / 280 279 / 280

The CPU failure is guest_dynamic_loader, which fails the same way on main.

@Dextroid17 Dextroid17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux negative control — the Linux result above is a Release run, which passes either way and so does not exercise the read.

Debug + -D_GLIBCXX_ASSERTIONS, gcc 16.2.1, merged onto d70b8998; only PacketMemory.cpp swapped between arms:

                     main        this PR
agc_driver_tests     exit 134    exit 0
agc_driver_pm4_tests exit 134    exit 0

On main the abort is span:288 ... operator[] inside Driver::preparePacketMemory (PacketMemory.cpp:21); the gdb frame reads packet=std::span of length 2, header=0xC0004200, opcode=0x42 — the 2-dword PFP_SYNC_ME packet (Pm4.cpp:335 size(2)). 0x49 is size(8) (Pm4.cpp:412), so the guarded read is in bounds whenever the value is used. Release arm with the change: both tests pass.

This also closes the two agc_driver failures in issue #2321 (its #331 guest_ajm is a separate AT9 issue).

Could not verify: Windows.

Written with AI assistance.

@LeandroLP23

Copy link
Copy Markdown
Contributor

Independent confirmation on AMD, from a duplicate I opened by mistake (#2338, closed). Windows 11 (26300), Radeon 860M (RDNA 3.5), WinLibs GCC 15.2.0 r7, clean build with -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-D_GLIBCXX_ASSERTIONS:

agc_driver agc_driver_pm4
main d70b899 aborts: std::span::operator[] assertion in Driver::preparePacketMemory aborts, same place
main + this change passes passes

Bisecting with that build gives b25c6cc (the merge of #1362) as the first bad commit; its parent d026063 passes.

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the diff (the interrupt select is now read only for RELEASE_MEM, which Validate requires to be 8 dwords, so the 2-dword PFP_SYNC_ME no longer indexes past its span), build + ctest of libSceAgcDriver (270/270) and CI. The negative control and the Linux/Windows runs from @Dextroid17, @fisherjoey and @LeandroLP23 confirm it. Merging.

@adriadam10
adriadam10 merged commit b2f4218 into boykopovar:main Oct 10, 2026
7 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…mem-int-sel-bounds

fix(libSceAgcDriver): read the RELEASE_MEM interrupt select only from RELEASE_MEM packets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants