fix(libkernel_sys): check the readlink size before the path #8603

Merged
xXPBSXx merged 1 commit from upstream-pr/8603 into main 2026-10-20 21:50:50 +00:00
xXPBSXx commented 2026-10-20 18:05:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T18:05:20Z.


What

readlink and readlinkat returned EFAULT for a NULL path and ENOENT for an empty one before they looked at the buffer size. FreeBSD 11.4 kern_readlinkat (vfs_syscalls.c:2232) returns EINVAL for a size above IOSIZE_MAX before it looks the path up. The size is now checked first in both functions; a NULL or empty path with a valid size behaves as before. Overlap: #5528 (readlink path length, open) conflicts in Export.cpp (git merge-tree: one conflict), #8312 and #8522 are clean; whichever lands second rebases. pr_overlap was not run.
Fixes #8602

Tested

Windows 10 (19045), WinLibs GCC 15.2.0 r7, Release, with this commit (994fb42929) on main 892a4f1328; the run without the change was made on the same base:

  • guest_kernel_sys: aborts with exit code 0xc0000409 ("Kernel sys check failed at line 304", guest errno 14) without the change to Export.cpp, passes with it, 3 of 3 runs.
  • python tools/check_conventions.py --base upstream/main and git diff --check pass.
  • Not tested: Linux; GuestNamedShmIoDescriptorReuse.cpp (it mentions readlink, is Linux-only and does not link libkernel_sys); a console; a title run.

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; 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
  • Unblocks: none
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4940181014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8603). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T18:05:20Z. --- ### What `readlink` and `readlinkat` returned `EFAULT` for a NULL path and `ENOENT` for an empty one before they looked at the buffer size. FreeBSD 11.4 `kern_readlinkat` (vfs_syscalls.c:2232) returns `EINVAL` for a size above `IOSIZE_MAX` before it looks the path up. The size is now checked first in both functions; a NULL or empty path with a valid size behaves as before. Overlap: #5528 (readlink path length, open) conflicts in `Export.cpp` (`git merge-tree`: one conflict), #8312 and #8522 are clean; whichever lands second rebases. `pr_overlap` was not run. Fixes #8602 ### Tested Windows 10 (19045), WinLibs GCC 15.2.0 r7, Release, with this commit (994fb42929) on `main` 892a4f1328; the run without the change was made on the same base: - `guest_kernel_sys`: aborts with exit code 0xc0000409 ("Kernel sys check failed at line 304", guest errno 14) without the change to `Export.cpp`, passes with it, 3 of 3 runs. - `python tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - Not tested: Linux; `GuestNamedShmIoDescriptorReuse.cpp` (it mentions `readlink`, is Linux-only and does not link `libkernel_sys`); a console; a title run. ### 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 - [x] Unimplemented paths throw; 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] Unblocks: none - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 18:27:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T18:27:36Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 5528 core/libs/prx/libkernel_sys/Export.cpp L278, L287

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 6044 core/libs/tests/GuestKernelSys.cpp
PR 7201 core/libs/prx/libkernel_sys/Export.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298143525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8603#issuecomment-6298143525). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T18:27:36Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 5528](https://www.github.com/boykopovar/AnyPS5/pull/5528) | `core/libs/prx/libkernel_sys/Export.cpp` [L278](https://github.com/boykopovar/AnyPS5/blob/352dbe751a732c7f79c1d23e2b544e0abc9cc954/core/libs/prx/libkernel_sys/Export.cpp#L278), [L287](https://github.com/boykopovar/AnyPS5/blob/352dbe751a732c7f79c1d23e2b544e0abc9cc954/core/libs/prx/libkernel_sys/Export.cpp#L287) | | | 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](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestKernelSys.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel_sys/Export.cpp` |
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!8603
No description provided.