Skip to content

fix(libSceAudiodecCpu): probe guest size-query pointers - #20388

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
hyvvs:fix/worker32-fourth-guest-safety-nov15
Nov 15, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
hyvvs:fix/worker32-fourth-guest-safety-nov15

Conversation

@hyvvs

@hyvvs hyvvs commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What

Both sceAudiodecCpuQueryMemSize and sceAudiodecCpuInternalQueryMemSize dereferenced the guest-supplied decoder control and work-memory descriptor directly, then wrote ui_memory_size directly. A non-null unmapped control pointer (0x10) crashed the host before the query could return. Valid Blu-ray and DVD LPCM queries already have a 0x190138-byte result and specific null, descriptor-size and codec validation behavior covered by the existing library test.

Probe exactly the fields this query needs with GuestCopyIn_nid_no_patch (the control's pParam and the memory descriptor's ui_size), and write only ui_memory_size through GuestCopyOut_nid_no_patch, preserving errno. Keep the original null/size/type check order and result bytes. An inaccessible non-null guest pointer now throws std::runtime_error rather than asserting any unmeasured console error code. A library-local CMake file registers the focused test without changing the large shared root CMake file. Document the safety fallback through a valid technical-debt fragment, with no direct debt-file edit. Decode/initialization paths are not changed.

