Skip to content

fix(libkernel): answer Windows reparse points that are not links - #8534

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
ycbuzi:pr/windows-reparse-non-link
Oct 22, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
ycbuzi:pr/windows-reparse-non-link

Conversation

@ycbuzi

@ycbuzi ycbuzi commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

What

lstat and readlink throw NotImplemented for 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: lstat now answers as stat does and readlink returns EINVAL, as FreeBSD's readlink(2) does for a file that is not a link and as CPython's os.lstat and os.readlink do 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, and readlink returns EINVAL.

The tests create reparse points with FSCTL_SET_REPARSE_POINT and a GUID buffer, one with tag 0x00000ABC (no name-surrogate bit) and one with 0x20000ABC. A compact /exe (WOF) file cannot serve as the fixture: on Windows 11 24H2 the WOF filter hides the reparse point from GetFileAttributesW and FileAttributeTagInfo alike, measured with a probe that sets, queries and clears tags. Windows refuses every open of an unhandled tag without FILE_FLAG_OPEN_REPARSE_POINT (ERROR_CANT_ACCESS_FILE), so the test requires lstat to agree with stat on that file rather than to succeed; a filter-handled tag opens normally and takes the same path.

Related: mashingaan's #6447 (closed) returned EINVAL for other reparse points without the tag check. #7202 (open) rewrites the same lstat block of NativeStat.cpp for long paths, and #8312 (open) changes another branch of ReadNativeLink (ENOTDIR through a regular file); each is independent in behaviour, so whichever lands second rebases. The lstat technical-debt entry loses only the clause this change makes false, keeping #7551's O_NOFOLLOW sentence, 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 main d073fe6 plus this commit, run elevated:

  • guest_kernel_sys and guest_filesystem pass.
  • With main's WindowsSymbolicLink.hpp, NativeStat.cpp and libkernel_sys/Export.cpp and the new tests kept, both fail (exit 0xc0000409); with the change both pass.
  • main's own guest_kernel_sys and guest_filesystem pass against this change's code.
  • Not verified: an unelevated run. runas /trustlevel executes nothing on this host, so whether FSCTL_SET_REPARSE_POINT on a file the test owns needs elevation is unverified.

Linux: the change is inside #ifdef _WIN32; not run here.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

