fix(libc): follow a Windows symbolic link in access #9474

Merged
Gruzzberry merged 1 commit from upstream-pr/9474 into main 2026-10-25 18:14:12 +00:00
Gruzzberry commented 2026-10-21 22:59:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-21T22:59:05Z.


What

On Windows, access read the attributes and the security descriptor of a symbolic link itself, not of its target: a dangling link passed F_OK and R_OK, a link to a read-only file passed W_OK, and a link to itself passed F_OK. FreeBSD 11.4's kern_accessat looks the path up with FOLLOW, so the target decides: ENOENT for a missing target, ELOOP for a loop, and the target's permissions.

When the resolved path is a reparse point, access now opens it without FILE_FLAG_OPEN_REPARSE_POINT (so Windows follows the link), takes the target's path with GetFinalPathNameByHandleW, and checks that path as before. A failed open goes through the existing error mapping, with ERROR_CANT_RESOLVE_FILENAME as ELOOP (62), as the guest stat maps it. Paths that are not reparse points take the same calls as on main. Linux already follows links in the host access 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_access: new checks with a dangling link (F_OK and R_OK fail with ENOENT), a link to itself (ELOOP), and a link to sample.txt (R_OK|W_OK passes; with the target read-only R_OK passes and W_OK fails with EACCES; with only the link read-only W_OK passes). 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 (access on the dangling link returns 0); with this PR it passes.
  • guest_filesystem, guest_path_case, guest_path_name_length, guest_appcontent (other callers of access): pass.
  • 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), a console, a title run.

Overlaps

  • #7447 adds an archive lookup at the start of access_nid_postfix. The two compose: its archive branch returns before the host checks, and this PR only changes the host checks after it (FollowedPath on the resolved path, the target for the attributes and the security descriptor). Either order works; whichever lands second rebases and keeps both, then reruns guest_access and #7447's archive access checks. Asked on #7447.
  • tools/pr_overlap.py --branch on the rebased head lists no direct overlap; the 2 pull requests it could not compare are #7447 (above) and #6044 (below).
  • #6044 moves GuestAccess.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. Merge order: after #7447 if both are ready; this PR then rebases and keeps both the archive lookup and the link following.
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959488077 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9474). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-21T22:59:05Z. --- ### What On Windows, `access` read the attributes and the security descriptor of a symbolic link itself, not of its target: a dangling link passed `F_OK` and `R_OK`, a link to a read-only file passed `W_OK`, and a link to itself passed `F_OK`. FreeBSD 11.4's [`kern_accessat`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_syscalls.c#L1824-L1870) looks the path up with `FOLLOW`, so the target decides: `ENOENT` for a missing target, `ELOOP` for a loop, and the target's permissions. When the resolved path is a reparse point, `access` now opens it without `FILE_FLAG_OPEN_REPARSE_POINT` (so Windows follows the link), takes the target's path with `GetFinalPathNameByHandleW`, and checks that path as before. A failed open goes through the existing error mapping, with `ERROR_CANT_RESOLVE_FILENAME` as `ELOOP` (62), as the guest `stat` maps it. Paths that are not reparse points take the same calls as on `main`. Linux already follows links in the host `access` 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_access`: new checks with a dangling link (`F_OK` and `R_OK` fail with `ENOENT`), a link to itself (`ELOOP`), and a link to `sample.txt` (`R_OK|W_OK` passes; with the target read-only `R_OK` passes and `W_OK` fails with `EACCES`; with only the link read-only `W_OK` passes). 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 (`access` on the dangling link returns 0); with this PR it passes. - `guest_filesystem`, `guest_path_case`, `guest_path_name_length`, `guest_appcontent` (other callers of `access`): pass. - 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`), a console, a title run. ### Overlaps - #7447 adds an archive lookup at the start of `access_nid_postfix`. The two compose: its archive branch returns before the host checks, and this PR only changes the host checks after it (`FollowedPath` on the resolved path, the target for the attributes and the security descriptor). Either order works; whichever lands second rebases and keeps both, then reruns `guest_access` and #7447's archive `access` checks. Asked on #7447. - `tools/pr_overlap.py --branch` on the rebased head lists no direct overlap; the 2 pull requests it could not compare are #7447 (above) and #6044 (below). - #6044 moves `GuestAccess.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. Merge order: after #7447 if both are ready; this PR then rebases and keeps both the archive lookup and the link following. - [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:00:49 +00:00 (Migrated from github.com)

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


