fix(libc): follow a Windows symbolic link before .. in a guest path #9371
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9371"
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 cadenasynyster on 2026-10-21T19:31:51Z.
What
On Windows,
..after a directory symbolic link whose target is missing resolved lexically to the link's parent, sostat("dir/dangling-link/../present.txt")did not fail. FreeBSD 11.4'slookup()(sys/kern/vfs_lookup.c) follows the link before it handles.., so the call fails withENOENT.RequireHostDirectoryincore/libs/prx/libc/src/General.cppchecks the component before..withstd::filesystem::status, which on MinGW reads the link's own attributes, and a Windows directory symbolic link carriesFILE_ATTRIBUTE_DIRECTORYwhether its target exists or not. On Windows it now opens a reparse point withCreateFileWandFILE_FLAG_BACKUP_SEMANTICS, which follows it, and decides from the target: a directory passes, a file givesENOTDIR, a missing targetENOENT, and a loop (ERROR_CANT_RESOLVE_FILENAME)ELOOP. Any other open error falls through to the existing check. Components that are not reparse points, and Linux and macOS, are unchanged.The test for this in
guest_filesystem(TestParentTraversal:directory-link,file-link,dangling-link) never ran on Windows. It creates its links withstd::filesystem::create_directory_symlinkandcreate_symlink, which MinGW's libstdc++ (GCC 15) does not implement on Windows (create_directory_symlinkreturnsfunction_not_supportedunder_GLIBCXX_FILESYSTEM_IS_WINDOWS, andcreate_symlinkdoes the same without_GLIBCXX_HAVE_SYMLINK). On Windows the block now creates them withCreateSymbolicLinkWandSYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE, as the later link checks in the same file do. It also deletes them withDeleteFileWandRemoveDirectoryWbefore the fixture'sremove_all. With the dangling link left in place,remove_allthrew afilesystem_errorthat ended the test;docs/dev/debt/libs.mdrecords the same MinGW problem forGuestKernelSys.cpp.TestParentTraversalalso covers a self-referencing directory link and a two-link loop before.., which fail withELOOP.Tested
Windows 11 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release,
-DBUILD_TESTING=ON, unelevated PowerShell with Developer Mode on, onmain1896871ba, then rebased ontod6e7ab42d.main'sGeneral.cppand this PR's test:guest_filesystemfails withFilesystem check failed at line 194, the first check of thedangling-link/..case (statofdangling-link/../present.txtdoes not fail withENOENT). Thefile-link/..cases already pass there withENOTDIR.guest_filesystempasses 3 of 3. The log showsresolveError=20for everyfile-link/..open andresolveError=2for everydangling-link/..open.guest_kernel_sys,guest_file_timestamps,guest_posix_filesystem,guest_directory,guest_directory_rewind,guest_directory_close,guest_directory_buffer,file_streams,file_position,file_identity,guest_kernel_rename,guest_rename_dot,guest_realpath,guest_working_directory,guest_path_case,guest_path_drive_component,guest_path_name_length,guest_statvfs,guest_fstatvfs,guest_fstatfs,guest_fdopendir,guest_fiopen,guest_fopen_long_host_path,guest_shm_open,guest_savedata_mount_status,savedata_replace_file_failure,guest_system_service_path_boundary.guest_filesystemandguest_kernel_syspass 3 of 3 runs, andpython tools/check_conventions.py --base origin/mainpasses...(directory linksself-loopto itself andloop-atoloop-btoloop-a, next topresent.txt), measured with a temporary probe that is not in this PR: with this PR,statofself-loop/../present.txtandloop-a/../present.txtfails withELOOP(62) andsceKernelStatreturns0x8002003E; withmain'sGeneral.cppboth calls return 0. The two loop cases inTestParentTraversalare regression coverage. Withmain'sGeneral.cppthe test fails at an earlier check, so it is not an isolated negative control for them.SYMBOLIC_LINK_FLAG_DIRECTORY):CreateFileWfails withERROR_ACCESS_DENIED(5), solink/../present.txtandlink/fail withENOTDIRandlinkitself withEACCES, where FreeBSD, which has one link type, follows it. Not fixed here; recorded indocs/dev/debt/libc.md. I did not compare that case withmain.tools/pr_overlap.pywas not run here: it needsgh, which is not installed on this machine. #9109 changesResolvein the same file, and #8797 and #8550 edit other parts ofGuestFilesystem.cpp; neither touchesRequireHostDirectoryor this link block.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 wachi35676 on 2026-10-21T23:40:00Z.
Windows run with a negative control, and the
ELOOPpath, which the test doesn't cover.Head
23b2528f6fmerged onto maina6dcea927(clean). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release,BUILD_TESTING=ON. Unelevated, Developer Mode on, soCreateSymbolicLinkWwithALLOW_UNPRIVILEGED_CREATEworks and the link cases run.guest_filesystem,guest_kernel_sys: 2/2, 3 runs.libc/src/General.cppfrom main,guest_filesystemfails at line 194 (Filesystem check failed at line 194 (guest errno 2, Win32 error 0), incheckInvalid).check_conventions.py --base a6dcea927: passes.Loops are not reported as
ELOOP. Probe: directory linksloop-a→loop-b→loop-a, andself→self, next topresent.txt:So
CreateFileWdoes fail withERROR_CANT_RESOLVE_FILENAME(1921), the code this PR maps toELOOP. Butstatthrough a looping link before..still succeeds, the same as main. FreeBSD 11.4'slookup()givesELOOPthere. A dangling link works as described (the test'sdangling-linkcase). I did not trace which path skipsRequireHostDirectoryfor the loop. Aloop-a/..case inTestParentTraversalwould show it.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T06:54:33Z.
Review: CHANGES_REQUESTED
I reviewed the Windows path change and the current checks. Checks I ran on head
23b2528f6fa1431893b643acb08b4254afab5256: -python3 tools/check_conventions.py --base upstream/main --head refs/review/9371: passed. -git diff --check upstream/main...HEAD: passed. -cmake -S. -B /tmp/AnyPS5-9371-review/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON: configuration could not complete because this checkout lacks the SDL2 submodule'sCMakeLists.txtand the host lacks XRandR support. I therefore could not runguest_filesystemlocally. The hosted relinker matrix and register-context checks pass, but the full Linux and Windows jobs are skipped; those results do not validate this libc change. The Windows focused run in the PR and the independent Windows run are useful evidence for the dangling-link case. There is still a correctness gap in the stated FreeBSD behavior. The independent Windows probe reports thatstat("loop-a/../present.txt")andstat("self/../present.txt")succeed for directory-link loops, althoughCreateFileWitself returnsERROR_CANT_RESOLVE_FILENAME(1921), which this change intends to map toELOOP. Please trace why the path reaches a successful stat, add self-loop and two-link-loop cases toTestParentTraversal, and make the guest calls returnELOOPbefore treating the behavior as covered. The PR’s own probe also reports a file-type link pointing at a directory yieldsENOTDIRforlink/.., unlike the FreeBSD target behavior; please test and document/resolve that edge case as well. The branch is 514 commits behind currentmain, whileCONTRIBUTING.mdrequires keeping a PR branch current. The overlap scan could not compareGuestFilesystem.cppwith open #7530 and #9095 because those PRs already conflict with the base. I manually checked their changed test regions: their junction-removal fixture is separate from thisTestParentTraversalfixture; #8797 also merges cleanly in the pairwise tree check. Please rerun overlap checks after rebasing.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T02:27:34Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
9ea4c6561be22466166fb26fa61cd2eb0d23f2cf, basemain.diff.patch, then read the head context of each changed function and its callers through the repository reader (repo_read.py).Results
General.cpp,GuestFilesystem.cppwindows.hincluded in both fileslibc.mdline 141_WIN32-onlyFindings
Blocking
None.
Non-blocking
core/libs/tests/GuestFilesystem.cpp:328: the link cleanup runs only after everycheckInvalidsucceeds. If one of theRequirechecks at lines 319 or 320 fails, the test throws first anddangling-link,self-loopand the loop links stay in the test root. Nothing hangs and the fixture name is unique per run, so this only leaves files behind after a failure. The existing test has the same shape on Linux, so a scope guard is optional.Sources
..handling and the reparse-point branch:General.cppat the head.GuestFilesystem.cppat the head.docs/dev/debt/libc.mdat the head.Not verified
guest_filesystemandguest_kernel_syson Windows. The author reports 3 of 3 passes on the rebased head; I did not run them.ELOOPandENOTDIRvalues for the loop and file-link cases: author measurements, not repeated here.WithTrailingSeparatoratGeneral.cpp:379): I did not check howGetFileAttributesWtreats a link with a trailing separator.docs/dev/debt/libs.mdrecords the same MinGW problem. The entry at line 9 coversremoveandremove_allon dangling links, not thecreate_directory_symlinkfailure.General.cpp(diff and lines 280–330, callers),GuestFilesystem.cpp(diff and lines 196–210 and 330–345, plus symbol search),docs/dev/debt/libc.md(diff and lines 139–141). Excluded by rule: none.To get this to a good state
Nothing is required.
Pull request closed