fix(libkernel): fail open with O_CREAT and O_EXCL on a Windows symbolic link #9496

Merged
Gruzzberry merged 1 commit from upstream-pr/9496 into main 2026-10-25 17:35:58 +00:00
Gruzzberry commented 2026-10-21 23:22:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-21T23:22:38Z.


What

On Windows, open with O_CREAT|O_EXCL on a symbolic link whose target is missing succeeded and created the target. FreeBSD 11.4's vn_open_cred only adds FOLLOW when O_EXCL is not set, so the lookup finds the link itself and the call fails with EEXIST whatever the link points to, as POSIX requires for O_CREAT|O_EXCL on a symbolic link.

OpenNative now fails O_CREAT|O_EXCL with EEXIST before the host open when the last component is a reparse point. Any reparse point is an existing name, so the answer does not depend on its kind. A link to an existing file already failed with EEXIST and still does; O_CREAT without O_EXCL still creates the target through a dangling link, as FreeBSD does. Linux already fails in the host open and is unchanged.

Tested

Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON, on main d6eafa54d0 (rebased), Developer Mode on so links can be created.

  • guest_filesystem: new checks with a dangling link: open with O_CREAT|O_EXCL|O_WRONLY fails with EEXIST, sceKernelOpen returns 0x80020011, and no target appears; O_CREAT|O_WRONLY then creates the target through the link; O_CREAT|O_EXCL fails with EEXIST again. The link and target are removed afterwards; without link permission the checks are skipped with a message. On main the test fails at the first new check (the open returns a descriptor); with this PR it passes.
  • Full suite on main d6eafa54d0 and on main with #9442, #9469, #9474, #9487 and #9496 merged together, same machine: 1890 tests each, identical results (1869 passed, 18 skipped; on both, the 3 agc_driver_sample_order* tests fail and agc_driver_image_array_window_past_layer_limit is not built, as its 64 KiB alignas is rejected by this MinGW toolchain).
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux (no change there; the new checks create the link with std::filesystem::create_symlink), a console, a title run.

Overlaps

  • tools/pr_overlap.py --branch on the rebased head lists no direct overlap. Of the 9 pull requests it could not compare, #7201 adds a macOS-only O_CREAT check after the O_NOFOLLOW block, below this one, and #7530 and #9095 match only in a debt entry; none changes the O_CREAT|O_EXCL check.
  • #6044 moves GuestFilesystem.cpp to tests/files/; if it lands first, the new cases move with the file in the rebase.

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); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959688426 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9496). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-21T23:22:38Z. --- ### What On Windows, `open` with `O_CREAT|O_EXCL` on a symbolic link whose target is missing succeeded and created the target. FreeBSD 11.4's [`vn_open_cred`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_vnops.c#L204-L266) only adds `FOLLOW` when `O_EXCL` is not set, so the lookup finds the link itself and the call fails with `EEXIST` whatever the link points to, as POSIX requires for `O_CREAT|O_EXCL` on a symbolic link. `OpenNative` now fails `O_CREAT|O_EXCL` with `EEXIST` before the host open when the last component is a reparse point. Any reparse point is an existing name, so the answer does not depend on its kind. A link to an existing file already failed with `EEXIST` and still does; `O_CREAT` without `O_EXCL` still creates the target through a dangling link, as FreeBSD does. Linux already fails in the host `open` and is unchanged. ### Tested Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `-DBUILD_TESTING=ON`, on `main` d6eafa54d0 (rebased), Developer Mode on so links can be created. - `guest_filesystem`: new checks with a dangling link: `open` with `O_CREAT|O_EXCL|O_WRONLY` fails with `EEXIST`, `sceKernelOpen` returns `0x80020011`, and no target appears; `O_CREAT|O_WRONLY` then creates the target through the link; `O_CREAT|O_EXCL` fails with `EEXIST` again. The link and target are removed afterwards; without link permission the checks are skipped with a message. On `main` the test fails at the first new check (the open returns a descriptor); with this PR it passes. - Full suite on `main` d6eafa54d0 and on `main` with #9442, #9469, #9474, #9487 and #9496 merged together, same machine: 1890 tests each, identical results (1869 passed, 18 skipped; on both, the 3 `agc_driver_sample_order*` tests fail and `agc_driver_image_array_window_past_layer_limit` is not built, as its 64 KiB `alignas` is rejected by this MinGW toolchain). - `python tools/check_conventions.py --base upstream/main`: passes. - Not tested: Linux (no change there; the new checks create the link with `std::filesystem::create_symlink`), a console, a title run. ### Overlaps - `tools/pr_overlap.py --branch` on the rebased head lists no direct overlap. Of the 9 pull requests it could not compare, #7201 adds a macOS-only `O_CREAT` check after the `O_NOFOLLOW` block, below this one, and #7530 and #9095 match only in a debt entry; none changes the `O_CREAT|O_EXCL` check. - #6044 moves `GuestFilesystem.cpp` to `tests/files/`; if it lands first, the new cases move with the file in the rebase. ### 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`); no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source: none added - [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 AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-21 23:27:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:27:15Z.