lstat and readlink threw NotImplemented for every Windows reparse point
other than a symbolic link or a drive junction. A tag without the name
surrogate bit (cloud files, deduplication) does not stand for another path,
so lstat now answers as stat does and readlink returns EINVAL, as FreeBSD
does for a file that is not a link and as CPython's os.lstat and os.readlink
do (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, and readlink returns EINVAL.

The tests set reparse tags with FSCTL_SET_REPARSE_POINT, one without the
name surrogate bit and one with it. A compact /exe (WOF) file cannot serve
as the fixture: on Windows 11 24H2 the WOF filter hides the reparse point
from GetFileAttributesW and FileAttributeTagInfo alike. Windows refuses
every open of an unhandled tag without FILE_FLAG_OPEN_REPARSE_POINT, so the
test requires lstat to agree with stat rather than to succeed.

mashingaan's boykopovar#6447 returned EINVAL for other reparse
points without the tag check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Progress report (8c26eac → 9897260)

📈 System libraries: 42.35% (+0.02%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel_sys readlink_nid_postfix
libkernel_sys readlinkat_nid_postfix

@github-actions

github-actions Bot commented Oct 20, 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
PR 7202 core/libs/prx/libkernel/File/src/NativeStat.cpp L54-55, L57-59
PR 7530 core/libs/tests/GuestFilesystem.cpp L1048
docs/dev/debt/libkernel.md L132
PR 9095 core/libs/tests/GuestFilesystem.cpp L1048
docs/dev/debt/libkernel.md L132
PR 9355 docs/dev/debt/libkernel_sys.md L13

Some 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.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel.md
PR 5528 core/libs/prx/libkernel_sys/Export.cpp
core/libs/tests/GuestKernelSys.cpp
PR 6044 core/libs/tests/GuestFilesystem.cpp
core/libs/tests/GuestKernelSys.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6525 core/libs/prx/libkernel_sys/Export.cpp
core/libs/tests/GuestKernelSys.cpp
docs/dev/debt/libkernel_sys.md
PR 6740 docs/dev/debt/libkernel.md
PR 6830 docs/dev/debt/libkernel.md
PR 6879 core/libs/prx/libkernel/File/src/NativeStat.cpp
docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
PR 7509 docs/dev/debt/libkernel.md
PR 7565 docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8547 docs/dev/debt/libkernel.md
PR 8553 docs/dev/debt/libkernel.md
PR 8658 core/libs/prx/libkernel/File/src/NativeStat.cpp
docs/dev/debt/libkernel.md
PR 8726 docs/dev/debt/libkernel.md

@ycbuzi

ycbuzi commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

On the overlap with #7202 above: merging the two, git auto-merges this PR's IsNameSurrogate(p, "lstat") in DoLstat without a conflict marker, while #7202 moves every other Windows call there to its \\?\-prepared path. On a reparse point beyond MAX_PATH that line then throws std::system_error (lstat: CreateFileW: The system cannot find the path specified), because CreateFileW gets the raw long path.

Measured on Windows 11, MinGW-w64 GCC 15.2.0, Release, main 4036fab + #7202 (ad3dfd1ba) + this PR (0ecef87c4):

  • With IsNameSurrogate, Read and ReadJunction all taking prepared, guest_filesystem, guest_kernel_sys and guest_posix_filesystem pass.
  • A 0x20000ABC name surrogate added to fix(libkernel): support lstat on long Windows paths #7202's long-path block in GuestFilesystem.cpp (lstat through /long-stat-host, expecting mode 0100666) 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 prepared resolution; if #7202 lands first I will rebase this one with it and add the long-path case.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@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 Require that FSCTL_SET_REPARSE_POINT succeeds, and as you noted, nobody has confirmed that it works without elevation. If it doesn't, guest_filesystem and guest_kernel_sys would abort for anyone running them as a normal user on Windows (CI wouldn't show it, since its runners are admin). GuestFilesystem.cpp already handles the same situation for symbolic links (around line 939: on ERROR_PRIVILEGE_NOT_HELD it prints that the checks are skipped and carries on). Could the reparse-point checks do the same when the DeviceIoControl fails 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_filesystem and guest_kernel_sys passing on Linux and Windows.

…fused for rights

Both fixtures required FSCTL_SET_REPARSE_POINT to succeed; a user without the right would have
aborted guest_filesystem and guest_kernel_sys. They now print that the checks are skipped and carry
on, as the symbolic link checks do without Developer Mode. On this PC the control succeeds at
medium integrity, so the checks ran both elevated and unelevated.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ycbuzi

ycbuzi commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Done in 338e2cb, on top of the fix so the delta stays visible: both fixtures now treat a refused FSCTL_SET_REPARSE_POINT (ERROR_PRIVILEGE_NOT_HELD or ERROR_ACCESS_DENIED) the way the symbolic-link checks treat CreateSymbolicLinkW: 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 /groups in the same script: Mandatory Label\Medium Mandatory Level), with PATH and the working directories as ctest sets them. guest_filesystem and guest_kernel_sys both exit 0. The only skip message is the existing symbolic-link one in guest_filesystem (creating symbolic links needs Developer Mode or administrator rights), which confirms the run was not elevated; no reparse point message appeared, so FSCTL_SET_REPARSE_POINT with a GUID tag succeeds at medium integrity on this build and the new checks ran. Elevated, through ctest, 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.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, and sorry for the slow reply. 338e2cb does 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.

@oneandonlydean
oneandonlydean merged commit ab347d1 into boykopovar:main Oct 22, 2026
10 checks passed
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.

2 participants