fix(kernel): safely copy guest path arguments #9423
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9423"
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 AliZedan1A on 2026-10-21T21:30:19Z.
What
Snapshot guest path strings through checked host reads before syscall wrappers inspect or resolve them. Unreadable pointers now return guest
EFAULT, unterminated 1024-byte paths returnENAMETOOLONG, and two-path calls preserve source-before-destination validation order. Add cross-platform guard-page coverage for boundary lengths, relative*atcalls, error precedence, and filesystem side effects.The overlap check reports line conflicts with several unrelated filesystem PRs. In particular, #8723 adds a symlink target length check that is also enforced by the checked 1024-byte snapshot here; this PR does not depend on it. #9442 will follow this PR and retain checked path copying in its shared
chflags/lchflagshelper.Tested
Linux x86-64, head
f552230adrebased ontomain8b3e39832:guest_kernel_sys_tests,guest_filesystem_tests,guest_path_errors_tests,guest_kernel_rename_tests,guest_rename_dot_tests,guest_posix_scalar_io_tests, andagc_driver_storage_file_write_testswith GCC 16.2.1, Release,BUILD_TESTING=ON.ctest --test-dir build-pr-9423 -R "^guest_(filesystem|path_errors|kernel_rename|rename_dot|posix_scalar_io|kernel_sys)$" --repeat until-fail:3 --output-on-failure: 6/6 passed on all three runs.agc_driver_storage_file_writepassed on all three runs withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationon an NVIDIA GeForce RTX 3050 Laptop GPU. The verbose log had no missing-layer message orVUID-validation errors.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch fix/guest-path-efault: refreshed; only known shared-file overlaps remain.git diff --check origin/main...HEAD: passed.4d7b47abe7and old base.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)Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T22:41:38Z.
Windows run of 4d7b47abe7 merged onto
maina6dcea9279(3393625503, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON.Built
libc,libkernel,libkernel_sysandguest_kernel_sys_testswith no errors or warnings.ctest --repeat until-fail:2onguest_kernel_sys: passes on both repeats. Not run: a title.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:40:08Z.
Windows run of the wider related set, a negative check, and the path exports this doesn't cover yet.
Head
4d7b47abe7merged onto maina6dcea927(clean). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release,BUILD_TESTING=ON.guest_kernel_sys,guest_filesystem,guest_kernel_rename,guest_rename_dot,guest_posix_scalar_io: 5/5, 3 runs. (guest_path_errorsis UNIX-only.)check_conventions.py --base a6dcea927: passes.Probe, with an unreadable page (
VirtualAllocPAGE_NOACCESS) as the path:statEFAULT0xc0000005)access(libcFilesystem.cpp)chdir(libcGeneral.cpp)remove(libcFilesystem.cpp)opendir(libcDirectory.cpp)So the fix works where it is applied. The libc path exports
access,chdir,remove,opendirandrealpathstill read the guest string directly. That may be out of scope here, but the title promises guest path arguments in general.Cost: 20,000
statcalls on an existing file average 85-90 µs on the PR and 84-86 µs on main (14-byte path), and 286-312 µs vs 306-310 µs on a 200-byte missing path, three rounds each. That is within run-to-run noise, so theReadProcessMemorycopy doesn't show.On the claims: 1024 bytes without a NUL gives
ENAMETOOLONGand 1023 bytes is accepted, as FreeBSD'snameicopyinstr(..., MAXPATHLEN)does. The new order inlinkandrenameat(source looked up before the destination string is copied) matcheskern_linkatandkern_renameat. The copy is per page, so a string that ends right before an unreadable page is accepted (the test'sBoundarycase passes here).AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:36:10Z.
The current overlap scan and manual diff review show that #9442 refactors
chflagsinStdio.cppwhile #9423 changes the sharedPathErrorcontract and updateschflagsto copy guest path input. Please coordinate with #9442’s author on order and confirm that the final code retains both checked path copying and the new no-followlchflagspath; record a dependency if one must land first.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:57:04Z.
Review: DISMISSED
The focused guard-page coverage and the Windows/Linux runs reported on this PR are useful, but this branch is still based on merge base
0c6a5bd5938f; currentmainis524398151f1e. GitHub reports the comparison as diverged, 417 commits behind and 1 ahead. The repository contribution rules require PR branches to stay current withmain, and the hosted checks shown here are only conventions, intake and labels; no product build/test run is reported for this head.Please rebase onto current
main, refresh the overlap report and resolve any remaining shared-file ordering with the affected authors (including the existingStdio.cpp/chflagscoordination with #9442), then rerun the focused path tests on the rebased head and update the tested-base/CI report. The already reported Linux and Windows results are on the old base and should remain identified as such. I did not run local tests in this pass because there is no matching configured build for this PR head.Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T06:49:08Z.
#9442 (
lchflags) moves the body ofchflags_nid_postfixinStdio.cppinto a sharedChangeFileFlags_nid_no_patch(function, path, flags, follow), so it overlaps thePathErrorchange here. I suggest this PR lands first, since it covers many callers; I will then rebase #9442 so the helper keeps the copied path (std::string copy; PathError(path, copy); path = copy.c_str();) for bothchflagsandlchflags. If #9442 happens to land first, the change on your side is that one call moved into the helper. Does that order work for you? (#9469 changesLookupErrornext to it, notchflags, so it does not overlap this PR.)Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:49:34Z.
Update: #9442 and #9693 will both go after this PR. #9693 now uses
CopyGuestPath_nid_no_patchfor thesetloginname, so it carries this PR's commit until it merges; nothing is needed here.Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T12:09:42Z.
A Windows regression I hit while stacking #9693 on this PR:
agc_driver_storage_file_writepasses onmain8b3a6ba88and fails with only this PR's commit on top (3 runs out of 3; Windows 11, MinGW-w64 GCC 15.2.0 r7, Release). It stops inCheckShutdownAndGuard(core/libs/prx/libSceAgcDriver/tests/execution/StorageFileWrite.cpp) with the uncaught exceptionfile source read guard.The test installs
AgcDriver::GuestMemory::SetReadGuardwith a guard that throws for any read, then callsfile.Open()before itstryaroundsceKernelWrite. With this PR,opencopies the path throughCopyGuestBytes, which callsGuestArenaPrepareHostRead_nid_no_patch, so the AGC read hook now runs for the path copy and the guard throws out ofOpen(). Onmainthe path is not read through that hook, so the guard only meets thesceKernelWritesource as intended.Not checked: Linux. Full suite with this PR plus #9693's two
setlogincommits (which only touch the login code) onmain8b3a6ba88: 1892 tests, the same results asmainapart from this one.Imported from boykopovar/AnyPS5. Originally posted by AliZedan1A on 2026-10-22T13:58:48Z.
@MarcZX10 Rebased onto
main8b3e39832and pushed headf552230ad. Theagc_driver_storage_file_writeregression is fixed by opening the output before installing the source-read guard, while checked path reads continue through the host-read hook. The six focused path tests and the AGC regression test each passed three runs on Linux; conventions, overlap, and diff checks pass. The PR description now records the exact commands, base, GPU, and validation result. Ready for re-review.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-22T23:58:09Z.
Review: CHANGES_REQUESTED
Head
4e2119bfbstill merges cleanly onto currentmain, with one gap:mainnow haslchmod(#9200), andlchmod_nid_postfixincore/libs/prx/libkernel_sys/Export.cpp(~line 579) dereferences*pathand passes the raw pointer toResolvePathError_nid_no_patchbefore callingfchmodat_nid_postfix. An unreadable non-null pointer faults the host there, which is what this PR closes for the other path wrappers.CopyPathat the top oflchmod_nid_postfix(returnFail(error)), and use the copy for the empty-string check and the resolve.lchmodrow to the guard-page test inGuestKernelSys.cpp.accessinlibc/Filesystem.cppstays out of scope as agreed (#9368 stays open for it). @MarcZX10 your change request was about the rebase and the #9442/#9693 order, which are done; once thelchmodpoint is pushed, could you re-review?