Skip to content

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

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
QW1CKS:fix/libkernel-fchmodat-symlink-throw
Nov 5, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
QW1CKS:fix/libkernel-fchmodat-symlink-throw

Conversation

@QW1CKS

@QW1CKS QW1CKS commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

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: libkernel_sys: fchmodat silently succeeds on a symbolic link where lchmod throws #14088
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@slopgobblercobbler slopgobblercobbler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@QW1CKS, please drop the three new fchmodatThrew test lines and keep the rest of the change. They require the unimplemented symlink-mode operation to throw, so a future implementation that correctly changes the link's mode would fail this test. The existing regular-file mode and argument-error checks are useful coverage to retain.

QW1CKS commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Dropped in e7f1dcec9c: the three fchmodatThrew lines are gone and the rest of the change is unchanged. guest_kernel_sys passes on Linux, and check_conventions.py --base origin/main is clean. The Tested section now records that no new assertion is added and why.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

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_sys/Export.cpp
PR 9019 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9097 core/libs/prx/libkernel_sys/Export.cpp
PR 9161 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9162 docs/dev/debt/libkernel_sys.md
PR 9297 docs/dev/debt/libkernel_sys.md
PR 9302 docs/dev/debt/libkernel_sys.md
PR 9389 core/libs/prx/libkernel_sys/Export.cpp
PR 9537 docs/dev/debt/libkernel_sys.md
PR 9713 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 10016 core/libs/prx/libkernel_sys/Export.cpp
PR 10332 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 10335 docs/dev/debt/libkernel_sys.md
PR 10657 docs/dev/debt/libkernel_sys.md
PR 11031 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 11034 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 11212 docs/dev/debt/libkernel_sys.md
PR 12130 docs/dev/debt/libkernel_sys.md
PR 12506 docs/dev/debt/libkernel_sys.md
PR 12642 docs/dev/debt/libkernel_sys.md
PR 13127 docs/dev/debt/libkernel_sys.md
PR 13129 docs/dev/debt/libkernel_sys.md
PR 13253 docs/dev/debt/libkernel_sys.md
PR 13256 docs/dev/debt/libkernel_sys.md
PR 13286 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 14085 docs/dev/debt/libkernel_sys.md
PR 14212 docs/dev/debt/libkernel_sys.md
PR 14216 docs/dev/debt/libkernel_sys.md
PR 14257 docs/dev/debt/libkernel_sys.md
PR 14299 docs/dev/debt/libkernel_sys.md
PR 14304 docs/dev/debt/libkernel_sys.md
PR 14403 docs/dev/debt/libkernel_sys.md
PR 14548 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 14798 docs/dev/debt/libkernel_sys.md
PR 15000 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 15025 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 15035 docs/dev/debt/libkernel_sys.md
PR 15037 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md

@github-actions github-actions Bot added the fix error Closes an issue (Fixes #N) label Oct 31, 2026
@JJenkx

JJenkx commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Windows build and run, since the description notes Windows was not built.

Head e7f1dcec9c merged onto main 1bc97b9527. Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, full build with BUILD_TESTING=ON.

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

The changed branch decides "symbolic" from FILE_ATTRIBUTE_REPARSE_POINT. Two Windows facts bear on it:

  • A WOF-compressed regular file (compact /c /exe:xpress4k) does not report that attribute here (GetAttributes gives Archive, and fsutil reparsepoint query says it is not a reparse point). So the new throw does not reach compressed files.
  • A file symbolic link created by this unelevated account reports Archive, ReparsePoint, so it takes the new throw path.

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

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 1, 2026
@QW1CKS
QW1CKS force-pushed the fix/libkernel-fchmodat-symlink-throw branch from e7f1dce to 865b873 Compare November 2, 2026 20:37
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 2, 2026
@QW1CKS

QW1CKS commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Both Windows facts are the ones the branch depends on: a compressed file that does not report FILE_ATTRIBUTE_REPARSE_POINT stays on the normal chmod path, and Archive, ReparsePoint on an unelevated symlink is exactly the case that now throws. The branch was rebased onto 9090972b7e as 865b873c4b after your run; only docs/dev/debt/libkernel_sys.md conflicted, and Export.cpp is byte-identical, so your build still describes the code under review.

@QW1CKS

QW1CKS commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 9090972b7e as 865b873c4b to clear the conflict. Only docs/dev/debt/libkernel_sys.md conflicted: #10427 rewrote the pathconf entry, this branch rewrites fchmodat and lchmod, so main's pathconf line is kept and the other two are this branch's. Export.cpp merged cleanly and its patch is unchanged from f0cef5ef21. check_conventions.py --base upstream/main is clean and guest_kernel_sys passes. The rebase dropped the earlier approval, so this head needs another look.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@QW1CKS
QW1CKS force-pushed the fix/libkernel-fchmodat-symlink-throw branch from 865b873 to a1471ff Compare November 5, 2026 22:26
@QW1CKS

QW1CKS commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main bf80054e7c as a1471fffdb to clear a new conflict. Only docs/dev/debt/libkernel_sys.md conflicted again: this branch rewrites the fchmodat and lchmod entries, and main added _execve and _execvpe entries next to them, so the branch wording is kept and both new entries are kept. Export.cpp merged cleanly and both function bodies are byte-identical to 865b873c4b. check_conventions.py --base upstream/main is clean and guest_kernel_sys passes (Ubuntu 24.04, GCC 13.3, Release). The approval is at 865b873c4b, so this head needs another look.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 5, 2026
@oneandonlydean
oneandonlydean merged commit b6c74f1 into boykopovar:main Nov 5, 2026
2 checks passed
@QW1CKS
QW1CKS deleted the fix/libkernel-fchmodat-symlink-throw branch November 6, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs fix error Closes an issue (Fixes #N) prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel_sys: fchmodat silently succeeds on a symbolic link where lchmod throws

5 participants