fix(libkernel): follow a Windows symbolic link in chmod #9487

Merged
Gruzzberry merged 1 commit from upstream-pr/9487 into main 2026-10-25 17:25:25 +00:00
Gruzzberry commented 2026-10-21 23:13:57 +00:00 (Migrated from github.com)

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


What

On Windows, chmod through a symbolic link changed the link and left the file it names unchanged, and a dangling link succeeded. _wchmod sets the read-only attribute of the path it is given without following a link. FreeBSD 11.4's sys_chmod calls kern_fchmodat with flag 0, which looks the path up with FOLLOW.

NativeChmod now opens a reparse point without FILE_FLAG_OPEN_REPARSE_POINT (so Windows follows it), takes the target's path from the handle and changes that path. A failed open goes through WindowsOpenError_nid_no_patch: ENOENT for a missing target, ELOOP for a loop. The handle-to-path code moves out of WindowsDescriptorPath_nid_no_patch into HandlePath so both use it; fchmod goes through the same descriptor path as before. Paths that are not reparse points take the same _wchmod call as on main. fchmodat with AT_SYMLINK_NOFOLLOW returns before reaching chmod and is unchanged. Linux 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 next to the fchmod ones. Through a link to the test file, chmod 0400 clears the file's owner write bit while the link keeps no read-only attribute, and chmod 0600 restores it; a dangling link fails with ENOENT; a link to itself fails with ELOOP (Windows only). The links are removed afterwards; without link permission the checks are skipped with a message. On main the test fails at the first new check (the file stays writable); 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 links with std::filesystem::create_symlink, and the loop check is Windows only), a console, a title run.

Overlaps

  • tools/pr_overlap.py --branch on the rebased head lists no direct overlap. Of the 12 pull requests it could not compare, #7447 only declares fchmod in a test and #8520 calls WindowsDescriptorPath_nid_no_patch, whose result this PR keeps; neither changes NativeChmod or the handle-path code.
  • #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:4959617569 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9487). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-21T23:13:57Z. --- ### What On Windows, `chmod` through a symbolic link changed the link and left the file it names unchanged, and a dangling link succeeded. `_wchmod` sets the read-only attribute of the path it is given without following a link. FreeBSD 11.4's [`sys_chmod`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_syscalls.c#L2452-L2457) calls `kern_fchmodat` with flag 0, which looks the path up with `FOLLOW`. `NativeChmod` now opens a reparse point without `FILE_FLAG_OPEN_REPARSE_POINT` (so Windows follows it), takes the target's path from the handle and changes that path. A failed open goes through `WindowsOpenError_nid_no_patch`: `ENOENT` for a missing target, `ELOOP` for a loop. The handle-to-path code moves out of `WindowsDescriptorPath_nid_no_patch` into `HandlePath` so both use it; `fchmod` goes through the same descriptor path as before. Paths that are not reparse points take the same `_wchmod` call as on `main`. `fchmodat` with `AT_SYMLINK_NOFOLLOW` returns before reaching `chmod` and is unchanged. Linux 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 next to the `fchmod` ones. Through a link to the test file, `chmod 0400` clears the file's owner write bit while the link keeps no read-only attribute, and `chmod 0600` restores it; a dangling link fails with `ENOENT`; a link to itself fails with `ELOOP` (Windows only). The links are removed afterwards; without link permission the checks are skipped with a message. On `main` the test fails at the first new check (the file stays writable); 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 links with `std::filesystem::create_symlink`, and the loop check is Windows only), a console, a title run. ### Overlaps - `tools/pr_overlap.py --branch` on the rebased head lists no direct overlap. Of the 12 pull requests it could not compare, #7447 only declares `fchmod` in a test and #8520 calls `WindowsDescriptorPath_nid_no_patch`, whose result this PR keeps; neither changes `NativeChmod` or the handle-path code. - #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:15:43 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed the Windows chmod path and its focused link cases. The non-link path retains its existing _wchmod behavior; for a reparse point the code opens the target (without OPEN_REPARSE_POINT), resolves the handle to the target path, records that target as written, and then changes its mode. The resulting error path uses the repository Windows error mapper, which maps ERROR_CANT_RESOLVE_FILENAME to ELOOP and missing paths to ENOENT. The tests cover changing permissions through a link, ensuring the link itself stays unchanged on Windows, a dangling target, and a loop; they clean up the links afterward. I checked the neighboring open filesystem PRs #9469 and #9474: they touch separate Stdio.cpp regions and the same test file at separate cases, with no overlapping behavior that needs a Depends on relationship. Conventions, intake, eligibility, labels and progress-report checks pass. The automatic product build jobs were skipped; the PR reports Windows focused testing locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607386391 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9487#pullrequestreview-5607386391). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:15:43Z. **Review:** APPROVED --- Reviewed the Windows chmod path and its focused link cases. The non-link path retains its existing _wchmod behavior; for a reparse point the code opens the target (without OPEN_REPARSE_POINT), resolves the handle to the target path, records that target as written, and then changes its mode. The resulting error path uses the repository Windows error mapper, which maps ERROR_CANT_RESOLVE_FILENAME to ELOOP and missing paths to ENOENT. The tests cover changing permissions through a link, ensuring the link itself stays unchanged on Windows, a dangling target, and a loop; they clean up the links afterward. I checked the neighboring open filesystem PRs #9469 and #9474: they touch separate Stdio.cpp regions and the same test file at separate cases, with no overlapping behavior that needs a Depends on relationship. Conventions, intake, eligibility, labels and progress-report checks pass. The automatic product build jobs were skipped; the PR reports Windows focused testing locally.
