fix(libSceAgc): read sceAgcLinkShaders' and sceAgcAcbSetWorkloadsActive's guest pointers through checked copies #23397

Merged
milescoviello merged 2 commits from upstream-pr/23397 into main 2026-11-27 03:22:31 +00:00
milescoviello commented 2026-11-19 00:14:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-19T00:14:54Z.


What

Folds my two open libSceAgc guest-copy PRs into one, as asked on #23161. Each commit is the original PR's change with its message, and the two debt entries are merged into one fragment. #22057 and #22495 will be closed with a link here.

  • sceAgcLinkShaders (#22057). It read the vertex and pixel shader headers through the guest pointers and stored the 34 context and 3 primitive registers straight into the caller's outputs, so an unmapped output or shader pointer crashed the host.
    • Both outputs and both headers are now read through GuestCopyIn_nid_no_patch first.
    • The registers are written through GuestCopyOut_nid_no_patch before the pipeline is committed. If the primitive registers cannot be written, the context registers are restored.
    • An inaccessible pointer returns GRAPHICS5_ERROR_INVALID_SHADER_PROGRAM, the result for a null output or vertex shader, with errno preserved. Nothing is published.
  • sceAgcAcbSetWorkloadsActive (#22495). It read the workload ids straight through the guest pointer.
    • The ids (at most 63) are now read once through GuestCopyIn_nid_no_patch.
    • Ids that cannot be read return null without writing to the command buffer, the result for null ids. The earlier checks still run first.
    • domx4q's #22417 makes the same change to the DCB form in DcbState/src/Workload.cpp; this PR doesn't edit that file.

Results for valid pointers are unchanged. The special-register and semantic tables the shader headers point to are still read directly; the debt fragment says so.

Tested

Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, -DBUILD_TESTING=ON, on c6853f2859 (on main 973026d9b0):

  • guest_shader_link gains four unmapped (0x10) calls: context output, primitive output, vertex shader, pixel shader. Each returns GRAPHICS5_ERROR_INVALID_SHADER_PROGRAM, keeps errno at 71 and leaves both outputs byte-for-byte unchanged.
  • agc_commands gains one check: ids at 0x10 with a count of 2 return null and leave the buffer's cursor where it was.
  • agc_commands, agc_initialization and guest_shader_link pass, 3 runs.
  • Negative controls (from the original PRs): with main's LinkShaders.cpp or Control.cpp and the new checks, the tests end in fatal SIGSEGV (code 1) at address 0x0000000000000010.

Windows 11 VM (GeForce GT 1030, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release):

  • agc_commands, agc_initialization and guest_shader_link pass, 3 runs, on c6853f2859.
  • maskym's earlier Windows + NVIDIA run of #22495's head c4c8723a96: the agc, guest_video_out, video_out and pad_sdl tests pass 2050 of 2054 on both main and the PR, with the same VUID- messages.

Both:

  • git merge-tree against main d89f26516c is clean. #22417's Commands.cpp hunk adds a test function away from this PR's line.
  • tools/check_conventions.py passes on the branch and this body. tools/debt_fold.py --check reports nothing for the fragment.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5386357267 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23397). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-19T00:14:54Z. --- ### What Folds my two open `libSceAgc` guest-copy PRs into one, as asked on #23161. Each commit is the original PR's change with its message, and the two debt entries are merged into one fragment. #22057 and #22495 will be closed with a link here. - **`sceAgcLinkShaders`** (#22057). It read the vertex and pixel shader headers through the guest pointers and stored the 34 context and 3 primitive registers straight into the caller's outputs, so an unmapped output or shader pointer crashed the host. - Both outputs and both headers are now read through `GuestCopyIn_nid_no_patch` first. - The registers are written through `GuestCopyOut_nid_no_patch` before the pipeline is committed. If the primitive registers cannot be written, the context registers are restored. - An inaccessible pointer returns `GRAPHICS5_ERROR_INVALID_SHADER_PROGRAM`, the result for a null output or vertex shader, with `errno` preserved. Nothing is published. - **`sceAgcAcbSetWorkloadsActive`** (#22495). It read the workload ids straight through the guest pointer. - The ids (at most 63) are now read once through `GuestCopyIn_nid_no_patch`. - Ids that cannot be read return null without writing to the command buffer, the result for null ids. The earlier checks still run first. - domx4q's #22417 makes the same change to the DCB form in `DcbState/src/Workload.cpp`; this PR doesn't edit that file. Results for valid pointers are unchanged. The special-register and semantic tables the shader headers point to are still read directly; the debt fragment says so. ### Tested Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, `-DBUILD_TESTING=ON`, on `c6853f2859` (on `main` `973026d9b0`): - `guest_shader_link` gains four unmapped (`0x10`) calls: context output, primitive output, vertex shader, pixel shader. Each returns `GRAPHICS5_ERROR_INVALID_SHADER_PROGRAM`, keeps `errno` at 71 and leaves both outputs byte-for-byte unchanged. - `agc_commands` gains one check: ids at `0x10` with a count of 2 return null and leave the buffer's cursor where it was. - `agc_commands`, `agc_initialization` and `guest_shader_link` pass, 3 runs. - Negative controls (from the original PRs): with `main`'s `LinkShaders.cpp` or `Control.cpp` and the new checks, the tests end in `fatal SIGSEGV (code 1) at address 0x0000000000000010`. Windows 11 VM (GeForce GT 1030, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release): - `agc_commands`, `agc_initialization` and `guest_shader_link` pass, 3 runs, on `c6853f2859`. - maskym's earlier [Windows + NVIDIA run](https://github.com/boykopovar/AnyPS5/pull/22495#issuecomment-6975795267) of #22495's head `c4c8723a96`: the `agc`, `guest_video_out`, `video_out` and `pad_sdl` tests pass 2050 of 2054 on both `main` and the PR, with the same `VUID-` messages. Both: - `git merge-tree` against `main` `d89f26516c` is clean. #22417's `Commands.cpp` hunk adds a test function away from this PR's line. - `tools/check_conventions.py` passes on the branch and this body. `tools/debt_fold.py --check` reports nothing for the fragment. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-23 06:09:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T06:09:04Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this; the points below are optional.

What I ran

Reviewed head c6853f285966c5f0f61a258a22c4087365804438. No commands or tests were run. I read the prepared description, commits, diff, manifest, README, and full text of all five changed files; I also read the checked-copy implementations and shader helper functions relevant to the changes. files.json was not available as a review document; the manifest and review README list all five changed files as included.

Results

Check Result Note
Changed-file review passed All five changed files read
Tests not run Author reports Linux and Windows runs
Negative control not run Author reports Linux controls

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author-reported test runs and negative controls were not independently run. Console behavior for unreadable guest pointers is explicitly unmeasured in the debt fragment. The shader headers are copied safely, but the special-register and semantic tables they reference remain directly read as documented.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017234776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23397#pullrequestreview-6017234776). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T06:09:04Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this; the points below are optional. ## What I ran Reviewed head `c6853f285966c5f0f61a258a22c4087365804438`. No commands or tests were run. I read the prepared description, commits, diff, manifest, README, and full text of all five changed files; I also read the checked-copy implementations and shader helper functions relevant to the changes. `files.json` was not available as a review document; the manifest and review README list all five changed files as included. ## Results | Check | Result | Note | |---|---|---| | Changed-file review | passed | All five changed files read | | Tests | not run | Author reports Linux and Windows runs | | Negative control | not run | Author reports Linux controls | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author-reported test runs and negative controls were not independently run. Console behavior for unreadable guest pointers is explicitly unmeasured in the debt fragment. The shader headers are copied safely, but the special-register and semantic tables they reference remain directly read as documented. ## To get this to a good state Nothing is required.
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!23397
No description provided.