fix(libSceGnmDriver): safely probe the command buffer in the VGT control writers #20423

Merged
milescoviello merged 2 commits from upstream-pr/20423 into main 2026-11-15 06:24:06 +00:00
milescoviello commented 2026-11-15 05:43:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-15T05:43:10Z.


What

sceGnmSetVgtControl and sceGnmResetVgtControl (the _nid_disambig1 exports of libSceGnmDriver) stored their three-dword packet with cmdbuf[0..2] = ..., so a non-null cmdbuf pointing at unmapped memory faulted the host. Both now build the packet on the host and write it with one GuestCopyOut_nid_no_patch, returning -1 (their refusal for a null or wrongly sized buffer) when the write fails.

The argument checks, the sceKernelIsNeoMode choice between the base and Neo encodings, and the packet words are unchanged.

Only the libSceGnmDriver exports change. The libSceGnmDriverForNeoMode sceGnmSetVgtControl / sceGnmResetVgtControl are left alone because #16238 rewrites them; the new test cases therefore run only for the normal provider. The debt entry records the unmapped-memory result as a host-safety fallback; console behaviour there is not measured.

Tested

Linux (Ubuntu 26.04.1), GCC 15.2, Release.

  • guest_gnm_vgt_normal_base and guest_gnm_vgt_normal_neo: both writers given the unmapped buffer 0x10 with size 3 return -1. errno is not asserted, since sceKernelIsNeoMode, which both call before writing, already changes it on every call.
  • ctest -R '^guest_gnm_vgt_': 6/6 pass (the json / none metadata modes and the Neo provider are unchanged).
  • tools/check_conventions.py passes on the branch and this body.

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:5319908493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20423). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-15T05:43:10Z. --- ### What `sceGnmSetVgtControl` and `sceGnmResetVgtControl` (the `_nid_disambig1` exports of libSceGnmDriver) stored their three-dword packet with `cmdbuf[0..2] = ...`, so a non-null `cmdbuf` pointing at unmapped memory faulted the host. Both now build the packet on the host and write it with one `GuestCopyOut_nid_no_patch`, returning -1 (their refusal for a null or wrongly sized buffer) when the write fails. The argument checks, the `sceKernelIsNeoMode` choice between the base and Neo encodings, and the packet words are unchanged. Only the libSceGnmDriver exports change. The libSceGnmDriverForNeoMode `sceGnmSetVgtControl` / `sceGnmResetVgtControl` are left alone because #16238 rewrites them; the new test cases therefore run only for the `normal` provider. The debt entry records the unmapped-memory result as a host-safety fallback; console behaviour there is not measured. ### Tested Linux (Ubuntu 26.04.1), GCC 15.2, Release. - `guest_gnm_vgt_normal_base` and `guest_gnm_vgt_normal_neo`: both writers given the unmapped buffer `0x10` with size 3 return -1. `errno` is not asserted, since `sceKernelIsNeoMode`, which both call before writing, already changes it on every call. - `ctest -R '^guest_gnm_vgt_'`: 6/6 pass (the `json` / `none` metadata modes and the Neo provider are unchanged). - `tools/check_conventions.py` passes on the branch and this body. ### 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-15 05:54:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T05:54:59Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the packet encoding remains unchanged and the writers now return -1 when the guest copy fails.

What I ran

Reviewed head 72a75c6062ae9dc24a3c36694dafde5193fefc6f from the prepared diff and source reader. No commands or tests were run.

Results

Check Result Note
Code review passed Changed implementations and test logic read
Tests not run Author reports 6/6 targeted tests passed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author-reported Linux/GCC test results were not independently run. Console behavior for unmapped memory remains unmeasured, as documented. The complete 877-line export file was not read; relevant includes and changed writer functions were read. All three changed files listed in the manifest were read. files.json was not available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5909342414 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20423#pullrequestreview-5909342414). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-15T05:54:59Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the packet encoding remains unchanged and the writers now return -1 when the guest copy fails. ## What I ran Reviewed head `72a75c6062ae9dc24a3c36694dafde5193fefc6f` from the prepared diff and source reader. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Changed implementations and test logic read | | Tests | not run | Author reports 6/6 targeted tests passed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author-reported Linux/GCC test results were not independently run. Console behavior for unmapped memory remains unmeasured, as documented. The complete 877-line export file was not read; relevant includes and changed writer functions were read. All three changed files listed in the manifest were read. `files.json` was not available through the reader. ## 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!20423
No description provided.