The access change also edits the same access_nid_postfix region as #7447, which adds archive-aware access lookup. These changes address separate cases, but both need to compose at that function and may not apply cleanly if either lands first. Please coordinate the merge order with #7447’s author and update Depends on if one PR must land before the other; after rebasing, verify both symlink-target access and archive-entry access still pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328462730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9474#issuecomment-6328462730). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:00:49Z. --- The access change also edits the same `access_nid_postfix` region as #7447, which adds archive-aware access lookup. These changes address separate cases, but both need to compose at that function and may not apply cleanly if either lands first. Please coordinate the merge order with #7447’s author and update `Depends on` if one PR must land before the other; after rebasing, verify both symlink-target access and archive-entry access still pass.
Gruzzberry commented 2026-10-21 23:14:07 +00:00 (Migrated from github.com)

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


Full suite with this PR merged together with #9442, #9469, #9474 and #9487, against main on the same Windows 11 machine (MinGW-w64 GCC 15.2.0 r7, Release): 1875 tests, the same results except agc_import_settle_first_use, which also skips on main when its copies finish before the import returns (5 of 5 runs).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328658493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9474#issuecomment-6328658493). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-21T23:14:07Z. --- Full suite with this PR merged together with #9442, #9469, #9474 and #9487, against `main` on the same Windows 11 machine (MinGW-w64 GCC 15.2.0 r7, Release): 1875 tests, the same results except `agc_import_settle_first_use`, which also skips on `main` when its copies finish before the import returns (5 of 5 runs).
MarcZX10 commented 2026-10-22 04:31:12 +00:00 (Migrated from github.com)

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

Review: DISMISSED


The Windows symlink handling and tests cover the relevant semantics: following targets for F_OK/R_OK/W_OK, missing targets, loops, target permissions and link-only attributes; the non-link path is unchanged. The PR itself says #7447 also edits access_nid_postfix for archive paths, but no author-agreed order is recorded. Please coordinate with #7447’s author, document the order/Depends on relationship, and preserve both archive lookup and symlink following in the combined function. This branch and test report are based on a6dcea927, while upstream main is ab347d144d. Please rebase and rerun guest_access, the listed filesystem callers, conventions and current overlap checks. Hosted product jobs are skipped; I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609283747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9474#pullrequestreview-5609283747). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:31:12Z. **Review:** DISMISSED --- The Windows symlink handling and tests cover the relevant semantics: following targets for `F_OK`/`R_OK`/`W_OK`, missing targets, loops, target permissions and link-only attributes; the non-link path is unchanged. The PR itself says #7447 also edits `access_nid_postfix` for archive paths, but no author-agreed order is recorded. Please coordinate with #7447’s author, document the order/Depends on relationship, and preserve both archive lookup and symlink following in the combined function. This branch and test report are based on a6dcea927, while upstream main is ab347d144d88fae054d9770cf0db8d3565735c02. Please rebase and rerun `guest_access`, the listed filesystem callers, conventions and current overlap checks. Hosted product jobs are skipped; I did not run local tests.
Gruzzberry commented 2026-10-22 06:49:02 +00:00 (Migrated from github.com)

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


Rebased onto main d6eafa54d0. guest_access, guest_filesystem, guest_path_case, guest_path_name_length and guest_appcontent 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.

On #7447: I asked its author on #7447. The two compose, as its archive branch returns before the host checks this PR changes, so either order works; whichever lands second keeps both and reruns guest_access and the archive access checks. The description records this under Overlaps.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334630885 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9474#issuecomment-6334630885). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T06:49:02Z. --- Rebased onto `main` d6eafa54d0. `guest_access`, `guest_filesystem`, `guest_path_case`, `guest_path_name_length` and `guest_appcontent` 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. On #7447: I asked its author on #7447. The two compose, as its archive branch returns before the host checks this PR changes, so either order works; whichever lands second keeps both and reruns `guest_access` and the archive `access` checks. The description records this under Overlaps.
Gruzzberry commented 2026-10-22 11:40:58 +00:00 (Migrated from github.com)

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


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