fix(libkernel): answer Windows reparse points that are not links #8534
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8534"
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 ycbuzi on 2026-10-20T15:26:01Z.
What
lstatandreadlinkthrowNotImplementedfor every Windows reparse point other than a symbolic link or a drive junction, which terminates the title. A tag without the name-surrogate bit (cloud files, deduplication) does not stand for another path:lstatnow answers asstatdoes andreadlinkreturnsEINVAL, as FreeBSD's readlink(2) does for a file that is not a link and as CPython'sos.lstatandos.readlinkdo since 3.8 (bpo-37834). A name surrogate that is neither a symbolic link nor a junction (a mounted volume, a WSL link) is reported as the reparse point itself with the mode of its attributes, andreadlinkreturnsEINVAL.The tests create reparse points with
FSCTL_SET_REPARSE_POINTand a GUID buffer, one with tag0x00000ABC(no name-surrogate bit) and one with0x20000ABC. Acompact /exe(WOF) file cannot serve as the fixture: on Windows 11 24H2 the WOF filter hides the reparse point fromGetFileAttributesWandFileAttributeTagInfoalike, measured with a probe that sets, queries and clears tags. Windows refuses every open of an unhandled tag withoutFILE_FLAG_OPEN_REPARSE_POINT(ERROR_CANT_ACCESS_FILE), so the test requireslstatto agree withstaton that file rather than to succeed; a filter-handled tag opens normally and takes the same path.Related: mashingaan's #6447 (closed) returned
EINVALfor other reparse points without the tag check. #7202 (open) rewrites the samelstatblock ofNativeStat.cppfor long paths, and #8312 (open) changes another branch ofReadNativeLink(ENOTDIRthrough a regular file); each is independent in behaviour, so whichever lands second rebases. Thelstattechnical-debt entry loses only the clause this change makes false, keeping #7551'sO_NOFOLLOWsentence, and the non-link reparse points get an entry of their own so both stay under the length limit.Tested
Windows 11 24H2, MinGW-w64 GCC 15.2.0 (x86_64-ucrt-posix-seh r7), Release, on
maind073fe6a1plus this commit, run elevated:guest_kernel_sysandguest_filesystempass.main'sWindowsSymbolicLink.hpp,NativeStat.cppandlibkernel_sys/Export.cppand the new tests kept, both fail (exit 0xc0000409); with the change both pass.main's ownguest_kernel_sysandguest_filesystempass against this change's code.runas /trustlevelexecutes nothing on this host, so whetherFSCTL_SET_REPARSE_POINTon a file the test owns needs elevation is unverified.Linux: the change is inside
#ifdef _WIN32; not run 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 github-actions[bot] on 2026-10-20T15:26:38Z.
Progress report (
8c26eac→9897260)📈 System libraries: 42.35% (+0.02%, +2 implemented functions)
✅ 2 implemented
readlink_nid_postfixreadlinkat_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T15:39:58Z.
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/libkernel/File/src/NativeStat.cppL54-55, L57-59core/libs/tests/GuestFilesystem.cppL1048docs/dev/debt/libkernel.mdL132core/libs/tests/GuestFilesystem.cppL1048docs/dev/debt/libkernel.mdL132docs/dev/debt/libkernel_sys.mdL13Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel_sys/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel_sys/Export.cppcore/libs/tests/GuestKernelSys.cppcore/libs/tests/GuestFilesystem.cppcore/libs/tests/GuestKernelSys.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel_sys/Export.cppcore/libs/tests/GuestKernelSys.cppdocs/dev/debt/libkernel_sys.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/NativeStat.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel_sys/Export.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/NativeStat.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-20T15:57:33Z.
On the overlap with #7202 above: merging the two, git auto-merges this PR's
IsNameSurrogate(p, "lstat")inDoLstatwithout a conflict marker, while #7202 moves every other Windows call there to its\\?\-prepared path. On a reparse point beyondMAX_PATHthat line then throwsstd::system_error(lstat: CreateFileW: The system cannot find the path specified), becauseCreateFileWgets the raw long path.Measured on Windows 11, MinGW-w64 GCC 15.2.0, Release,
main4036fab1b+ #7202 (ad3dfd1ba) + this PR (0ecef87c4):IsNameSurrogate,ReadandReadJunctionall takingprepared,guest_filesystem,guest_kernel_sysandguest_posix_filesystempass.0x20000ABCname surrogate added to #7202's long-path block inGuestFilesystem.cpp(lstatthrough/long-stat-host, expecting mode0100666) passes with that resolution and aborts with the auto-merged line.The hazard is the same in either order: the line comes from this PR, so a rebase of #7202 onto it keeps it on the raw path too. Whichever lands second needs the
preparedresolution; if #7202 lands first I will rebase this one with it and add the long-path case.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T23:08:54Z.
@ycbuzi Thanks, the tag check and the CPython reference make this easy to follow, and nothing that works today changes.
One request for the tests: both new fixtures
RequirethatFSCTL_SET_REPARSE_POINTsucceeds, and as you noted, nobody has confirmed that it works without elevation. If it doesn't,guest_filesystemandguest_kernel_syswould abort for anyone running them as a normal user on Windows (CI wouldn't show it, since its runners are admin).GuestFilesystem.cppalready handles the same situation for symbolic links (around line 939: onERROR_PRIVILEGE_NOT_HELDit prints that the checks are skipped and carries on). Could the reparse-point checks do the same when theDeviceIoControlfails for lack of rights? An unelevated run showing it passes would also settle it.After that, the bar is a full CI run with
guest_filesystemandguest_kernel_syspassing on Linux and Windows.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T03:20:43Z.
@oneandonlydean Done in
338e2cb, on top of the fix so the delta stays visible: both fixtures now treat a refusedFSCTL_SET_REPARSE_POINT(ERROR_PRIVILEGE_NOT_HELDorERROR_ACCESS_DENIED) the way the symbolic-link checks treatCreateSymbolicLinkW: they print that the reparse point checks are skipped, remove the file and carry on. Any other failure still fails the test.Unelevated run, as asked: Windows 11 Home 10.0.26200.9711, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,
BUILD_TESTING=ON, Developer Mode off. The two executables were started from Explorer, so they ran at medium integrity (whoami /groupsin the same script:Mandatory Label\Medium Mandatory Level), with PATH and the working directories as ctest sets them.guest_filesystemandguest_kernel_sysboth exit 0. The only skip message is the existing symbolic-link one inguest_filesystem(creating symbolic links needs Developer Mode or administrator rights), which confirms the run was not elevated; no reparse point message appeared, soFSCTL_SET_REPARSE_POINTwith a GUID tag succeeds at medium integrity on this build and the new checks ran. Elevated, throughctest, both pass as well with nothing skipped.What this does not show is the skip branch itself running: I have no account here for which the control is refused.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T04:22:25Z.
Thanks, and sorry for the slow reply.
338e2cbdoes what I asked: a refused FSCTL_SET_REPARSE_POINT skips only those checks, and only for the two rights errors, the same way the symbolic-link checks already do. The medium-integrity run is a better answer than I expected, since it shows the checks run unelevated rather than being skipped. The fix commit is unchanged since I last read it. Because #8312 touched the same files, I ran the full workflow on this head: guest_filesystem and guest_kernel_sys passed on Linux and Windows, with 0 failures overall. Merging.