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

Merged
kr4y4 merged 1 commit from upstream-pr/1587 into main 2026-10-10 01:12:22 +00:00
kr4y4 commented 2026-10-08 13:49:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-08T13:49:39Z.


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 0596a7a2), 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 033a4636 (rebased on 63c57d22 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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4787802407 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1587). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-08T13:49:39Z. --- ### 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 0596a7a2), 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 033a4636 (rebased on 63c57d22 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 - [x] Based on current `main`; no other open PR implements the same thing - [x] One topic per PR - [x] No comments in code except technical debt - [x] No silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fisherjoey commented 2026-10-09 04:22:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T04:22:26Z.


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 29e533ac.

main 29e533ac 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074209036 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1587#issuecomment-6074209036). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-09T04:22:26Z. --- 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` 29e533ac. | | `main` 29e533ac | `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 commented 2026-10-09 15:53:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T15:53:00Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5472353294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1587#pullrequestreview-5472353294). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-09T15:53:00Z. **Review:** COMMENTED --- 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 commented 2026-10-09 19:41:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T19:41:04Z.


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 d70b8998 aborts: std::span::operator[] assertion in Driver::preparePacketMemory aborts, same place
main + this change passes passes

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6087997841 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1587#issuecomment-6087997841). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-09T19:41:04Z. --- 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` d70b8998 | aborts: `std::span::operator[]` assertion in `Driver::preparePacketMemory` | aborts, same place | | `main` + this change | passes | passes | Bisecting with that build gives b25c6cce (the merge of #1362) as the first bad commit; its parent d026063a passes.
adriadam10 commented 2026-10-10 01:12:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T01:12:19Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092038681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1587#issuecomment-6092038681). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T01:12:19Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1587
No description provided.