Skip to content

fix(libkernel): copy sceKernelDebugOutText's text in through a checked guest copy - #23158

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/kernel-debug-out-text-guest-copy
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/kernel-debug-out-text-guest-copy

Conversation

@milescoviello

@milescoviello milescoviello commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelDebugOutText built its [debug:N] line with "... " + text and, without a host stderr descriptor, printed text with fprintf. Both read the caller's string through the guest pointer, so an unmapped text crashed the host.

Changes:

  • The text is copied in once with CopyGuestString_nid_no_patch, up to 64 KiB. Text with no terminator within 64 KiB is read as its first 64 KiB with one GuestCopyIn_nid_no_patch, so very long text is cut there instead of read to its end.
  • Both output paths use the copy.
  • An unreadable text returns 0x8002000e (EFAULT), the result a null text already gets.

Output for readable text is unchanged.

Tested

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

  • guest_filesystem gains an unmapped (0x10) text next to the existing null-text check; it returns 0x8002000e.
  • guest_filesystem passes, 3 runs, on a6ef3b5f34, the pre-squash commit with this tree.
  • Negative control: the same tree with main's Notification.cpp ends guest_filesystem in fatal SIGSEGV (code 1) at address 0x0000000000000010.

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

  • guest_filesystem passes, 3 runs, on a6ef3b5f34.
  • Negative control: main with only the new test (36075b4f22) ends guest_filesystem in an access violation (0xc0000005).

Both:

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

…d guest copy

sceKernelDebugOutText appended the caller's text to its output line and
passed it to fprintf through the guest pointer, so an unmapped text
crashed the host. It now copies the text in with
CopyGuestString_nid_no_patch (up to 64 KiB; longer text is cut there) and
prints the copy. An unreadable text returns 0x8002000e, as a null one
does.

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 20b00d1b3e:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_filesystem_tests built cleanly.
  • CTest (guest_filesystem):
    1/1 Test #5415: guest_filesystem .................   Passed    0.14 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/System/src/Notification.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5415: guest_filesystem .................***Exception: SegFault  0.52 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Validated CopyGuestString_nid_no_patch error handling: return code 63 (ENAMETOOLONG) triggers fallback GuestCopyIn_nid_no_patch of DebugTextLimit (64 KiB), while any other non-zero error returns 0x8002000e (EFAULT).
    • Verified guest pointer validation: nullptr check precedes guest copy, and unmapped/invalid guest addresses return 0x8002000e (EFAULT) matching existing null-pointer handling.
    • Audited channel check: negative channel values return 0x80020016 (EINVAL) before attempting guest string copies.
    • Checked output formatting and mutex concurrency: outputMutex guards File::HostStandardError and std::fprintf/std::fflush calls, output string uses copied guest buffer safely without out-of-bounds reads.
    • Verified AGENTS.md compliance: no unauthorized comments in code, technical debt fragment correctly added under docs/dev/debt/changes/fix-kernel-debug-out-text-guest-copy.md.

Looks Good To Me

@github-actions

github-actions Bot commented Nov 19, 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 9371 core/libs/tests/GuestFilesystem.cpp
PR 15037 core/libs/tests/GuestFilesystem.cpp
PR 25495 core/libs/tests/GuestFilesystem.cpp

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 20b00d1b3e, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#24576, #24603, #14196, #14527, #17718, #18671, #22753, #22792, #23503, #24245, #24480, #24553, #24714, #21236, #21765, #21987, #22030, #22107, #22397, #22571, #23816, #24067, #18401, #19101, #19398, #19657, #21563, #24584, #24628). 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_filesystem, guest_filesystem_error (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 (6523 tests) on the RTX 3080 has 7 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, agc_driver_store_over_untracked, agc_storage_write_back_host_retile. Traced to other PRs of the batch, each by reverting it and testing again: #19101 (guest_video_out_window_margins_bounds); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): agc_driver_image_gather_lod. The 2125 agc_/video tests on the iGPU have 5 failing: agc_driver_image_gather_lod, agc_driver_stencil_plane_memory, agc_driver_store_over_untracked, agc_storage_write_back_host_retile, guest_video_out_window_margins_bounds (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_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 — no blocking findings

The checked copy protects both output paths from directly dereferencing an unreadable guest string; I did not run tests or verify the helper’s return-code contract.

What I ran

Read the prepared diff and all changed files at head 20b00d1b3ed90a8f67b65ad042a9348a10649b76. No commands or tests were run.

Results

Check Result Note
Changed-file review passed All three changed files read
Tests not run Author-reported runs not independently verified
Helper return contract not run Numeric truncation code not confirmed

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • The implementation of CopyGuestString_nid_no_patch and whether return value 63 reliably means the string reached the 64 KiB limit.
  • Test execution and behavior on Linux, Windows, or console hardware.
  • files.json was not available through the reader; manifest lists all three changed files as included, and each was read: core/libs/prx/libkernel/System/src/Notification.cpp, core/libs/tests/GuestFilesystem.cpp, and docs/dev/debt/changes/fix-kernel-debug-out-text-guest-copy.md.

To get this to a good state

Nothing is required.

@milescoviello

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Thanks for the review. On the return contract: on main at 1d1587ced3, CopyGuestString_nid_no_patch returns 0 when it finds the terminating NUL inside the limit, 14 when a page is unreadable, 12 when the allocation fails, and 63 only after it has copied all maximum bytes without finding a NUL. So 63 here means the first 64 KiB were readable and contain no NUL, and the fallback copies exactly those 64 KiB with GuestCopyIn_nid_no_patch.

@oneandonlydean
oneandonlydean merged commit 05cf001 into boykopovar:main Nov 27, 2026
16 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