fix(libkernel): stop O_NOFOLLOW from opening a Windows directory junction #7551

Merged
mazen320 merged 1 commit from upstream-pr/7551 into main 2026-10-20 10:20:02 +00:00
mazen320 commented 2026-10-18 13:23:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-18T13:23:48Z.


What

lstat reports a Windows directory junction as a symbolic link. open and sceKernelOpen with O_NOFOLLOW still opened the target and returned a descriptor. A symbolic link in that situation returns EMLINK.

O_NOFOLLOW now returns EMLINK for a drive-absolute directory junction and does not open the target. An open without that flag still follows the junction. A volume mount is unchanged.

Tested

Windows 11, WinLibs GCC 15.2.0, unelevated. Before the change, opening a junction with O_NOFOLLOW returned a descriptor. After the change, guest_filesystem (ctest #1200) passed: sceKernelOpen returns 0x8002001F, open returns -1 with errno 31, and an open without the flag still returns a descriptor. Conventions passed against upstream/main. GitHub Windows and Linux CI were not run.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4909442870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7551). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-18T13:23:48Z. --- ### What `lstat` reports a Windows directory junction as a symbolic link. `open` and `sceKernelOpen` with `O_NOFOLLOW` still opened the target and returned a descriptor. A symbolic link in that situation returns `EMLINK`. `O_NOFOLLOW` now returns `EMLINK` for a drive-absolute directory junction and does not open the target. An open without that flag still follows the junction. A volume mount is unchanged. ### Tested Windows 11, WinLibs GCC 15.2.0, unelevated. Before the change, opening a junction with `O_NOFOLLOW` returned a descriptor. After the change, `guest_filesystem` (ctest #1200) passed: `sceKernelOpen` returns `0x8002001F`, `open` returns -1 with errno 31, and an open without the flag still returns a descriptor. Conventions passed against `upstream/main`. GitHub Windows and Linux CI were not run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-18 13:24:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T13:24:09Z.


I compared this with open #7530. The behavior is distinct: #7530 handles rmdir/unlink on drive-absolute junctions, while this PR handles O_NOFOLLOW on open/sceKernelOpen. Both include WindowsSymbolicLink.hpp in Open.cpp and extend the same GuestFilesystem.cpp fixture, so please coordinate the rebase/order and verify the combined fixture covers both no-follow rejection and removing the junction without touching its target. #7530 already has Windows evidence for the removal path; this PR reports the no-follow cases separately.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250442009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7551#issuecomment-6250442009). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T13:24:09Z. --- I compared this with open #7530. The behavior is distinct: #7530 handles `rmdir`/`unlink` on drive-absolute junctions, while this PR handles `O_NOFOLLOW` on `open`/`sceKernelOpen`. Both include `WindowsSymbolicLink.hpp` in `Open.cpp` and extend the same `GuestFilesystem.cpp` fixture, so please coordinate the rebase/order and verify the combined fixture covers both no-follow rejection and removing the junction without touching its target. #7530 already has Windows evidence for the removal path; this PR reports the no-follow cases separately.
MarcZX10 commented 2026-10-18 13:25:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T13:25:03Z.


I fetched both PR heads and ran a local git merge-tree comparison. Open.cpp and GuestFilesystem.cpp auto-merge; docs/dev/debt/libkernel.md has the sole content conflict, where both PRs edit the same Windows link behavior bullet. The combined branch is otherwise clean at the merge-tree level. This confirms the required rebase resolution is documentation-only; the combined Windows fixture should still run both behavior sets.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250450210 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7551#issuecomment-6250450210). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T13:25:03Z. --- I fetched both PR heads and ran a local `git merge-tree` comparison. `Open.cpp` and `GuestFilesystem.cpp` auto-merge; `docs/dev/debt/libkernel.md` has the sole content conflict, where both PRs edit the same Windows link behavior bullet. The combined branch is otherwise clean at the merge-tree level. This confirms the required rebase resolution is documentation-only; the combined Windows fixture should still run both behavior sets.
mazen320 commented 2026-10-18 13:26:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-18T13:26:26Z.


They are separate. #7530 removes the junction. This one refuses to follow it when O_NOFOLLOW is set.

A local merge of the two heads keeps Open.cpp and GuestFilesystem.cpp without a conflict. The filesystem test ends up with both checks: O_NOFOLLOW returns EMLINK, and rmdir / unlink remove only the junction. The only conflict is the one debt sentence in docs/dev/debt/libkernel.md. Whichever lands second should keep both sentences.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250463409 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7551#issuecomment-6250463409). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-18T13:26:26Z. --- They are separate. #7530 removes the junction. This one refuses to follow it when `O_NOFOLLOW` is set. A local merge of the two heads keeps `Open.cpp` and `GuestFilesystem.cpp` without a conflict. The filesystem test ends up with both checks: `O_NOFOLLOW` returns `EMLINK`, and `rmdir` / `unlink` remove only the junction. The only conflict is the one debt sentence in `docs/dev/debt/libkernel.md`. Whichever lands second should keep both sentences.
github-actions[bot] commented 2026-10-18 14:06:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:06:53Z.


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 5021 core/libs/prx/libkernel/File/src/Open.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestFilesystem.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6658 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6977 docs/dev/debt/libkernel.md
PR 7049 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/Open.cpp
PR 7332 core/libs/prx/libkernel/File/src/Open.cpp
docs/dev/debt/libkernel.md
PR 7437 core/libs/prx/libkernel/File/src/Open.cpp
docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7556 docs/dev/debt/libkernel.md
PR 7605 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250862711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7551#issuecomment-6250862711). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T14:06:53Z. --- <!-- pr-overlap --> 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/File/src/Open.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestFilesystem.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libkernel.md` | | [PR 6519](https://www.github.com/boykopovar/AnyPS5/pull/6519) | `docs/dev/debt/libkernel.md` | | [PR 6658](https://www.github.com/boykopovar/AnyPS5/pull/6658) | `docs/dev/debt/libkernel.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/File/src/Open.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7437](https://www.github.com/boykopovar/AnyPS5/pull/7437) | `core/libs/prx/libkernel/File/src/Open.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7464](https://www.github.com/boykopovar/AnyPS5/pull/7464) | `docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` | | [PR 7556](https://www.github.com/boykopovar/AnyPS5/pull/7556) | `docs/dev/debt/libkernel.md` | | [PR 7605](https://www.github.com/boykopovar/AnyPS5/pull/7605) | `docs/dev/debt/libkernel.md` |
TheTerr4 commented 2026-10-18 14:59:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheTerr4 on 2026-10-18T14:59:34Z.


Windows runtime check. Windows 11 Pro 10.0.26200, Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7 (UCRT), Release.

This PR's head e79cf0f75 merged cleanly into main 385ed71f2; the full build and libs both exit 0.

  • guest_filesystem, guest_posix_filesystem and guest_kernel_sys pass, three repeated -j1 runs.
  • Negative control: with libkernel/File/src/Open.cpp restored to main's version, guest_filesystem aborts (exit 0xc0000409) in the junction case (sceKernelOpen follows the junction).
  • Not run: the full suite, Linux, macOS. The symlink cases in guest_filesystem are skipped on this machine (Developer Mode is off); the junction cases ran.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251390673 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7551#issuecomment-6251390673). Originally posted by [TheTerr4](https://github.com/TheTerr4) on 2026-10-18T14:59:34Z. --- Windows runtime check. Windows 11 Pro 10.0.26200, Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7 (UCRT), Release. This PR's head `e79cf0f75` merged cleanly into `main` `385ed71f2`; the full build and `libs` both exit 0. - `guest_filesystem`, `guest_posix_filesystem` and `guest_kernel_sys` pass, three repeated `-j1` runs. - Negative control: with `libkernel/File/src/Open.cpp` restored to `main`'s version, `guest_filesystem` aborts (exit 0xc0000409) in the junction case (`sceKernelOpen` follows the junction). - Not run: the full suite, Linux, macOS. The symlink cases in `guest_filesystem` are skipped on this machine (Developer Mode is off); the junction cases ran. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-20 10:21:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T10:21:33Z.


Re-checked against current main (merges cleanly, junction path unchanged in logic), the new test and TheTerr4's Windows run with its negative control; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288742872 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7551#issuecomment-6288742872). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T10:21:33Z. --- Re-checked against current main (merges cleanly, junction path unchanged in logic), the new test and TheTerr4's Windows run with its negative control; merged.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7551
No description provided.