MarcZX10 commented 2026-10-22 02:14:55 +00:00 (Migrated from github.com)

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

Review: APPROVED


Re-reviewed the Windows path and regression cases. The non-reparse path retains _wchmod; a reparse point is opened following its target, resolved to the target path, recorded as the written path, and then chmodded. The error mapping covers a missing target and a loop. Tests cover changing the target through the symlink, checking the link's own attributes, dangling and loop cases, and cleanup. I manually checked the reported shared Stdio.cpp warnings (#5021, #6879, #6936 and #7201); none changes the chmod or handle-path helpers. Hosted eligibility, intake, conventions, labels and progress-report checks pass; product/relinker jobs are skipped. The author reports focused Windows testing; I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608504171 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9487#pullrequestreview-5608504171). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:14:55Z. **Review:** APPROVED --- Re-reviewed the Windows path and regression cases. The non-reparse path retains `_wchmod`; a reparse point is opened following its target, resolved to the target path, recorded as the written path, and then chmodded. The error mapping covers a missing target and a loop. Tests cover changing the target through the symlink, checking the link's own attributes, dangling and loop cases, and cleanup. I manually checked the reported shared `Stdio.cpp` warnings (#5021, #6879, #6936 and #7201); none changes the chmod or handle-path helpers. Hosted eligibility, intake, conventions, labels and progress-report checks pass; product/relinker jobs are skipped. The author reports focused Windows testing; I did not run local tests.
MarcZX10 commented 2026-10-22 04:29:00 +00:00 (Migrated from github.com)

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

Review: DISMISSED


The chmod path appears correct for the cases reported: non-reparse paths keep _wchmod, a reparse point is followed through a handle-derived target path, and tests cover target mode changes, dangling targets, loops, and cleanup. The prior manual review found the #5021/#6879/#6936/#7201 Stdio warnings outside the chmod/helper path, and #6044’s GuestFilesystem changes were in separate cases. The current branch and Windows tests are based on a6dcea9279, while upstream main is ab347d144d. Please rebase onto current main, rerun the focused guest_filesystem checks and conventions, then refresh overlap/manual comparisons. I could not retrieve the path-filtered PR patches for the warned PRs in this pass, so I am relying on the earlier review’s manual diff; do not treat this message as a fresh independent diff verification. Hosted product jobs are skipped; I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609270487 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9487#pullrequestreview-5609270487). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:29:00Z. **Review:** DISMISSED --- The chmod path appears correct for the cases reported: non-reparse paths keep `_wchmod`, a reparse point is followed through a handle-derived target path, and tests cover target mode changes, dangling targets, loops, and cleanup. The prior manual review found the #5021/#6879/#6936/#7201 Stdio warnings outside the chmod/helper path, and #6044’s GuestFilesystem changes were in separate cases. The current branch and Windows tests are based on a6dcea9279, while upstream main is ab347d144d88fae054d9770cf0db8d3565735c02. Please rebase onto current main, rerun the focused `guest_filesystem` checks and conventions, then refresh overlap/manual comparisons. I could not retrieve the path-filtered PR patches for the warned PRs in this pass, so I am relying on the earlier review’s manual diff; do not treat this message as a fresh independent diff verification. Hosted product jobs are skipped; I did not run local tests.
Gruzzberry commented 2026-10-22 06:49:03 +00:00 (Migrated from github.com)

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


Rebased onto main d6eafa54d0. guest_filesystem and guest_kernel_sys pass 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:6334631191 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9487#issuecomment-6334631191). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T06:49:03Z. --- Rebased onto `main` d6eafa54d0. `guest_filesystem` and `guest_kernel_sys` pass 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:00 +00:00 (Migrated from github.com)

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


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:6339857071 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9487#issuecomment-6339857071). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T11:41:00Z. --- 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!9487
No description provided.