Skip to content

fix(libSceAudioOut): copy volume array elements through GuestCopyIn - #29179

Closed
Sheikh-Bilal65 wants to merge 1 commit into
boykopovar:mainfrom
Sheikh-Bilal65:fix/audioout-set-volume-guest-copy
Closed

Sheikh-Bilal65 wants to merge 1 commit into
boykopovar:mainfrom
Sheikh-Bilal65:fix/audioout-set-volume-guest-copy

Conversation

@Sheikh-Bilal65

@Sheikh-Bilal65 Sheikh-Bilal65 commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

What

Copy selected vol entries via GuestCopyIn_nid_no_patch before mutating port->volume (returning -2144993276 and preserving errno on invalid pointers) in sceAudioOutSetVolume, and add unmapped and page-boundary volume tests in GuestAudioOutVolumeBounds.cpp.

Tested

MSYS2 g++ -std=c++23 -Wall -Wextra (-Werror on GuestAudioOutVolumeBounds.cpp, zero new warnings on AudioOut.cpp), guest_pointer_audit.py, debt_fold.py --check, and check_conventions.py passed locally; runtime CTest execution pending CI.

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

Summary by CodeRabbit

  • Bug Fixes
    • Audio volume updates now handle invalid or inaccessible input memory safely, returning an invalid-pointer error instead of applying incomplete values.
    • If a volume update cannot read all selected values, the port’s existing volume settings remain unchanged.
    • Volume updates preserve the caller’s errno value when input reads fail.

@coderabbitai

coderabbitai Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Audio volume pointer handling

Layer / File(s) Summary
Guarded volume reads and validation
core/libs/prx/libSceAudioOut/src/AudioOut.cpp, core/libs/tests/GuestAudioOutVolumeBounds.cpp
The setter stages selected volume values from guarded guest-memory reads and returns an error if a read fails. Tests verify invalid-pointer handling, protected-page boundary behavior for channel masks 0x10 and 0x0F, and preservation of errno.

Possibly related issues

  • Issue 19123 describes guest-pointer parameters that are accessed without guarded copy helpers. This change applies that pattern to the volume array in sceAudioOutSetVolume.

Possibly related PRs

  • boykopovar/AnyPS5#16597: Both changes alter how sceAudioOutSetVolume validates or reads selected volume entries before storing them.

Suggested reviewers: boykopovar, xxpbsxx, marczx10

Change: Bug fix

Merge Risk: Minimal · up to 13e16

sceAudioOutSetVolume now rejects unreadable volume pointers with an error and leaves the port's volume unchanged. No merge-blocking risk was identified.

Security architecture risk: Minimal · up to 13e16

libSceAudioOut now rejects unreadable volume inputs without partially changing the port. The change keeps the existing API and port ownership, and the inspected behavior does not establish a new material security risk.

Security review details

Security Blast Radius

  • observed — The modified path is reached through the existing volume setter. The guest supplies a handle, mask, and input pointer; the setter retains the existing port lookup and its write destination is the volume array of that port.

Trust Boundaries and Controls

  • observed — libSceAudioOut enforces the commit decision: libc must report a complete copy of each selected value before the setter changes port state. The helper does not grant port authority or establish a single snapshot of all guest values.

Dependencies

  • observed — AudioOut now calls libc's GuestCopyIn while holding the audio mutex. If libSceAgcDriver has registered its host-read hook, GuestArena invokes it before attempting the copy; that hook runs any configured read guard and then calls FlushGpuWrites.

Data and control flow

  • observed — After resolving the port under the mutex, AudioOut copies only the entries selected by the guest mask into local storage. It writes only those channels after all selected copies succeed; unselected entries need not be readable.

Resilience and Maintainability Implications

  • observed — When a guarded copy returns false, the caller gets the invalid-pointer result with errno preserved. No channel has been written, so a retry needs no volume rollback. This guarantee covers port volume, not work already performed by the host-read hook. A C++ exception during a read also precedes the commit and unwinds the audio lock, but is not translated by this setter into the invalid-pointer result.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 2
  • Waived: $0.50 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d2d18b0f-bfe7-408c-a903-ccd9101f3533
Commits

Reviewing files that changed from the base of the PR and between 9cd7bea and 13e16ae.

Files selected for processing: 2

  • core/libs/prx/libSceAudioOut/src/AudioOut.cpp
  • core/libs/tests/GuestAudioOutVolumeBounds.cpp

Limit details: You’ve used all 10 included reviews currently available.

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

Could we test that a failed volume update leaves every channel unchanged? The setter stages the new gains before applying them, but the new fixture checks the return code and errno without checking the gains afterward. A unit test with an injected copy failure can assert the old gains are still in place. That would catch a regression back to applying each gain as it is read.

@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 change safely stages selected volume reads before updating the port, and I found no blocking defects.

What I ran

Reviewed head 13e16ae344f67a9c4918b32c8fbeb4734b8dce86. I read the prepared description, commits, manifest, diff, and both changed files; used repo_read.py to inspect the changed function and relevant channel definitions. I did not run tests or compile anything.

cat description.md commits.md manifest.json diff.patch files.json
rg --files files
python3 repo_read.py cat core/libs/prx/libSceAudioOut/src/AudioOut.cpp 660 730
python3 repo_read.py cat core/libs/prx/libSceAudioOut/src/AudioOut.cpp 1 190
python3 repo_read.py cat core/libs/prx/libc/src/General.cpp 1108 1120

Files read: core/libs/prx/libSceAudioOut/src/AudioOut.cpp and core/libs/tests/GuestAudioOutVolumeBounds.cpp. files.json lists no excluded files.

Results

Check Result Note
Source review passed Staged updates preserve existing values on copy failure
Runtime tests not run CI execution was pending per the description
Compilation not run No build or compile was requested

Negative control

Not run; no test execution was performed.

Findings

Blocking

None.

Non-blocking

  • core/libs/tests/GuestAudioOutVolumeBounds.cpp:139 checks the invalid-pointer result and errno, but does not assert that the port's existing volume settings remain unchanged after the failed read. Consider checking the state after this call to directly cover the transactional behavior described in the PR.

Sources

Not verified

Runtime CTest behavior and platform-specific execution were not verified. The PR description reports local compiler and script checks; I did not run them.

To get this to a good state

Nothing required.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 12863 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 18272 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
core/libs/tests/GuestAudioOutVolumeBounds.cpp
PR 18431 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 20630 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 22585 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 24296 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 27628 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 28140 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 28597 core/libs/prx/libSceAudioOut/src/AudioOut.cpp

@Sheikh-Bilal65

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #24632, which has been rebased onto main with per-channel GuestCopyIn staging and unchanged-gain checks.

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

Labels

needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants