symlink accepts a target of 1024 bytes or more instead of failing with ENAMETOOLONG #8722

Closed
opened 2026-10-20 22:24:42 +00:00 by xXPBSXx · 1 comment
xXPBSXx commented 2026-10-20 22:24:42 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T22:24:42Z.


symlink_nid_postfix (core/libs/prx/libkernel_sys/Export.cpp) has no length check on the target. FreeBSD 11.4 kern_symlinkat copies the target with copyinstr(path1, syspath, MAXPATHLEN, NULL) (sys/kern/vfs_syscalls.c:1490) before it looks up the link name; MAXPATHLEN is PATH_MAX = 1024 (sys/sys/param.h:280, sys/sys/syslimits.h:63). A target of 1024 bytes or more therefore fails with ENAMETOOLONG (63). Probe: symlink_nid_postfix(std::string(1100,'a').c_str(), "<root>/link") returned -1 with errno 1 on Windows without symlink privilege (and would try to create the link with it); expected -1 / 63.

AI-assisted (Claude Code).

Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/symlink-target-too-long

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5950646454 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8722). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T22:24:42Z. --- `symlink_nid_postfix` (core/libs/prx/libkernel_sys/Export.cpp) has no length check on the target. FreeBSD 11.4 `kern_symlinkat` copies the target with `copyinstr(path1, syspath, MAXPATHLEN, NULL)` (sys/kern/vfs_syscalls.c:1490) before it looks up the link name; `MAXPATHLEN` is `PATH_MAX` = 1024 (sys/sys/param.h:280, sys/sys/syslimits.h:63). A target of 1024 bytes or more therefore fails with ENAMETOOLONG (63). Probe: `symlink_nid_postfix(std::string(1100,'a').c_str(), "<root>/link")` returned -1 with errno 1 on Windows without symlink privilege (and would try to create the link with it); expected -1 / 63. AI-assisted (Claude Code). Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/symlink-target-too-long
Filip722 commented 2026-10-21 09:45:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-21T09:45:58Z.


Confirmed on Linux: main successfully creates links with 1024- and 1100-byte targets. This is more than an error-mapping difference caused by Windows symlink privilege.

Tested unchanged upstream main b5d763770a8e932b35db9bea1c415e7e0ac50a22 in a separate validation checkout. Environment: Debian GNU/Linux 13.7 (trixie), x86-64, kernel 7.2.9-x64v3-xanmod1, AMD Ryzen 5 7640HS, GCC/G++ 15.2.0, CMake 3.31.6/Ninja. Full project configuration: Release, BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, ANYPS5_USE_SYSTEM_DEPS=OFF; rebuilt libc, libkernel and libkernel_sys. Temporary probes linked directly to these freshly built, unpatched runtime libraries, as the repository runtime tests do. No production source changes.

Reproduction: from a scratch directory on Linux tmpfs, created a relative guest directory symlink-fixtures-guest-readlink and, for each length below, called:

std::string target(length, 'a');
symlink_nid_postfix(target.c_str(), relativeLinkPath.c_str());
readlink_nid_postfix(relativeLinkPath.c_str(), buffer, sizeof(buffer));

Each link had a distinct name. The target need not exist; the check concerns storing its bytes, not resolving it. Relative link paths ensure this exercises the guest sandbox resolver correctly.

Target bytes symlink_nid_postfix result Guest readlink result Target bytes identical?
1023 0 (created) 1023 yes
1024 0 (created) 1024 yes
1100 0 (created) 1100 yes

Host std::filesystem::read_symlink independently returned the same full bytes. Native Linux symlink controls also accepted all three lengths. The reported FreeBSD-style 1024-byte guest bound therefore needs enforcement in the guest adapter; this host filesystem does not impose that boundary. Main's symlink_nid_postfix currently checks neither the target length nor that bound before creating the link. Errno after successful calls is intentionally not interpreted.

Existing guest_kernel_sys passes on this build, but does not test these target lengths on main.

Scope: reproduces the missing bound on unchanged main and confirms 1023-byte creation is available here. I did not apply/test #8723. Only relative all-ASCII targets and a tmpfs scratch directory; no console, Windows, GPU or title execution tested.

AI-assisted: yes (Codex); I am responsible for the reported investigation and results.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312974125 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8722#issuecomment-6312974125). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-21T09:45:58Z. --- Confirmed on Linux: main successfully creates links with 1024- and 1100-byte targets. This is more than an error-mapping difference caused by Windows symlink privilege. Tested unchanged upstream `main` **`b5d763770a8e932b35db9bea1c415e7e0ac50a22`** in a separate validation checkout. Environment: Debian GNU/Linux 13.7 (trixie), x86-64, kernel `7.2.9-x64v3-xanmod1`, AMD Ryzen 5 7640HS, GCC/G++ 15.2.0, CMake 3.31.6/Ninja. Full project configuration: `Release`, `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`, `ANYPS5_USE_SYSTEM_DEPS=OFF`; rebuilt `libc`, `libkernel` and `libkernel_sys`. Temporary probes linked directly to these freshly built, unpatched runtime libraries, as the repository runtime tests do. No production source changes. Reproduction: from a scratch directory on Linux `tmpfs`, created a relative guest directory `symlink-fixtures-guest-readlink` and, for each length below, called: ```cpp std::string target(length, 'a'); symlink_nid_postfix(target.c_str(), relativeLinkPath.c_str()); readlink_nid_postfix(relativeLinkPath.c_str(), buffer, sizeof(buffer)); ``` Each link had a distinct name. The target need not exist; the check concerns storing its bytes, not resolving it. Relative link paths ensure this exercises the guest sandbox resolver correctly. | Target bytes | `symlink_nid_postfix` result | Guest `readlink` result | Target bytes identical? | |---|---|---|---| | 1023 | 0 (created) | 1023 | yes | | 1024 | 0 (created) | 1024 | yes | | 1100 | 0 (created) | 1100 | yes | Host `std::filesystem::read_symlink` independently returned the same full bytes. Native Linux `symlink` controls also accepted all three lengths. The reported FreeBSD-style 1024-byte guest bound therefore needs enforcement in the guest adapter; this host filesystem does not impose that boundary. Main's `symlink_nid_postfix` currently checks neither the target length nor that bound before creating the link. Errno after successful calls is intentionally not interpreted. Existing `guest_kernel_sys` passes on this build, but does not test these target lengths on main. Scope: reproduces the missing bound on unchanged main and confirms 1023-byte creation is available here. I did not apply/test #8723. Only relative all-ASCII targets and a tmpfs scratch directory; no console, Windows, GPU or title execution tested. AI-assisted: yes (Codex); I am responsible for the reported investigation and results.
Sign in to join this conversation.
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#8722
No description provided.