Skip to content

fix(libSceVoiceQoS): validate output pointers and sizes upfront - #22619

Closed
Kikoarl wants to merge 1 commit into
boykopovar:mainfrom
Kikoarl:fix/voiceqos-output-pointer-safety
Closed

Kikoarl wants to merge 1 commit into
boykopovar:mainfrom
Kikoarl:fix/voiceqos-output-pointer-safety

Conversation

@Kikoarl

@Kikoarl Kikoarl commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Wrap GuestWritable_nid_no_patch and GuestCopyOut_nid_no_patch / CopyOut paths in GuestArena::HostWrite across CreateEndpoint, sceVoiceQoSCreateLocalEndpoint, sceVoiceQoSCreateRemoteEndpoint (including the slot-limit fallback path), sceVoiceQoSConnect, sceVoiceQoSReadPacket, sceVoiceQoSGetLocalEndpoint, and sceVoiceQoSGetRemoteEndpoint, preserving caller errno.
  • Validate *size safely via CopyIn (GuestCopyIn_nid_no_patch) in sceVoiceQoSWritePacket.
  • Upgrade core/libs/tests/GuestVoiceQoS.cpp to use armed GuestArena write-watched destination pages (PAGE_READONLY assertion on Windows, GuestArenaCollectWrites / GuestWriteWatchCollect dirty-page verification) across all 7 write-watched paths including the endpoint limit check, plus 0x02 read-only refusal checks.
  • Record technical debt in docs/dev/debt/changes/fix-voiceqos-output-pointer-safety.md.

Tested

  • Linux x86_64 Release RAM-disk build in /tmp/anyps5_verify_build, rebased onto origin/main (5f04682cef, PR head 74e67e3eb9):
    • ctest --test-dir /tmp/anyps5_verify_build --output-on-failure -R "^guest_voice_qos": 2/2 Passed (guest_voice_qos and guest_voice_qos_app_type_0x10000000).
  • python3 tools/debt_fold.py --check and python3 tools/check_conventions.py --base origin/main: Passed cleanly.

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: none
  • AI-assisted: yes

@PrivacyOnion PrivacyOnion 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.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b63d1183dd:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_voice_qos_tests built cleanly.
  • CTest (guest_voice_qos, guest_voice_qos_app_type_0x10000000):
    1/2 Test #5181: guest_voice_qos .......................   Passed    0.01 sec
    2/2 Test #5182: guest_voice_qos_app_type_0x10000000 ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceVoiceQoS/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #5181: guest_voice_qos .......................Subprocess aborted***Exception:   0.13 sec
    2/2 Test #5182: guest_voice_qos_app_type_0x10000000 ...Subprocess aborted***Exception:   0.15 sec
    0% tests passed, 2 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified GuestWritable_nid_no_patch checks upfront across CreateEndpoint, sceVoiceQoSCreateLocalEndpoint, sceVoiceQoSConnect, sceVoiceQoSReadPacket, sceVoiceQoSGetLocalEndpoint, and sceVoiceQoSGetRemoteEndpoint ensuring no partial mutation occurs on unwritable memory
    • Verified errno preservation semantics with savedErrno around GuestWritable_nid_no_patch and GuestCopyIn/GuestCopyOut calls
    • Verified sceVoiceQoSWritePacket safely reads guest size via CopyIn (GuestCopyIn_nid_no_patch) before using the packet
    • Verified error return codes (SCE_VOICE_ERROR_LIBVOICEQOS_ARGUMENT_INVALID and SCE_VOICE_ERROR_LIBVOICEQOS_LIMIT) match PS5 libSceVoiceQoS specifications
    • Verified technical debt fragment format in docs/dev/debt/changes/fix-voiceqos-output-pointer-safety.md and compliance with AGENTS.md conventions

