fix(libc): keep errno when a checked guest copy faults on Linux #13664
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13664"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T22:19:07Z.
What
GuestCopyIn_nid_no_patchandGuestCopyOut_nid_no_patchreport a fault only through theirfalsereturn. On Linux they useprocess_vm_readv/process_vm_writev, which also leaveEFAULTin the hosterrno, and the guesterrnois that same variable (__errorreturns&errno). On Windows (ReadProcessMemory/VirtualQuery) and macOS (mach_vm_read_overwrite/mach_vm_write)errnois never touched. So any caller that reports the fault through a return code, and any test that checkserrnois left alone, seeserrno == 14on Linux only.The Linux paths now save
errnobefore the syscall and restore it on theEFAULTpath, so the three hosts behave the same and each caller sets the guesterrnoitself. Every current caller inmainalready does that (*__error() = 14,Fail(GuestEfault),PosixFailure(GUEST_EFAULT),Fault()), returns an SCE error code, or throws, so none depends on the leaked value. Non-EFAULTfailures still throw as before.libkernel has its own copies of this pattern that call
process_vm_readv/process_vm_writevdirectly, so the second commit applies the same rule to them:ReadGuest,WriteGuestandStoreGuestIdinSystem/src/Process.cpp,ReadGuest/WriteGuestinSocket/src/Udp.cpp(also exported asGuestSocketReadGuest_nid_no_patch),CopyIovecsinFile/src/Stdio.cppandReadGuestTimeinTime/Time.cpp. Their callers set the guesterrnothemselves (*__error() = 14,Fail(14),fail(NET_EFAULT)) or return an SCE code (sceKernelReadv/Writev/Preadv/Pwritev), so none depends on the leaked value either;StoreGuestId's non-EFAULTpath is unchanged. The twoprocess_vm_readvprobes in libSceAgcDriver (GuestMemory.cpp,FrameRecorder.cpp) are host-side page probes, not guest copies, and are left alone.This is the shared cause of the Linux-only failures in the "return EFAULT for invalid memory" family, for example #13577 (getlogin_r) and #13552 (system version queries): with this change their tests pass on Linux without the local
errnosave/restore suggested in their reviews.Tested
Ubuntu 26.04 x86_64, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON, basemain9605300f29(the branch was then rebased onto7fcab08f71, which changes neither touched file).guest_output_pointer_fault:GuestCopyOut/GuestCopyInon an unmapped address keeperrnoas the caller left it. Without the fix it fails 3/3 at theGuestCopyOutcheck; with only theGuestCopyOuthunk it fails 3/3 at theGuestCopyIncheck; with the fix 3/3 pass.ctest -E "^agc|gpu|vulkan|video_out"): 1853/1853 on the base and 1853/1853 with the fix.public_headerspasses;tools/check_conventions.pyclean.guest_system_configurationaborts 3/3 onmain, passes 3/3 on this branch.errno == 12345check aftergetlogin_r(0x10, size)fails 3/3 onmainand passes on this branch. Itsgetlogin_r(0x10, 1) == 14check still fails on every host (the size check runs first and returns 34); that is a test issue in #13577, not covered here.Second commit (
829f40c523), basemainc3c45d73ab, same machine:guest_output_pointer_faultgains two checks on the same unmapped addresses:GuestSocketReadGuest_nid_no_patch(Udp.cpp helpers) andsceKernelReadvwith an unreadable iovec table (Stdio.cppCopyIovecs, returns0x8002000e) keeperrno. Onmain+ the first commit it fails 3/3 at theGuestSocketReadGuestcheck; with only the Udp.cpp hunk reverted it fails 3/3 there, with only the Stdio.cpp hunk reverted it fails 3/3 at thesceKernelReadvcheck; with the commit 3/3 pass.mainand 1857/1857 onmain+ this branch.public_headerspasses;tools/check_conventions.pyclean.bed3f89b78merged on top with its localerrnosave/restore removed:guest_app_infoaborts 3/3 onmain+ the first commit only, passes 3/3 on this branch (covers the Process.cppWriteGuest). With its restore kept it passes too, and a 187-test libkernel subset (process, socket, readv/writev, time, app_info) passes.Overlap: #11281 also touches
General.cpp(it adds aGuestCopyIn_nid_no_patchthatmainalready has); #9371 and #11446 touch other functions in the same file. None changes the lines edited here.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T22:35:23Z.
Review: APPROVED
Reviewed — looks good
The Linux
EFAULTpaths now restore the caller'serrno; the new regression assertions exercise both checked-copy directions and are registered asguest_output_pointer_fault.What I ran
Reviewed head
dfb9b774fc5c58b509a4ee7f17c7868b8014230cagainst PR base7fcab08f71e463b1768730a626a0f5472d336708. The current-main merge preview was clean againste8efeed58af48d0682ab2e0eab72cfaf996e4886. Environment: Linux x86-64, Python 3.11.2; GCC 12.2 was available but not invoked. No local C++ build or test was run.Results
GuestArenaBeginHostWritereturns true and the write-watch hook is a no-op; the test's invalid addresses therefore reachprocess_vm_writev/process_vm_readv. The changed EFAULT branches restore the saved value.GuestOutputPointerFault.cppasguest_output_pointer_fault; the test-quality heuristic's unregistered-test warning is a false positive.git diff --checkexited 0; conventions passed.e8efeed58af48d0682ab2e0eab72cfaf996e4886; no declared dependency.Unedited command output
Convention check:
Test-quality heuristic:
Registration:
Merge preview:
git diff --checkemitted no output and exited 0.Precheck helper stderr:
Negative control
GuestCopyOut; with only theGuestCopyOuthunk, 3/3 failures atGuestCopyIn; with both hunks, 3/3 passes. Not independently reproduced.Findings
Blocking
None found in the reviewed change.
Non-blocking
The Linux full-suite and focused negative-control results are author-reported; Linux CI was skipped. Windows relinker and macOS checks were still pending at the last snapshot.
Sources
errnoaccessor at the reviewed headNot verified
No local build or C++ test was run. Linux, Windows relinker, and macOS hosted results were not complete/available as passed at review time. The author's Linux results were not independently reproduced.