fix(filesystem): reject invalid parent traversal on Windows #3485
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3485"
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 santhoshkumar-dev on 2026-10-11T11:25:49Z.
What
Fixes #3117. A guest path such as
missing/../present.txtcurrently reachespresent.txton Windows, so an invalid open, truncate, rename or unlink can operate on the real target. Validate the directory before removing a parent component and returnENOENTfor a missing component orENOTDIRfor a file component.Carries milescoviello's original Linux fix (
98a5a9991bf2990173d2d137515d0ef6206b2535) with authorship preserved, then adds Windows validation and error propagation. The existing branch left invalid components for the host to reject; Win32 normalizes those components again. Filesystem entry points now translate resolver failures into their guest errors. APR, AvPlayer and font loading preserve their existing failure results. A failedfreopenalso closes the original stream.The regressions check invalid and valid traversal, case matching, guest working directories, mount aliases, symlinks where available, missing-leaf creation, and preservation of existing files/directories after failed writes. Native Windows drive/UNC paths retain their existing bypass; host directory symlink parent traversal remains lexical.
Tested
Rebased on
mainat0f863c102.guest_filesystemandguest_kernel_syscases fail withmain's production files and pass with the fix.ctest: 833 of 836 pass, 5 skipped. The 3 failures (windows_exceptions,agc_driver_lds_mixed_width_atomics,agc_driver_pixel_interlock) fail the same way with this PR's 16 files reverted tomain: an exception throughstd::call_onceand two GPU results on this card.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T11:30:03Z.
Thanks @santhoshkumar-dev for carrying my commit with its authorship and adding the Windows half.
Native Linux run of this PR's head (
f50a5fa7): Gentoo, GCC 15.3.0, Release with CI's configure flags, RTX 5090 Laptop GPU.guest_filesystem,guest_kernel_sys, APR, AvPlayer, font, path, directory, stream and save-data.ctest: 829/829. I left out only the threeguest_video_out_*tests, which time out here while the laptop's displays are off.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:58:25Z.
Rebased onto current
main(the empty-path checks added tosceKernelUnlink/Rename/Rmdir/Chmod/Truncate/Statconflicted with the new resolver error handling; both kept, authorship of both commits preserved). On Linux with the PR merged ontomain: scoped build and 171 ctest tests pass. Windows is covered by the runs from the author and @Silverash-i8; merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T12:01:09Z.
@adriadam10 the
conventionsfailure here isn't from this PR. Since #3470 (ddf6b8c9),mainhas a3rdparty/imguigitlink (6d910d54) with no entry in.gitmodules. The checkout step's submodule init then fails withfatal: No url found for submodule path '3rdparty/imgui' in .gitmodules, for every PR checked againstmainsince about 11:55 (e.g.https-ca-list-stubsandDirect-Memory-Exceptionfail the same way). Removing the stray gitlink (git rm --cached 3rdparty/imgui), or adding its.gitmodulesentry if imgui is meant to be a submodule, should clear them all.Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T12:04:34Z.
Thank you all:
conventionsfailure.mainand keeping both the new empty-path checks and the resolver error handling insceKernelUnlink/Rename/Rmdir/Chmod/Truncate/Stat.missing/../present.txtstill resolved there. That is what the second commit fixes.On CI: agreed with milescoviello, the only failing check is
conventions, frommain's3rdparty/imguigitlink with no.gitmodulesentry (still missing onmainat2220effbe). Nothing in this PR touches it. I'll leave the branch as rebased (2c1eb02c6) and won't push over it. If a Windows run of the rebased head would help before merging, I can do one.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T12:14:34Z.
@santhoshkumar-dev here's a Windows run of the rebased head, since my earlier run in #3117 was only of the first commit (it showed
missing/../present.txtstill resolving, so it doesn't cover the Windows half): Windows 11, WinLibs GCC 15.2.0 r7, Release,2c1eb02cmerged ontomain2220effb, full build.guest_filesystempasses, with all the new parent-traversal checks.guest_kernel_sys, APR, AvPlayer, font, path, directory, stream and save-data tests pass (17 tests matching those).ctest -E "^agc_"): 460/462.windows_exceptionsfails as it does onmain(#3411).guest_ampr_markersfailed once and then passed 5/5 on rerun (the intermittent failure from #3371).To get there I had to add two things that aren't about this PR, because both tests fail on Windows on
mainright now:guest_filesystemaborts at the empty-path check from #3465 (Require(!restoreTimeError): MinGW can't set a directory's write time). I've opened #3518 for that.guest_kernel_sysaborts onsymlink: Function not implementedfrom #3491, which #3510 fixes. I merged #3510 for this run.Both merged onto this PR without conflicts (#3510 also changes
libkernel_sys/Export.cpp, insymlinkonly), and both failures are onmainwithout this PR.One gap, from
symlink(#3491) landing while this PR was open: the rebased branch has it, and it still callsResolvePath_nid_no_patch(created)directly, and with this PR that now throws for an invalid... With a temporary probe inguest_kernel_sys,symlink("original.bin", "<root>/missing/../probe")aborts the test with an uncaughtfilesystem_error: Guest path component is not a directory, wherelinkin the same file returns ENOENT throughResolvePathError_nid_no_patch. Convertingsymlink's one call the same way would cover it, here or as a follow-up. The libc callers (rename,realpath,Filesystem.cpp) already catchfilesystem_error.AI-assisted (Claude Code); I ran all of this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T12:22:48Z.
Thanks @Silverash-i8 for the Windows run of the rebased head and for catching
symlink. Fixed here in1216b7f3:symlinknow resolves its new path withResolvePathError_nid_no_patch, aslinkdoes, somissing/../xreturns ENOENT andfile.txt/../xreturns ENOTDIR instead of throwing.guest_kernel_sysgains asymlinkcase in the existing invalid-parent loop.2c1eb02cwith the uncaughtfilesystem_error: Guest path component is not a directoryyou saw, and passes with the fix. The 28 filesystem, path, directory, stream, save-data, APR, AvPlayer and font tests pass.guest_filesystempasses, andguest_kernel_syspasses the invalid-parent loop including the new case. #3510 merges with this change without conflicts.One note for #3510, not this PR: on this machine Developer Mode is on, so its
CreateSymbolicLinkWsucceeds (symbolic→original.binis a real symlink), andguest_kernel_systhen stops at the success case'sstd::filesystem::is_symlink(std::filesystem::symlink_status(symbolic))(line 126 with #3510 merged), which MinGW's libstdc++ does not report as a symlink. Without Developer Mode the call returns EPERM and the test takes the "symbolic links unavailable" branch, which is presumably why your run passed.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T12:46:09Z.
@santhoshkumar-dev #3511 is in (
fab9f576), butconventionsstill fails here because this branch itself carries the stray3rdparty/imguigitlink: it was rebased ontomainafterddf6b8c9and before #3511, and the job checks out the PR head. Rebasing onto currentmain(a11c8f7f, it merges cleanly) should turn it green.Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T12:56:22Z.
@milescoviello thanks, that was it. Rebased onto
mainata11c8f7f(after #3511 removed the stray gitlink). It applied cleanly, the branch no longer carries3rdparty/imgui, and authorship of all three commits is unchanged:21d1698c(yours),557f726a, and548bedd9(thesymlinkfix for @Silverash-i8's report).check_conventions.py --base origin/mainandgit diff --checkpass, andguest_kernel_sysandguest_filesystempass on the rebased head (Linux, GCC 13.3, Release).@adriadam10 thanks for the earlier rebase. Since then the branch gained one commit,
548bedd9:symlink(#3491, merged while this was open) now returns the resolver's error likelinkinstead of throwing for an invalid.., with a case inguest_kernel_sys. Verified before/after on Linux, and on Windows with #3510/#3518 merged for that run only.Conventionsshould now pass.BuildandProgress reportneed a maintainer's approval to run on this push.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T13:57:16Z.
@adriadam10 friendly ping: the branch is rebased onto
a11c8f7fandConventionspasses now.BuildandProgress reporthave been waiting for approval since 12:56 (a fork push). Could you approve them when you have a moment?On the overlap note with #3510: since its update (
6aa0b4fb), the two conflict in one hunk ofreadlinkinlibkernel_sys/Export.cpp. This PR replacesconst auto native = ResolvePath_nid_no_patch(path);with theResolvePathError_nid_no_patchform, and #3510 adds its Windows reparse-point check right after that line. Keeping both resolves it: this PR's two lines, then #3510's#ifdef _WIN32block. If #3510 lands first, I'll rebase this one.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T19:57:39Z.
Rebased onto
mainat12c22662now that #3510 is in. Thereadlinkconflict is resolved as described above: this PR'sResolvePathError_nid_no_patchlines come first, then #3510's#ifdef _WIN32reparse-point check.symlinkapplies cleanly on top of #3510'sCreateSymbolicLinkWpath, and keeps returning the resolver's error for an invalid... Authorship of all three commits is unchanged (ad14190c,17827dd9,2ad91656).I rechecked the remaining direct
ResolvePath_nid_no_patchcallers: none were added since the last rebase. The ones left resolve fixed paths, catchstd::exception(dlopen), or already threw for a missing file before this PR (sceNgs2ParseWaveformFile).guest_kernel_sysandguest_filesystempass, including #3510's symlink success cases (Developer Mode on).check_conventions.py --base origin/mainandgit diff --checkpass.BuildandProgress reportwill need approval again for this push.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T20:04:14Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libc/src/Directory.cppL74-93core/libs/tests/GuestFilesystem.cppL78-79core/libs/prx/libc/src/General.cppL117, L126-129core/libs/prx/libc/src/General.cppL117core/libs/prx/libkernel/File/src/Open.cppL135-145Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T20:16:04Z.
@oneandonlydean could you take a look at this one as well when you have a moment? It's rebased onto current
mainwith the #3510 conflict resolved.Conventionspasses, andBuild/Progress reportpassed on the previous push and are waiting for approval on this one.I also have a performance improvement ready on another branch, which I can only open once this lands because of the one-open-PR limit.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:24:33Z.
Checked the current head on Linux merged onto
main: scoped build and 171 ctest tests pass, andguest_filesystem,guest_kernel_sys,guest_fontand the APR resolve test fail without the change. The earlierconventionsfailure was the stray3rdparty/imguigitlink onmain; it passes now, along with the other PR checks. Windows is covered by the runs from @Silverash-i8 and the author; merging.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T21:25:05Z.
Checked the diff on
2ad91656: the resolver's error reaches every entry point in its own error style, and thereadlinkandsymlinkpaths keep #3510's Windows code. Full build started on this head; merging when it's green.One thing I'm checking alongside it: a title that opens
dir/../filewheredirisn't in the host layout worked before and now gets ENOENT. I'm running two titles with every..path logged and will post here only if one fails.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T21:26:21Z.
Thanks for checking that case, @oneandonlydean, and thanks @santhoshkumar-dev for carrying the commit. ENOENT there is what FreeBSD returns for a missing component, but a directory that exists on the console and not in our host layout would hit it too. If one of the titles does, I'm glad to look at its path log and follow up, for example by creating that directory in the layout or keeping the old behaviour for that prefix.
AI-assisted: yes