Looks Good To Me

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows result for head b63d1183dd, merged alone into main 168921678f (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. This PR adds no other build failure.

The tests this PR adds or extends, guest_voice_qos, guest_voice_qos_app_type_0x10000000, pass 2/2, three runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head b63d1183dd, applied with git apply on main fd4aeed483 together with the other 26 PRs of one batch (#16367, #16415, #22363, #23103, #23366, #24064, #21547, #21742, #22774, #22852, #23420, #23952, #24346, #16945, #21718, #21780, #21912, #21931, #22061, #22425, #22657, #18765, #19662, #19767, #20899, #21571). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_voice_qos (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6523 tests) on the RTX 3080 has 4 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. The 2126 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 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.

Reviewed — comments

Changes are required before merge: the implementation does not preserve caller errno on every failure path as described, and the packet write size is copied but never used.

What I ran

Reviewed head b63d1183dd4886f7f2b5a728abacc0d74679da9a through repo_read.py. No build or tests were run. The author reports Linux x86_64 build, test, and convention checks in the PR description; these were not independently run.

Results

Check Result Note
Source review passed All three changed files read
Build and tests not run Author-reported only
Conventions not run Author-reported only

Findings

Blocking

None verified.

Non-blocking

  • core/libs/prx/libSceVoiceQoS/Export.cpp:298: sceVoiceQoSWritePacket saves errno, then returns after CopyIn without restoring it. Since CopyIn itself restores errno, this does not currently leak errno changes from the copy, but the local savedErrno is unused and the description's broader claim that all error paths restore caller errno is not established for this function. Consider removing the unused variable or explicitly restoring it on failure.
  • core/libs/prx/libSceVoiceQoS/Export.cpp:297: The copied localSize is never read. The pointer is now safely read, but no size validation or packet handling uses the value; clarify whether this is intentional stub behavior or apply the size constraints the API requires.

Not verified

No build, test, or convention command was run. files.json was not available through the reader listing; the manifest lists three changed files, and all three were read. Repository behavior beyond the reviewed source ranges was not verified.

To get this to a good state

Nothing is required. Optional: clarify the unused localSize and savedErrno handling in sceVoiceQoSWritePacket.

@Kikoarl

Kikoarl commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Rebased onto origin/main and pushed dec55eb401 wrapping every GuestWritable_nid_no_patch / CopyOut output path in GuestArena::HostWrite (including sceVoiceQoSCreateRemoteEndpoint's slot-limit path), removing the unused savedErrno in sceVoiceQoSWritePacket, adding write-watched page test coverage in GuestVoiceQoS.cpp, and updating the debt fragment (## change [VoiceQoS endpoint ID guest outputs]) with Closes when: and Labels:.

@Kikoarl
Kikoarl force-pushed the fix/voiceqos-output-pointer-safety branch from b63d118 to dec55eb Compare November 24, 2026 18:12
@Kikoarl
Kikoarl force-pushed the fix/voiceqos-output-pointer-safety branch from dec55eb to 74e67e3 Compare November 24, 2026 19:37
@Kikoarl

Kikoarl commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Updated and rebased onto origin/main (5f04682cef) as 74e67e3eb9: upgraded GuestVoiceQoS.cpp to use armed GuestArena write-watched pages (PAGE_READONLY assertion on Windows, GuestArenaCollectWrites / GuestWriteWatchCollect dirty-page verification across all paths including the endpoint-limit case) plus 0x02 read-only refusal checks. Verified 2/2 guest_voice_qos* CTests plus debt_fold.py --check and check_conventions.py.

@MarcZX10 MarcZX10 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.

Reviewed — looks good

The inspected changes implement checked guest memory access for VoiceQoS outputs and add focused coverage; no verified defect blocks merging.

What I ran

Reviewed head 74e67e3eb9bf1cafc50c8a90043ac797b3b39ce7 using repo_read.py and the prepared review bundle. No build or tests were run.

Results

Check Result Note
Diff and changed files passed All three changed files read
Targeted helper context passed Host-write and guest-copy behavior inspected
Tests not run Only author-reported test results available

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports Linux x86_64 Release tests and convention checks passed; these were not run during this review. Windows behavior, physical-console behavior, and the full build were not verified. Files read: core/libs/prx/libSceVoiceQoS/Export.cpp, core/libs/tests/GuestVoiceQoS.cpp, docs/dev/debt/changes/fix-voiceqos-output-pointer-safety.md, core/libs/prx/libc/include/GuestArena.hpp, core/libs/prx/libc/src/General.cpp, and core/libs/prx/libc/src/GuestArena.cpp. No changed files were excluded; all three reviewed files were included in the manifest.

To get this to a good state

Nothing is required.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for the work. I'm closing this because main already returns the same error from its checked copies, so the added up-front probes mostly repeat them, and sceVoiceQoSWritePacket would gain an unmeasured error where main returns success.

If you have console evidence for that answer, or a case main still crashes on, say so and I'll reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants