Repository navigation
fix(libkernel): copy sceKernelDebugOutText's text in through a checked guest copy - #23158
Conversation
…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
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 20b00d1b3e:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_filesystem_testsbuilt 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.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #5415: guest_filesystem .................***Exception: SegFault 0.52 sec 0% tests passed, 1 tests failed out of 1 - 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
|
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.
|
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
|
Thanks @kiwe147 for including this one in the batch. The |
MarcZX10
left a comment
There was a problem hiding this comment.
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_patchand whether return value63reliably means the string reached the 64 KiB limit. - Test execution and behavior on Linux, Windows, or console hardware.
files.jsonwas 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, anddocs/dev/debt/changes/fix-kernel-debug-out-text-guest-copy.md.
To get this to a good state
Nothing is required.
|
@MarcZX10 Thanks for the review. On the return contract: on |
What
sceKernelDebugOutTextbuilt its[debug:N]line with"... " + textand, without a host stderr descriptor, printedtextwithfprintf. Both read the caller's string through the guest pointer, so an unmapped text crashed the host.Changes:
CopyGuestString_nid_no_patch, up to 64 KiB. Text with no terminator within 64 KiB is read as its first 64 KiB with oneGuestCopyIn_nid_no_patch, so very long text is cut there instead of read to its end.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_filesystemgains an unmapped (0x10) text next to the existing null-text check; it returns0x8002000e.guest_filesystempasses, 3 runs, ona6ef3b5f34, the pre-squash commit with this tree.main'sNotification.cppendsguest_filesysteminfatal SIGSEGV (code 1) at address 0x0000000000000010.Windows 11 VM (GeForce GT 1030, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release):
guest_filesystempasses, 3 runs, ona6ef3b5f34.mainwith only the new test (36075b4f22) endsguest_filesystemin an access violation (0xc0000005).Both:
git merge-treeagainstmain92231f2168is clean. It is also clean with fix(libc): keep errno unchanged when getc and putc fail on a stream of the wrong mode #22696, fix(libc): keep UNC host paths on their share on Windows #19652 and fix(libc): follow a Windows symbolic link before .. in a guest path #9371, which edit the test file. feat(libkernel_sys): implement mount, unmount and nmount privilege checks #15037 already conflicts withmain, and this adds no conflict to it.tools/check_conventions.pypasses on the branch and this body.tools/debt_fold.py --checkreports nothing for this fragment.20b00d1b3e, applied with other PRs ontomainfd4aeed483(one combined tree, not this PR alone), Windows 11, WinLibs GCC 15.2.0 r7, Release, no validation layer:guest_filesystemandguest_filesystem_errorpass on an NVIDIA GeForce RTX 3080 (driver 621.24).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)