Tested

  • Untouched production negative control: WSL Ubuntu 24.04, GCC 13.3, -fsanitize=address,undefined -fno-omit-frame-pointer -ffunction-sections -fdata-sections -Wl,--gc-sections, linking the new core/libs/tests/GuestAudiodecCpuQueryGuest.cpp directly against the original core/libs/prx/libSceAudiodecCpu/Export.cpp and actual libc/src/General.cpp, GuestArena.cpp, GuestWriteWatch.cpp. AddressSanitizer aborted on a READ at 0x10, in QueryMemSize, Export.cpp:156, reached from sceAudiodecCpuQueryMemSize. Reproduced with the final unchanged regression using the unmodified copy of Export.cpp in a separate untouched worktree.
  • Patched focused regression PASS, directly linked to the real production files under the same GCC 13 ASan/UBSan flags: unmapped control/descriptor pointers, preserved errno, null/size/type validation precedence, unchanged 0x190138-byte outputs through both public/internal query aliases, preservation of other output fields, valid descriptors abutting a guard page, writes crossing into a protected page, and read-only output rejection.
  • Existing full GuestAudiodecCpu.cpp suite PASS under GCC 13 ASan/UBSan linked to the patched production Export.cpp and the same real libc guest-memory helpers. This exercises the existing decoder, work-memory query, format and LPCM output tests, not just the new focused test. Standalone harnesses use an external no-op missing-function reporting shim solely for linking; the production NotImplementedAt throw and guest-copy implementations are unchanged.
  • Windows MinGW-w64 GCC 15.2.0: g++ -std=c++20 -Wall -Wextra -Werror -fsyntax-only -Icore/libs -Icore passed on both production Export.cpp and new GuestAudiodecCpuQueryGuest.cpp.
  • python tools/check_conventions.py --base upstream/main, python tools/debt_fold.py --check, and git diff HEAD^ HEAD --check passed. The independent library-name overlap scan found no competing query implementation among 1,530 open PRs; the complete post-rebase branch overlap scan of 1,508 open PRs returned No overlap. Prior closed/merged libSceAudiodecCpu work (test(libSceAudiodecCpu): cover internal API parameter validation and error states #17324, feat(libSceAudiodecCpu): wrap Blu-ray LPCM output past the module's 0x43800-byte buffer #17649) was screened; neither implemented this guest-memory check. An initial root-CMake test registration failed the full overlap scan; it was removed before this PR, and the clean scan was repeated against the library-local registration.
  • Full WSL CMake configuration (-DANYPS5_USE_SYSTEM_DEPS=ON -DBUILD_TESTING=ON) was blocked before target generation by missing SDL2Config.cmake; full module-loading CTest and actual PS5/game testing were not performed. WSL's guest-write watch reported its existing memory-comparison fallback when asynchronous userfaultfd write protection was unavailable.

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

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

Review in progress — reader access unavailable

I could not inspect the prepared review folder or repository because the provided reader command could not be run in this environment.

What I ran

  • Attempted to invoke repo_read.py through the available tool interface; the command runner was unavailable.

Results

Check Result Note
Review materials not run Reader access unavailable

Findings

Blocking

None verified.

Non-blocking

None.

Not verified

The change description, commits, diff, manifest, changed files, and repository context were not read. No files can be reported as reviewed.

To get this to a good state

Provide a working reader interface so the pinned change can be inspected.

@oneandonlydean
oneandonlydean merged commit 4da77d3 into boykopovar:main Nov 15, 2026
14 checks passed
@MarcZX10

Copy link
Copy Markdown
Contributor

Withdrawn: the automated review posted on this pull request (review 5909104210 or 5910118205 respectively) was sent by mistake. It did not complete and reports no finding. Please disregard it.

@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 — no blocking findings

The change adds guest-memory checks to the two audiodec memory-size queries, and I found no blocking defect when reading the reviewed head.

What I ran

  • Head reviewed: 5ab1cf0 (merged).
  • Read the four changed files at that head and the diff.
  • Checked the GuestCopyIn/GuestCopyOut declarations (argument order matches), the AudiodecCtrl and AudiodecCpuMemory layouts (the first fields are the ones read), and the repository conventions for throwing on unreadable guest memory and for library-local CMake registration.
  • Did not build or run tests. The precheck refuses closed pull requests and did not run.

Results

Check Result Note
Source review passed Null, size and type check order kept
Guest copy argument order passed Matches the declarations
Struct layouts passed Read fields are first in their structs
Repository conventions passed Library-local CMake and debt fragment
Build and runtime tests not run Not built here
Hosted CI passed 7 success, 7 skipped
Precheck not applicable Pull request is closed

Findings

Blocking

None.

Non-blocking

  • A bad control or descriptor pointer now throws std::runtime_error (Export.cpp lines 162, 168, 176) instead of faulting the host. The repository uses the same pattern for guest memory, but the export trampoline's handling of the exception was not checked.

Sources

  • QueryMemSize:
    int QueryMemSize(const char* function, const AudiodecCtrl* ctrl, AudiodecCpuMemory* memory, std::uint32_t type) {
    if (!ctrl) return ErrorCtrl;
    const int savedErrno = errno;
    const void* param = nullptr;
    const bool readableCtrl = GuestCopyIn_nid_no_patch(&param, ctrl, sizeof(param));
    errno = savedErrno;
    if (!readableCtrl) throw std::runtime_error("sceAudiodecCpuQueryMemSize: unreadable control pointer");
    if (!param) return ErrorParam;
    if (!memory) return ErrorMemory;
    std::uint32_t memorySize = 0;
    const bool readableSize = GuestCopyIn_nid_no_patch(&memorySize, memory, sizeof(memorySize));
    errno = savedErrno;
    if (!readableSize) throw std::runtime_error("sceAudiodecCpuQueryMemSize: unreadable memory descriptor");
    if (memorySize != StructSize) return ErrorMemorySize;
    if (!KnownType(type)) return ErrorType;
    if (!Lpcm(type)) UnknownCodec(function, type);
    const std::uint32_t outputSize = LpcmMemorySize;
    auto* destination = reinterpret_cast<std::uint8_t*>(memory) + offsetof(AudiodecCpuMemory, ui_memory_size);
    const bool writableSize = GuestCopyOut_nid_no_patch(destination, &outputSize, sizeof(outputSize));
    errno = savedErrno;
    if (!writableSize) throw std::runtime_error("sceAudiodecCpuQueryMemSize: unwritable memory-size output");
    return 0;
  • GuestCopyIn/Out declarations:
    extern "C" bool GuestCopyOut_nid_no_patch(void* destination, const void* source, std::size_t bytes);
    extern "C" bool GuestCopyIn_nid_no_patch(void* destination, const void* source, std::size_t bytes);
  • AudiodecCpuMemory:
    struct AudiodecCpuMemory {
    std::uint32_t ui_size;
    void* p_memory;
    std::uint32_t ui_memory_size;
    };
  • AudiodecCtrl:
    struct AudiodecCtrl {
    void* pParam;
    void* pBsiInfo;
    AudiodecAuInfo* pAuInfo;
    AudiodecPcmItem* pPcmItem;
    };

Not verified

  • Build, the focused regression test and the existing AudiodecCpu suite were not run here. The ASan results are the author's.
  • Exception handling at the export boundary.

To get this to a good state

Not applicable: the pull request is merged.

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.

3 participants