Skip to content

fix(filesystem): reject invalid parent traversal on Windows - #3485

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
santhoshkumar-dev:codex/windows-path-traversal
Oct 11, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
santhoshkumar-dev:codex/windows-path-traversal

Conversation

@santhoshkumar-dev

Copy link
Copy Markdown
Contributor

What

Fixes #3117. A guest path such as missing/../present.txt currently reaches present.txt on Windows, so an invalid open, truncate, rename or unlink can operate on the real target. Validate the directory before removing a parent component and return ENOENT for a missing component or ENOTDIR for 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 failed freopen also 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 main at 0f863c102.

  • Windows 11 Pro 26200, AMD Radeon RX 6700 XT, WinLibs MinGW-w64 GCC 15.2.0 r7, Release:
    • The new guest_filesystem and guest_kernel_sys cases fail with main's production files and pass with the fix.
    • Full 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 to main: an exception through std::call_once and two GPU results on this card.
  • Ubuntu 24.04 under WSL2, GCC 13.3, Release: 28 selected filesystem, path, directory, stream, save-data, APR, AvPlayer and font tests pass.
  • No console test. This is a filesystem regression fix, not a gameplay claim.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes (Codex and Claude Code); the carried Linux commit was also disclosed as AI-assisted by its author

🤖 Generated with Claude Code

@milescoviello

Copy link
Copy Markdown
Contributor

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.

  • 36/36 selected tests pass: guest_filesystem, guest_kernel_sys, APR, AvPlayer, font, path, directory, stream and save-data.
  • Full ctest: 829/829. I left out only the three guest_video_out_* tests, which time out here while the laptop's displays are off.

AI-assisted: yes

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto current main (the empty-path checks added to sceKernelUnlink/Rename/Rmdir/Chmod/Truncate/Stat conflicted with the new resolver error handling; both kept, authorship of both commits preserved). On Linux with the PR merged onto main: scoped build and 171 ctest tests pass. Windows is covered by the runs from the author and @Silverash-i8; merging once CI is green.

@adriadam10
adriadam10 force-pushed the codex/windows-path-traversal branch from f50a5fa to 2c1eb02 Compare October 11, 2026 11:58
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
@milescoviello

Copy link
Copy Markdown
Contributor

@adriadam10 the conventions failure here isn't from this PR. Since #3470 (ddf6b8c9), main has a 3rdparty/imgui gitlink (6d910d54) with no entry in .gitmodules. The checkout step's submodule init then fails with fatal: No url found for submodule path '3rdparty/imgui' in .gitmodules, for every PR checked against main since about 11:55 (e.g. https-ca-list-stubs and Direct-Memory-Exception fail the same way). Removing the stray gitlink (git rm --cached 3rdparty/imgui), or adding its .gitmodules entry if imgui is meant to be a submodule, should clear them all.

@santhoshkumar-dev

Copy link
Copy Markdown
Contributor Author

Thank you all:

On CI: agreed with milescoviello, the only failing check is conventions, from main's 3rdparty/imgui gitlink with no .gitmodules entry (still missing on main at 2220effbe). 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)

@Silverash-i8

Copy link
Copy Markdown
Contributor

@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.txt still resolving, so it doesn't cover the Windows half): Windows 11, WinLibs GCC 15.2.0 r7, Release, 2c1eb02c merged onto main 2220eff, full build.

To get there I had to add two things that aren't about this PR, because both tests fail on Windows on main right now:

Both merged onto this PR without conflicts (#3510 also changes libkernel_sys/Export.cpp, in symlink only), and both failures are on main without this PR.

One gap, from symlink (#3491) landing while this PR was open: the rebased branch has it, and it still calls ResolvePath_nid_no_patch(created) directly, and with this PR that now throws for an invalid ... With a temporary probe in guest_kernel_sys, symlink("original.bin", "<root>/missing/../probe") aborts the test with an uncaught filesystem_error: Guest path component is not a directory, where link in the same file returns ENOENT through ResolvePathError_nid_no_patch. Converting symlink's one call the same way would cover it, here or as a follow-up. The libc callers (rename, realpath, Filesystem.cpp) already catch filesystem_error.

AI-assisted (Claude Code); I ran all of this on my machine.

santhoshkumar-dev added a commit to santhoshkumar-dev/AnyPS5 that referenced this pull request Oct 11, 2026
symlink, added in boykopovar#3491 while this branch was open, still resolved its
new path with ResolvePath_nid_no_patch, which now throws for an invalid
"..". Use ResolvePathError_nid_no_patch as link does, so
"missing/../x" returns ENOENT and "file/../x" ENOTDIR.

Reported by @Silverash-i8 on boykopovar#3485.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@santhoshkumar-dev

Copy link
Copy Markdown
Contributor Author

Thanks @Silverash-i8 for the Windows run of the rebased head and for catching symlink. Fixed here in 1216b7f3: symlink now resolves its new path with ResolvePathError_nid_no_patch, as link does, so missing/../x returns ENOENT and file.txt/../x returns ENOTDIR instead of throwing. guest_kernel_sys gains a symlink case in the existing invalid-parent loop.

One note for #3510, not this PR: on this machine Developer Mode is on, so its CreateSymbolicLinkW succeeds (symbolic → original.bin is a real symlink), and guest_kernel_sys then stops at the success case's std::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)

@milescoviello

Copy link
Copy Markdown
Contributor

@santhoshkumar-dev #3511 is in (fab9f576), but conventions still fails here because this branch itself carries the stray 3rdparty/imgui gitlink: it was rebased onto main after ddf6b8c9 and before #3511, and the job checks out the PR head. Rebasing onto current main (a11c8f7, it merges cleanly) should turn it green.

santhoshkumar-dev added a commit to santhoshkumar-dev/AnyPS5 that referenced this pull request Oct 11, 2026
symlink, added in boykopovar#3491 while this branch was open, still resolved its
new path with ResolvePath_nid_no_patch, which now throws for an invalid
"..". Use ResolvePathError_nid_no_patch as link does, so
"missing/../x" returns ENOENT and "file/../x" ENOTDIR.

Reported by @Silverash-i8 on boykopovar#3485.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@santhoshkumar-dev
santhoshkumar-dev force-pushed the codex/windows-path-traversal branch from 1216b7f to 548bedd Compare October 11, 2026 12:56
@santhoshkumar-dev

Copy link
Copy Markdown
Contributor Author

@milescoviello thanks, that was it. Rebased onto main at a11c8f7f (after #3511 removed the stray gitlink). It applied cleanly, the branch no longer carries 3rdparty/imgui, and authorship of all three commits is unchanged: 21d1698c (yours), 557f726a, and 548bedd9 (the symlink fix for @Silverash-i8's report). check_conventions.py --base origin/main and git diff --check pass, and guest_kernel_sys and guest_filesystem pass 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 like link instead of throwing for an invalid .., with a case in guest_kernel_sys. Verified before/after on Linux, and on Windows with #3510/#3518 merged for that run only. Conventions should now pass. Build and Progress report need a maintainer's approval to run on this push.

AI-assisted: yes (Claude Code)

@santhoshkumar-dev

Copy link
Copy Markdown
Contributor Author

@adriadam10 friendly ping: the branch is rebased onto a11c8f7f and Conventions passes now. Build and Progress report have 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 of readlink in libkernel_sys/Export.cpp. This PR replaces const auto native = ResolvePath_nid_no_patch(path); with the ResolvePathError_nid_no_patch form, 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 _WIN32 block. If #3510 lands first, I'll rebase this one.

AI-assisted: yes (Claude Code)

milescoviello and others added 3 commits October 12, 2026 01:24
Guest paths were normalized lexically before they reached the host, so
"missing/../file" and "file/../x" dropped the component before "..":
stat and open succeeded on the file, unlink deleted it and rmdir removed
a directory, where FreeBSD's lookup() resolves ".." with VOP_LOOKUP in
the directory reached so far and fails with ENOENT for a missing
component and ENOTDIR for a file. POSIX path resolution (XBD 4.13) says
the same.

".." is still collapsed lexically when the path before it is an existing
directory, so case-insensitive matching and aliases behave as before.
When it is not, the rest of the path is passed to the host unchanged and
the host resolves it. Linux then reports ENOENT or ENOTDIR as FreeBSD
does; Windows collapses ".." itself, so its results are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XYhZu5HokHMo9mfi8QU83m
symlink, added in boykopovar#3491 while this branch was open, still resolved its
new path with ResolvePath_nid_no_patch, which now throws for an invalid
"..". Use ResolvePathError_nid_no_patch as link does, so
"missing/../x" returns ENOENT and "file/../x" ENOTDIR.

Reported by @Silverash-i8 on boykopovar#3485.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@santhoshkumar-dev
santhoshkumar-dev force-pushed the codex/windows-path-traversal branch from 548bedd to 2ad9165 Compare October 11, 2026 19:57
@santhoshkumar-dev

Copy link
Copy Markdown
Contributor Author

Rebased onto main at 12c22662 now that #3510 is in. The readlink conflict is resolved as described above: this PR's ResolvePathError_nid_no_patch lines come first, then #3510's #ifdef _WIN32 reparse-point check. symlink applies cleanly on top of #3510's CreateSymbolicLinkW path, 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_patch callers: none were added since the last rebase. The ones left resolve fixed paths, catch std::exception (dlopen), or already threw for a missing file before this PR (sceNgs2ParseWaveformFile).

  • Windows 11, RX 6700 XT, WinLibs GCC 15.2.0 r7, Release: guest_kernel_sys and guest_filesystem pass, including fix(libkernel_sys): create symlinks with CreateSymbolicLinkW on Windows #3510's symlink success cases (Developer Mode on).
  • Ubuntu 24.04 under WSL2, GCC 13.3, Release: the same two tests and the 28 filesystem, path, directory, stream, save-data, APR, AvPlayer and font tests pass.
  • check_conventions.py --base origin/main and git diff --check pass.

Build and Progress report will need approval again for this push.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#3635 core/libs/prx/libc/src/Directory.cpp L74-93
#3654 core/libs/tests/GuestFilesystem.cpp L78-79
#3892 core/libs/prx/libc/src/General.cpp L117, L126-129
#3959 core/libs/prx/libc/src/General.cpp L117
#3968 core/libs/prx/libkernel/File/src/Open.cpp L135-145

@santhoshkumar-dev

Copy link
Copy Markdown
Contributor Author

@oneandonlydean could you take a look at this one as well when you have a moment? It's rebased onto current main with the #3510 conflict resolved. Conventions passes, and Build/Progress report passed 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)

@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
9 tasks done
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the current head on Linux merged onto main: scoped build and 171 ctest tests pass, and guest_filesystem, guest_kernel_sys, guest_font and the APR resolve test fail without the change. The earlier conventions failure was the stray 3rdparty/imgui gitlink on main; it passes now, along with the other PR checks. Windows is covered by the runs from @Silverash-i8 and the author; merging.

@adriadam10
adriadam10 merged commit 14a7e64 into boykopovar:main Oct 11, 2026
12 checks passed
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Checked the diff on 2ad9165: the resolver's error reaches every entry point in its own error style, and the readlink and symlink paths 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/../file where dir isn'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.

@milescoviello

Copy link
Copy Markdown
Contributor

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

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.

libc: guest paths resolve ".." lexically, so stat/open/unlink/rmdir act on "missing/../file" instead of failing; fix branch ready

5 participants