fix(libSceAgc): read sceAgcAcbSetWorkloadsActive's workload ids through a checked copy #22495

Closed
milescoviello wants to merge 1 commit from upstream-pr/22495 into main
milescoviello commented 2026-11-17 17:51:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-17T17:51:43Z.


What

sceAgcAcbSetWorkloadsActive read the caller's workload ids straight through the guest pointer while building the active mask. For a registered stream, an unmapped id array crashed the host.

  • The ids (at most 63, so at most 252 bytes) are read once through GuestCopyIn_nid_no_patch into a host array, and the mask is built from that copy.
  • Ids that cannot be read return null without writing to the command buffer, the result this call already gives for null ids.

Results for readable ids are unchanged. The checks before the read (null buffer, null ids, count 0 or above 63, unregistered stream) still run first, so an unregistered stream still returns null without touching the ids, as the debt entry for the DCB form records the console doing. #22417 (domx4q) makes the same change to sceAgcDcbSetWorkloadsActive in DcbState/src/Workload.cpp. This PR changes only the ACB form in Acb/src/Control.cpp, so the two don't overlap.

Tested

Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, -DBUILD_TESTING=ON:

  • agc_commands gains one check after the registered-stream ACB checks: ids at 0x10 with a count of 2 return null and leave the buffer's cursor where it was.
  • agc_commands passes, 3 runs.
  • Negative control: with main's Control.cpp and the new check, it ends in fatal SIGSEGV (code 1) at address 0x0000000000000010.
  • maskym's Windows + NVIDIA run of c4c8723a96 merged into main e069a7562f (Windows 11, i7-12700K, RTX 2070 SUPER, WinLibs GCC 15.2.0, Release, Khronos validation layer 1.4.366): the agc, guest_video_out, video_out and pad_sdl tests pass 2050 of 2054 on both main and this PR with the same set of VUID- messages, agc_commands and agc_initialization pass, and the three failures also fail on main there.
  • git merge-tree against main is clean. #22417 doesn't edit Control.cpp. Its Commands.cpp hunk adds a test function after testMemory, away from the line this PR adds, and git apply -3 of both diffs onto main is clean.
  • tools/check_conventions.py passes on the branch and this body. tools/debt_fold.py --check reports nothing for this 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:5362099017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22495). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-17T17:51:43Z. --- ### What `sceAgcAcbSetWorkloadsActive` read the caller's workload ids straight through the guest pointer while building the active mask. For a registered stream, an unmapped id array crashed the host. - The ids (at most 63, so at most 252 bytes) are read once through `GuestCopyIn_nid_no_patch` into a host array, and the mask is built from that copy. - Ids that cannot be read return null without writing to the command buffer, the result this call already gives for null ids. Results for readable ids are unchanged. The checks before the read (null buffer, null ids, count 0 or above 63, unregistered stream) still run first, so an unregistered stream still returns null without touching the ids, as the debt entry for the DCB form records the console doing. #22417 (domx4q) makes the same change to `sceAgcDcbSetWorkloadsActive` in `DcbState/src/Workload.cpp`. This PR changes only the ACB form in `Acb/src/Control.cpp`, so the two don't overlap. ### Tested Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, `-DBUILD_TESTING=ON`: - `agc_commands` gains one check after the registered-stream ACB checks: ids at `0x10` with a count of 2 return null and leave the buffer's cursor where it was. - `agc_commands` passes, 3 runs. - Negative control: with `main`'s `Control.cpp` and the new check, it ends in `fatal SIGSEGV (code 1) at address 0x0000000000000010`. - maskym's [Windows + NVIDIA run](https://github.com/boykopovar/AnyPS5/pull/22495#issuecomment-6975795267) of `c4c8723a96` merged into `main` `e069a7562f` (Windows 11, i7-12700K, RTX 2070 SUPER, WinLibs GCC 15.2.0, Release, Khronos validation layer 1.4.366): the `agc`, `guest_video_out`, `video_out` and `pad_sdl` tests pass 2050 of 2054 on both `main` and this PR with the same set of `VUID-` messages, `agc_commands` and `agc_initialization` pass, and the three failures also fail on `main` there. - `git merge-tree` against `main` is clean. #22417 doesn't edit `Control.cpp`. Its `Commands.cpp` hunk adds a test function after `testMemory`, away from the line this PR adds, and `git apply -3` of both diffs onto `main` is clean. - `tools/check_conventions.py` passes on the branch and this body. `tools/debt_fold.py --check` reports nothing for this 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

Pull request closed

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!22495
No description provided.