fix(libkernel_sys): throw from fchmodat on a symbolic link as lchmod does #14101

Merged
QW1CKS merged 2 commits from upstream-pr/14101 into main 2026-11-05 23:44:38 +00:00
QW1CKS commented 2026-10-31 19:00:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QW1CKS on 2026-10-31T19:00:01Z.


What

fchmodat with AT_SYMLINK_NOFOLLOW on a symbolic link returned 0 and changed nothing on Windows and Linux, while lchmod on the same link threw through NotImplemented_nid_no_patch. The same unsupported operation was a fabricated success through one entry point and a throw through the other, against the rule that a path either does what it should or throws.

fchmodat now throws in that branch on the hosts whose fchmodat cannot change a link's own mode; macOS still calls the host fchmodat as before. lchmod drops its own symlink check and reaches the same throw through fchmodat, as FreeBSD's sys_lchmod forwards. The fchmodat entry under Silent stubs in docs/dev/debt/libkernel_sys.md is removed and both entries are cut to what is still open.

Tested

Linux x86-64, Ubuntu 24.04, GCC 13.3, Release relinker-unrelated full build with BUILD_TESTING=ON.

  • guest_kernel_sys: passes with the change and with Export.cpp reverted to main, so the test exercises the surrounding lchmod and regular-file cases on both trees. Per review, the added fchmodat throw assertion was dropped: it would fail a future implementation that correctly changes the link's own mode.
  • python3 tools/check_conventions.py --base origin/main: clean.
  • Windows and macOS were not built or run, and the console's own behaviour is not measured.

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: #14088
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5100600869 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14101). Originally posted by [QW1CKS](https://github.com/QW1CKS) on 2026-10-31T19:00:01Z. --- ### What `fchmodat` with `AT_SYMLINK_NOFOLLOW` on a symbolic link returned 0 and changed nothing on Windows and Linux, while `lchmod` on the same link threw through `NotImplemented_nid_no_patch`. The same unsupported operation was a fabricated success through one entry point and a throw through the other, against the rule that a path either does what it should or throws. `fchmodat` now throws in that branch on the hosts whose `fchmodat` cannot change a link's own mode; macOS still calls the host `fchmodat` as before. `lchmod` drops its own symlink check and reaches the same throw through `fchmodat`, as FreeBSD's `sys_lchmod` forwards. The `fchmodat` entry under **Silent stubs** in `docs/dev/debt/libkernel_sys.md` is removed and both entries are cut to what is still open. ### Tested Linux x86-64, Ubuntu 24.04, GCC 13.3, Release relinker-unrelated full build with `BUILD_TESTING=ON`. - `guest_kernel_sys`: passes with the change and with `Export.cpp` reverted to `main`, so the test exercises the surrounding `lchmod` and regular-file cases on both trees. Per review, the added `fchmodat` throw assertion was dropped: it would fail a future implementation that correctly changes the link's own mode. - `python3 tools/check_conventions.py --base origin/main`: clean. - Windows and macOS were not built or run, and the console's own behaviour is not measured. ### 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: #14088 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-31 19:09:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T19:09:43Z.

Review: APPROVED


Reviewed — looks good

At head f0cef5ef214ee5f0978298ad18dcab70e6cff70b, lchmod now reaches the same explicit unsupported symlink-mode path as fchmodat(..., AT_SYMLINK_NOFOLLOW) on Linux and Windows, resolving the inconsistency in issue #14088.

What I ran

Reviewed head f0cef5ef214ee5f0978298ad18dcab70e6cff70b against base 16452da93473aa42d8054da95f89e44a2a1d8d97. The PR previewed cleanly against current main. Environment: Debian 12, Python 3.11.2, GCC 12.2.0.

git diff --check 16452da93473aa42d8054da95f89e44a2a1d8d97...f0cef5ef214ee5f0978298ad18dcab70e6cff70b
python3 tools/check_conventions.py --base 16452da93473aa42d8054da95f89e44a2a1d8d97 --head f0cef5ef214ee5f0978298ad18dcab70e6cff70b
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14101
gh pr checks 14101 -R boykopovar/AnyPS5

Results

Check Result
Diff check and repository conventions Passed
Dependency/merge preview Passed
Hosted conventions, intake and labels Passed
Local guest_kernel_sys Not run locally; the author reports it passed on Ubuntu 24.04/GCC 13.3
ABI/test-quality helper scripts Could not run in the isolated precheck checkout because the local-only scripts are absent
Unedited command output
All conventions checks passed.
conventions	pass	19s	https://github.com/boykopovar/AnyPS5/actions/runs/41232082420/job/124628223490
intake	pass	20s	https://github.com/boykopovar/AnyPS5/actions/runs/41232082405/job/124628222974
labels	pass	8s	https://github.com/boykopovar/AnyPS5/actions/runs/41232082397/job/124628223300

Not verified

I did not independently run the C++ test or verify macOS/Windows runtime behavior or console behavior. The added symlink regression executes on Linux; the author reports the Linux test pass, and notes Windows/macOS were not run.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5724460727 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14101#pullrequestreview-5724460727). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T19:09:43Z. **Review:** APPROVED --- # Reviewed — looks good At head `f0cef5ef214ee5f0978298ad18dcab70e6cff70b`, `lchmod` now reaches the same explicit unsupported symlink-mode path as `fchmodat(..., AT_SYMLINK_NOFOLLOW)` on Linux and Windows, resolving the inconsistency in [issue #14088](https://github.com/boykopovar/AnyPS5/issues/14088). ## What I ran Reviewed head `f0cef5ef214ee5f0978298ad18dcab70e6cff70b` against base `16452da93473aa42d8054da95f89e44a2a1d8d97`. The PR previewed cleanly against current `main`. Environment: Debian 12, Python 3.11.2, GCC 12.2.0. ```sh git diff --check 16452da93473aa42d8054da95f89e44a2a1d8d97...f0cef5ef214ee5f0978298ad18dcab70e6cff70b python3 tools/check_conventions.py --base 16452da93473aa42d8054da95f89e44a2a1d8d97 --head f0cef5ef214ee5f0978298ad18dcab70e6cff70b python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14101 gh pr checks 14101 -R boykopovar/AnyPS5 ``` ## Results | Check | Result | |---|---| | Diff check and repository conventions | Passed | | Dependency/merge preview | Passed | | Hosted conventions, intake and labels | Passed | | Local `guest_kernel_sys` | Not run locally; the author reports it passed on Ubuntu 24.04/GCC 13.3 | | ABI/test-quality helper scripts | Could not run in the isolated precheck checkout because the local-only scripts are absent | <details> <summary>Unedited command output</summary> ```text All conventions checks passed. conventions pass 19s https://github.com/boykopovar/AnyPS5/actions/runs/41232082420/job/124628223490 intake pass 20s https://github.com/boykopovar/AnyPS5/actions/runs/41232082405/job/124628222974 labels pass 8s https://github.com/boykopovar/AnyPS5/actions/runs/41232082397/job/124628223300 ``` </details> ## Not verified I did not independently run the C++ test or verify macOS/Windows runtime behavior or console behavior. The added symlink regression executes on Linux; the author reports the Linux test pass, and notes Windows/macOS were not run.
slopgobblercobbler commented 2026-10-31 19:13:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-31T19:13:43Z.

Review: COMMENTED


Audited the implementation and Windows behavior:

  • FreeBSD 11.4 alignment: In FreeBSD (sys/kern/vfs_syscalls.c), sys_lchmod is defined directly as a forwarder to kern_fchmodat(td, AT_FDCWD, path, UIO_USERSPACE, mode, AT_SYMLINK_NOFOLLOW). Simplifying AnyPS5's lchmod to forward directly into fchmodat_nid_postfix matches FreeBSD kernel structure and eliminates duplicated path resolution and reparse point checks.
  • Windows host semantics: On Windows NTFS, reparse points (FILE_ATTRIBUTE_REPARSE_POINT) do not support independent POSIX file modes on the link object itself. Replacing the silent return 0 in fchmodat with NotImplemented_nid_no_patch removes a fabricated success stub and ensures consistent throw semantics across both entry points on hosts without native symlink mode manipulation.
  • Error precedence: Invalid flag combinations are caught with EINVAL (22) and null path pointers with EFAULT (14) via CopyPath prior to symlink inspection.
  • Conventions & Debt: Verified python tools/check_conventions.py --base upstream/main --head HEAD passes cleanly with 0 findings, and the silent stub entry in docs/dev/debt/libkernel_sys.md was appropriately removed.

Great cleanup that eliminates silent divergence between lchmod and fchmodat.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5724472396 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14101#pullrequestreview-5724472396). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-31T19:13:43Z. **Review:** COMMENTED --- Audited the implementation and Windows behavior: - FreeBSD 11.4 alignment: In FreeBSD (`sys/kern/vfs_syscalls.c`), `sys_lchmod` is defined directly as a forwarder to `kern_fchmodat(td, AT_FDCWD, path, UIO_USERSPACE, mode, AT_SYMLINK_NOFOLLOW)`. Simplifying AnyPS5's `lchmod` to forward directly into `fchmodat_nid_postfix` matches FreeBSD kernel structure and eliminates duplicated path resolution and reparse point checks. - Windows host semantics: On Windows NTFS, reparse points (`FILE_ATTRIBUTE_REPARSE_POINT`) do not support independent POSIX file modes on the link object itself. Replacing the silent return 0 in `fchmodat` with `NotImplemented_nid_no_patch` removes a fabricated success stub and ensures consistent throw semantics across both entry points on hosts without native symlink mode manipulation. - Error precedence: Invalid flag combinations are caught with `EINVAL` (22) and null path pointers with `EFAULT` (14) via `CopyPath` prior to symlink inspection. - Conventions & Debt: Verified `python tools/check_conventions.py --base upstream/main --head HEAD` passes cleanly with 0 findings, and the silent stub entry in `docs/dev/debt/libkernel_sys.md` was appropriately removed. Great cleanup that eliminates silent divergence between `lchmod` and `fchmodat`.
MarcZX10 commented 2026-11-02 21:05:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T21:05:43Z.

Review: APPROVED


Re-checked — new head, approved

The rebase preserves the reviewed fchmodat/lchmod implementation, current conventions and labels checks pass, and the Linux test is reported passing after the rebase; I found no blocking defect.

What I ran

Reviewed exact head 865b873c4bad99d6cbb23d90136382ff2f1655bf against base/current main 9090972b7e91fd266819cbd77a8b058e177b5682; GitHub and the repository precheck report a clean merge preview. Environment: Debian 12 x86_64, Linux 6.1.0-54-amd64, Python 3.11.2, Git 2.39.5, GCC 12.2.0. No local build or PR test suite was run.

git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...865b873c4bad99d6cbb23d90136382ff2f1655bf
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14101
python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682 --head 865b873c4bad99d6cbb23d90136382ff2f1655bf
gh pr checks 14101 --repo boykopovar/AnyPS5
python3 - <<'PY'
import subprocess
commits = ['e7f1dcec9c', 'f0cef5ef214ee5f0978298ad18dcab70e6cff70b', '865b873c4bad99d6cbb23d90136382ff2f1655bf']
path = 'core/libs/prx/libkernel_sys/Export.cpp'
def body(commit, start, end):
    source = subprocess.check_output(['git', 'show', f'{commit}:{path}'], text=True)
    i = source.index(start)
    return source[i:source.index(end, i)]
for name, start, end in [('fchmodat', 'int APS5_VABI fchmodat_nid_postfix(', 'int APS5_VABI lchmod_nid_postfix('), ('lchmod', 'int APS5_VABI lchmod_nid_postfix(', 'int APS5_VABI fchown_nid_postfix(')]:
    versions = [body(commit, start, end) for commit in commits]
    print(name, 'all_identical=' + str(versions[0] == versions[1] == versions[2]), 'lines=' + str(len(versions[0].splitlines())))
PY

The Windows build and test below were reported by another contributor at e7f1dcec9c, not run by me. I compared both changed function bodies at that head, the previous reviewed head, and this head; they are identical.

Results

Check Result Note
Diff and conventions passed No diff errors; all convention checks passed.
Current-base merge preview passed Clean against current main.
Hosted conventions and labels passed Both completed on the reviewed head.
Linux guest_kernel_sys passed Author-reported after rebase; tested SHA not stated.
Windows build and focused CTest passed Contributor-reported at e7f1dcec9c; function bodies match this head.
Local build and test suite not run No local compilation or PR tests.
Repository precheck bundle failed Isolated snapshot lacks two workspace-only helper scripts.
Unedited command output and test evidence

Diff check produced no output and exited 0.

All conventions checks passed.
conventions	pass	37s	https://github.com/boykopovar/AnyPS5/actions/runs/41520995645/job/125536668538
labels	pass	12s	https://github.com/boykopovar/AnyPS5/actions/runs/41520995525/job/125536666898
fchmodat all_identical=True lines=37
lchmod all_identical=True lines=8

Precheck helper errors:

/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14101-865b873c4bad/head-865b873c4bad-8419fb82/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14101-865b873c4bad/head-865b873c4bad-8419fb82/tools/pr_test_quality.py': [Errno 2] No such file or directory

Windows test report at the earlier head, supplied by JJenkx in this PR comment:

- Build: clean, no new warnings in `Export.cpp`.
- `ctest -R ^guest_kernel_sys$ --repeat until-fail:3`: passes 3/3.

As agreed in review, `guest_kernel_sys` has no assertion on that throw, so this run does not exercise it.

The author reports guest_kernel_sys and check_conventions.py passing after the rebase in this PR comment; that report does not state the tested SHA.

Negative control

Assertion Code change Test failed?
Unsupported symlink-mode calls throw on Linux/Windows None; no assertion or local test binary exercised this branch. Could not exercise.

Findings

Blocking

None found in the reviewed implementation.

Non-blocking

  • The new throw branch has no regression assertion. The reported Windows test explicitly says it did not exercise the throw; the author reports the Linux suite passes without an assertion for it. I reviewed the branch directly and found its error handling consistent with the documented unsupported-host behavior.

Sources

Not verified

I did not run a local build, CTest, a negative control, macOS tests or console behavior. The Linux test result is author-reported without an exact SHA; the Windows run is contributor-reported at the earlier head, though the two changed function bodies are identical at the reviewed head.

To get this to a good state

No code change is requested. I will rerun the same review checks if the head changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5743337661 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14101#pullrequestreview-5743337661). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T21:05:43Z. **Review:** APPROVED --- # Re-checked — new head, approved The rebase preserves the reviewed `fchmodat`/`lchmod` implementation, current conventions and labels checks pass, and the Linux test is reported passing after the rebase; I found no blocking defect. ## What I ran Reviewed exact head `865b873c4bad99d6cbb23d90136382ff2f1655bf` against base/current `main` `9090972b7e91fd266819cbd77a8b058e177b5682`; GitHub and the repository precheck report a clean merge preview. Environment: Debian 12 x86_64, Linux 6.1.0-54-amd64, Python 3.11.2, Git 2.39.5, GCC 12.2.0. No local build or PR test suite was run. ```sh git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...865b873c4bad99d6cbb23d90136382ff2f1655bf python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14101 python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682 --head 865b873c4bad99d6cbb23d90136382ff2f1655bf gh pr checks 14101 --repo boykopovar/AnyPS5 python3 - <<'PY' import subprocess commits = ['e7f1dcec9c', 'f0cef5ef214ee5f0978298ad18dcab70e6cff70b', '865b873c4bad99d6cbb23d90136382ff2f1655bf'] path = 'core/libs/prx/libkernel_sys/Export.cpp' def body(commit, start, end): source = subprocess.check_output(['git', 'show', f'{commit}:{path}'], text=True) i = source.index(start) return source[i:source.index(end, i)] for name, start, end in [('fchmodat', 'int APS5_VABI fchmodat_nid_postfix(', 'int APS5_VABI lchmod_nid_postfix('), ('lchmod', 'int APS5_VABI lchmod_nid_postfix(', 'int APS5_VABI fchown_nid_postfix(')]: versions = [body(commit, start, end) for commit in commits] print(name, 'all_identical=' + str(versions[0] == versions[1] == versions[2]), 'lines=' + str(len(versions[0].splitlines()))) PY ``` The Windows build and test below were reported by another contributor at `e7f1dcec9c`, not run by me. I compared both changed function bodies at that head, the previous reviewed head, and this head; they are identical. ## Results | Check | Result | Note | |---|---|---| | Diff and conventions | passed | No diff errors; all convention checks passed. | | Current-base merge preview | passed | Clean against current `main`. | | Hosted conventions and labels | passed | Both completed on the reviewed head. | | Linux `guest_kernel_sys` | passed | Author-reported after rebase; tested SHA not stated. | | Windows build and focused CTest | passed | Contributor-reported at `e7f1dcec9c`; function bodies match this head. | | Local build and test suite | not run | No local compilation or PR tests. | | Repository precheck bundle | failed | Isolated snapshot lacks two workspace-only helper scripts. | <details><summary>Unedited command output and test evidence</summary> Diff check produced no output and exited 0. ```text All conventions checks passed. conventions pass 37s https://github.com/boykopovar/AnyPS5/actions/runs/41520995645/job/125536668538 labels pass 12s https://github.com/boykopovar/AnyPS5/actions/runs/41520995525/job/125536666898 fchmodat all_identical=True lines=37 lchmod all_identical=True lines=8 ``` Precheck helper errors: ```text /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14101-865b873c4bad/head-865b873c4bad-8419fb82/tools/pr_abi_audit.py': [Errno 2] No such file or directory /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14101-865b873c4bad/head-865b873c4bad-8419fb82/tools/pr_test_quality.py': [Errno 2] No such file or directory ``` Windows test report at the earlier head, supplied by `JJenkx` in [this PR comment](https://github.com/boykopovar/AnyPS5/pull/14101#issuecomment-6549962826): ```text - Build: clean, no new warnings in `Export.cpp`. - `ctest -R ^guest_kernel_sys$ --repeat until-fail:3`: passes 3/3. As agreed in review, `guest_kernel_sys` has no assertion on that throw, so this run does not exercise it. ``` The author reports `guest_kernel_sys` and `check_conventions.py` passing after the rebase in [this PR comment](https://github.com/boykopovar/AnyPS5/pull/14101#issuecomment-6588301730); that report does not state the tested SHA. </details> ## Negative control | Assertion | Code change | Test failed? | |---|---|---| | Unsupported symlink-mode calls throw on Linux/Windows | None; no assertion or local test binary exercised this branch. | Could not exercise. | ## Findings ### Blocking None found in the reviewed implementation. ### Non-blocking - The new throw branch has no regression assertion. The reported Windows test explicitly says it did not exercise the throw; the author reports the Linux suite passes without an assertion for it. I reviewed the branch directly and found its error handling consistent with the documented unsupported-host behavior. ## Sources - [`fchmodat` and `lchmod` at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/865b873c4bad99d6cbb23d90136382ff2f1655bf/core/libs/prx/libkernel_sys/Export.cpp#L997-L1039) - [FreeBSD 11.4 `sys_lchmod` source](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/vfs_syscalls.c#L2490-L2496) ## Not verified I did not run a local build, CTest, a negative control, macOS tests or console behavior. The Linux test result is author-reported without an exact SHA; the Windows run is contributor-reported at the earlier head, though the two changed function bodies are identical at the reviewed head. ## To get this to a good state No code change is requested. I will rerun the same review checks if the head changes.
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!14101
No description provided.