Review: APPROVED


Reviewed the Windows reparse-point handling and the cross-platform regression cases. The check recognizes the link itself before the exclusive create can follow a dangling link to its target; O_CREAT without O_EXCL remains covered as a separate case. The guest_filesystem tests verify both the errno and guest error mapping, ensure no target is created on failure, and clean up the link and target. The PR checks for conventions, intake, eligibility, labels and report pass; hosted product build jobs are skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607466289 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9496#pullrequestreview-5607466289). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:27:15Z. **Review:** APPROVED --- Reviewed the Windows reparse-point handling and the cross-platform regression cases. The check recognizes the link itself before the exclusive create can follow a dangling link to its target; `O_CREAT` without `O_EXCL` remains covered as a separate case. The `guest_filesystem` tests verify both the errno and guest error mapping, ensure no target is created on failure, and clean up the link and target. The PR checks for conventions, intake, eligibility, labels and report pass; hosted product build jobs are skipped.
MarcZX10 commented 2026-10-22 02:09:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:09:14Z.

Review: APPROVED


Rechecked the current head and overlap state. The Windows reparse-point check runs before exclusive create can follow a dangling link; ordinary O_CREAT through that link remains covered. Regression checks verify POSIX and SCE errors, target non-creation, later ordinary creation, and cleanup. The author reports a Windows red/green run and a broader suite; hosted eligibility, conventions, intake, labels and report pass, while product/relinker jobs are skipped. The #5021/#6936/#7201 manual shared-file warnings were not found as concrete overlaps in the reviewed diff. I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608470468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9496#pullrequestreview-5608470468). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:09:14Z. **Review:** APPROVED --- Rechecked the current head and overlap state. The Windows reparse-point check runs before exclusive create can follow a dangling link; ordinary `O_CREAT` through that link remains covered. Regression checks verify POSIX and SCE errors, target non-creation, later ordinary creation, and cleanup. The author reports a Windows red/green run and a broader suite; hosted eligibility, conventions, intake, labels and report pass, while product/relinker jobs are skipped. The #5021/#6936/#7201 manual shared-file warnings were not found as concrete overlaps in the reviewed diff. I did not run local tests.
MarcZX10 commented 2026-10-22 04:26:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:26:20Z.

Review: DISMISSED


The Windows reparse-point check and regression cases are well targeted: they verify EEXIST through both POSIX and SCE entry points, confirm the dangling target is not created, then cover ordinary O_CREAT through the link and cleanup. The earlier manual overlap review also found the #5021/#6936/#7201 warnings were distinct. However, the tests and branch are based on a6dcea9279; upstream main is now ab347d144d. Please rebase onto current main, rerun the focused guest_filesystem regression and conventions check, and refresh the overlap scan/manual uncomparable-file review. Hosted product jobs are skipped; I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609254773 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9496#pullrequestreview-5609254773). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:26:20Z. **Review:** DISMISSED --- The Windows reparse-point check and regression cases are well targeted: they verify `EEXIST` through both POSIX and SCE entry points, confirm the dangling target is not created, then cover ordinary `O_CREAT` through the link and cleanup. The earlier manual overlap review also found the #5021/#6936/#7201 warnings were distinct. However, the tests and branch are based on a6dcea9279; upstream main is now ab347d144d88fae054d9770cf0db8d3565735c02. Please rebase onto current main, rerun the focused `guest_filesystem` regression and conventions check, and refresh the overlap scan/manual uncomparable-file review. Hosted product jobs are skipped; I did not run local tests.
Gruzzberry commented 2026-10-22 06:49:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T06:49:05Z.


Rebased onto main d6eafa54d0. guest_filesystem passes on the new head, the new checks fail on that main without the change, and check_conventions.py passes. Full suite on main d6eafa54d0 and on main with #9442, #9469, #9474, #9487 and #9496 merged together: 1890 tests each, identical results. The overlap scan of the rebased head and a manual check of the pull requests it could not compare are in the description under Overlaps.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334631607 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9496#issuecomment-6334631607). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T06:49:05Z. --- Rebased onto `main` d6eafa54d0. `guest_filesystem` passes on the new head, the new checks fail on that `main` without the change, and `check_conventions.py` passes. Full suite on `main` d6eafa54d0 and on `main` with #9442, #9469, #9474, #9487 and #9496 merged together: 1890 tests each, identical results. The overlap scan of the rebased head and a manual check of the pull requests it could not compare are in the description under Overlaps.
Gruzzberry commented 2026-10-22 11:41:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:41:03Z.


Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current main. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6339857881 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9496#issuecomment-6339857881). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T11:41:03Z. --- Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current `main`. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.
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!9496
No description provided.