Skip to content

fix(libc): write std::__sce_v2::filesystem::_Current_get's path through a checked guest copy - #22938

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/libc-sce-v2-current-get-guest-copy
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/libc-sce-v2-current-get-guest-copy

Conversation

@milescoviello

@milescoviello milescoviello commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

std::__sce_v2::filesystem::_Current_get stored the sandbox root / and its terminator through the caller's 260-byte buffer, so an unmapped or read-only buffer crashed the host.

Changes:

  • Both bytes are written with one GuestCopyOut_nid_no_patch.
  • A buffer that can't be written returns false, the function's existing failure result, and errno is kept.

The result for a valid buffer is unchanged. It still writes exactly two bytes, as the existing check pins.

Tested

Windows 11 VM (GeForce GT 1030, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release):

  • guest_sce_v2_filesystem gains an unmapped buffer (0x10), which returns false.
  • guest_sce_v2_filesystem passes, 3 runs, on d55b17a0f1.
  • Negative control: main with only the new check (eef55a4b23) ends guest_sce_v2_filesystem in an access violation (0xc0000005).
  • git merge-tree against main is clean. fix(libc): keep UNC host paths on their share on Windows #19652 also edits VersionedFilesystem.cpp, not this function; git merge-tree of this branch with it is clean. No open PR edits the test file.
  • tools/check_conventions.py passes on the branch and this body. tools/debt_fold.py --check reports nothing for this fragment.

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

  • guest_sce_v2_filesystem passes, 3 runs, on a725a55a9c (this PR's head).
  • Negative control: the same tree with main's source file ends guest_sce_v2_filesystem in SIGSEGV at address 0x10.
  • kiwe147's batch run of a725a55a9c, applied with other PRs onto main fd4aeed483 (one combined tree, not this PR alone), Windows 11, WinLibs GCC 15.2.0 r7, Release, no validation layer: guest_sce_v2_filesystem and guest_sce_v2_filesystem_calls pass on an NVIDIA GeForce RTX 3080 (driver 621.24).

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

…gh a checked guest copy

std::__sce_v2::filesystem::_Current_get stored the sandbox root "/" and
its terminator through the caller's pointer, so an unmapped or
read-only buffer crashed the host. Both bytes are now written with one
GuestCopyOut_nid_no_patch, and the function returns false, keeping
errno, when the buffer can't be written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 a725a55a9c:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_sce_v2_filesystem_tests built cleanly.
  • CTest (guest_sce_v2_filesystem):
    1/1 Test #1062: guest_sce_v2_filesystem ..........   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/VersionedFilesystem.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #1062: guest_sce_v2_filesystem ..........***Exception: SegFault  0.41 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified that GuestCopyOut_nid_no_patch is correctly used with target, root, and sizeof(root) (2 bytes including null terminator), safely handling unwritable guest pointers without host crash.
    • Verified that errno is preserved across GuestCopyOut_nid_no_patch via savedErrno, maintaining expected libc errno state on error.
    • Verified that the technical debt fragment in docs/dev/debt/changes/fix-libc-sce-v2-current-get-guest-copy.md follows the required schema, correctly documents the fallback, and passes debt check tools.
    • Verified that the unit test in core/libs/tests/GuestSceV2Filesystem.cpp exercises both the valid buffer path and the unwritable buffer path (0x10) without regressions.
    • Verified compliance with AGENTS.md: no illegal comments, no hardcoded magic game paths, clean conventions check, and clean git diff.

Looks Good To Me

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head a725a55a9c, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#24470, #24601, #17439, #17546, #21117, #21261, #21741, #21995, #22067, #22398, #23111, #23346, #23864, #24377, #24475, #24556, #14106, #14109, #19966, #20050, #20161, #20622, #21237, #22215, #22764, #22884, #23745, #24399, #24460). 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_sce_v2_filesystem, guest_sce_v2_filesystem_calls (2 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6525 tests) on the RTX 3080 has 5 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. Traced to other PRs of the batch, each by reverting it and testing again: #21117 (guest_pad); none is in this PR's area. The 2125 agc_/video tests on the iGPU have 1 failing: agc_driver_stencil_plane_memory (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)

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @kiwe147 for including this one in the batch. The guest_sce_v2_filesystem tests passing is a useful Windows data point, and I added it to the description, noted as a combined batch tree rather than this PR alone.

@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 uses the checked guest copy for the two output bytes, returns its failure result, and preserves errno; the inspected source supports merging.

What I ran

Reviewed head a725a55a9c1eec709ecdb9b95877b31d0818c602. No commands or tests were run; repo_read.py was unavailable as an executable tool here. The author reports tests, but those were not run in this review.

Read the prepared description, commits, manifest, diff, all three changed files, and the relevant GuestCopyOut_nid_no_patch implementation in General.cpp. No changed files were excluded.

Results

Check Result Note
Source review passed All changed files and copy helper read
Tests not run Author reports runs on Windows and Linux
Negative control not run Author reports a Linux negative control

Findings

Blocking

None.

Non-blocking

None.

Not verified

Runtime behavior and reported test runs were not independently verified. No files from files.json were available to inspect; the manifest lists three changed files, and all three were read from the pinned head.

To get this to a good state

Nothing is required.

@oneandonlydean
oneandonlydean merged commit e2ea797 into boykopovar:main Nov 27, 2026
26 checks passed
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.

5 participants