fix(libc): pass long host paths relative to the root so macOS accepts guest paths up to PATH_MAX #22932
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22932"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Romannachwievor on 2026-11-18T13:51:34Z.
What
On macOS, a guest path close to the 1024-byte guest limit failed with
ENAMETOOLONG. Its host form is the emulator root followed by the guest path, and macOS rejects host paths of 1024 bytes or more (#22270).The host working directory is the emulator root for the life of the process: guest
chdironly changesWorkingDirectory::current, and the only host change is inLoadExec, just before the process is replaced. So a path whose absolute host form would reachPATH_MAXis now passed to the host relative to the root. A guest path of at most 1023 bytes always fits that way. Shorter paths take the old route, and Windows is unchanged.In
core/libs/prx/libc/src/General.cpp:HostPathresolves such a path against an empty root.MatchNameslists.for an empty directory, so case-insensitive matching still applies on that route.SetWorkingDirectoryno longer callscanonical, whoserealpathresult must fit inPATH_MAX, on such a path. It canonicalizes the longest prefix that fits, then appends the remaining components after checking withsymlink_statusthat each exists and is not a symbolic link. A symbolic link past the host limit fails withENAMETOOLONG, as before. The..check against the root is unchanged.SetWorkingDirectoryandgetcwdrun theiris_directorycheck on the relative form.The debt entry for #22270 now lists the remaining limits: relative names used from a deep working directory, paths under an alias, descriptor-based
*atcalls, andfchdiron a long path. A separate M1 probe showedfchdirreturningENOTDIRfor a valid directory at the 1023-byte guest limit; recovering that descriptor path needs work outside this PR.Tested
-DCMAKE_OSX_ARCHITECTURES=x86_64, test targets and their libraries only:guest_kernel_sysandguest_kernel_sys_execve: fail onmain(Kernel sys check failed at line 1325 (guest errno 63),execve with a 1023 byte pathname did not reach the lookup), pass with this change.mainand with this change: the only difference isguest_kernel_sys.file_streams,guest_sce_net,guest_pollandguest_kernel_app_archive_mmapfail on both (#21720, #22443, #20161, #21538).dc77871833onmain7281ddca51plus #17425 and #11049 for the macOS build: Apple M1, macOS 26.5, x86_64 Release.libc,guest_kernel_sys_testsandguest_kernel_sys_execve_testsbuilt.guest_kernel_sys_execvepassed 3/3. With onlyCheckRawGetcwdPathLimitrun from the test binary, this change passed 3/3 andmainfailed 1/1 at line 1456 with guest errno 63. Temporary test edits were removed and the targets rebuilt.guest_kernel_sysnow stops at line 1190 with guest errno 13 in a directory rename permission check. With the new long-path check temporarily skipped, bothmainand this change stop at that same line. The test therefore cannot give a full-suite result on currentmain.fchdirprobe on a valid 1023-byte guest directory returnedENOTDIR(20). The probe was removed; the limit is recorded in the debt fragment.MatchNamesbuilds the same path as before (directory / entry->path().filename()equalsentry->path()).python3 tools/check_conventions.py --base origin/mainandgit diff --check origin/main...HEADpass on the rebased branch.python3 tools/debt_fold.py --checkfails on two untouched fragments in currentmain:docs-libkernel-pro-measured-1360.mdandfix-kernel-sys-title-workaround-bit-limit.md.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-18T14:05:27Z.
Review: COMMENTED
Tested head
b8276aee13on the M4 with a full build: macOS 27.0.1, Apple clang 21.0.0, x86_64 Release under Rosetta. I merged it into my macOS base (main57f7016922with #17425 and #11049), which brings inmainup to3055e5830c.guest_kernel_sysandguest_kernel_sys_execve: pass 3/3.ctest -j6 -E '^agc_', 4011 tests): 12 failures. Eleven of them are the ones in my run ofe7de7040e0on the issue (nkwebkit_affinetransformguestpointersnow passes, since #22859 is inmain). The new one,guest_refused_connect, also fails with this commit reverted on the same tree, so it comes frommain, not from this change.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T15:51:19Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: preserve guest-root containment when resolving paths whose host form exceeds
PATH_MAX.What I ran
Reviewed head
b8276aee1364d46ad2ba0db3e04bdf3e845934d8using the prepared review bundle and the pinned repository reader. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libc/src/General.cpp:379: For long paths,HostPathcallsResolveHostPath({}, names, module)with an empty root.ResolveHostPathhandles..components by appending them to that root, so a guest path such as/../outsidecan resolve to a host path outside the emulator root. The short-path route retains the root and the laterSetWorkingDirectorycontainment check, but this branch can pass the escaped path to filesystem operations without that check. Keep resolution anchored to the emulator root while avoiding an overlong absolute syscall path, and ensure..cannot escape the guest root.Non-blocking
None.
Not verified
core/libs/prx/libc/src/General.cppanddocs/dev/debt/changes/fix-libc-macos-long-host-paths.md.files.jsonwas unavailable through the reader, so excluded files and the complete reviewed-file manifest were not independently confirmed.To get this to a good state
Keep long-path resolution within the guest root, including paths containing
.., then rerun the path tests that cover long paths and traversal.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T20:06:22Z.
Review: COMMENTED
Reviewed — comments
The changed path handling has a potentially incorrect canonicalization edge case, and the reported tests were not run during this review.
What I ran
Reviewed head
1933d3d41da6ce2beaa8509cfe782ed3316b4819using the prepareddiff.patchand the pinned readerrepo_read.py. No commands or tests were run.Results
Findings
Blocking
None verified.
Non-blocking
core/libs/prx/libc/src/General.cpp:545— absolute resolved paths bypass the long-path handling.CanonicalHostPathimmediately callscanonical(resolved)whenresolvedis absolute. If an alias or provided path resolves to an absolute host path at or beyond the host path limit,chdirstill fails during canonicalization. The description explicitly leaves alias paths as open debt; consider documenting this limitation alongside the helper or adding a test to ensure this route remains intentionally unsupported.Not verified
description.mdare author-reported.core/libs/prx/libc/src/General.cpp,core/libs/tests/GuestKernelSys.cpp, anddocs/dev/debt/changes/fix-libc-macos-long-host-paths.md(all changed files listed inmanifest.json). The prepared artifacts read weredescription.md,commits.md,manifest.json, anddiff.patch. No changed files were excluded.To get this to a good state
Nothing is required. The alias path limitation is optional feedback.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T10:57:00Z.
Review: COMMENTED
Reviewed — comments
The review covers the changed implementation, test, and debt note at head
dc77871833c7ee122a53baaf4f2b4eb6fd6b9560; a potential edge case in root-relativechdirhandling merits clarification before a formal decision.What I ran
Results
Findings
Blocking
None.
Non-blocking
../components to climb past the emulator root, then expectsmkdiratto createinsidewithin that root. The relevant changed test lines arecore/libs/tests/GuestKernelSys.cpp:1453-1457. Please clarify how this exercises the stated root containment behavior, since itsclimb + insidepath appears to leave the root before resolvinginside.Not verified
files.jsonwas not available through the review-folder reader; the manifest shows all three changed files included and no excluded files.To get this to a good state
Nothing is required. The optional test-path clarification above is the only comment.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T00:30:56Z.
Review: COMMENTED
Reviewed — comments
The change addresses absolute guest paths whose host form exceeds
PATH_MAX; review is incomplete because one changed source file’s added lines were not all read, and no checks were run.What I ran
Inspected prepared diff and source at head
d6cde1fdd63b2f2b6e69190fb05b9238eed2883eusingrepo_read.pyreview-folder and source-reading tools. No build or tests were run.Results
Findings
Blocking
None verified.
Non-blocking
mkdiratandunlinkatwith a path containing leading..components, but the debt entry states descriptor-based*atcalls remain limited for long host paths. Consider adding a focused test or clarifying which*atcase this regression test covers. The test additions are atcore/libs/tests/GuestKernelSys.cpp:1453-1463.Not verified
core/libs/prx/libc/src/General.cpp,core/libs/tests/GuestKernelSys.cpp, anddocs/dev/debt/changes/fix-libc-macos-long-host-paths.md, but did not read every added line listed in the manifest. In particular, changed lines inGeneral.cppoutside the inspected ranges were not all reviewed.files.jsonwas not available as a review-folder document; the manifest lists all three changed files as included.To get this to a good state
Nothing is required. Optional: clarify the
*attest coverage noted above.Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-25T00:57:16Z.
Review: APPROVED
Reviewed exact head
d6cde1fdd63b2f2b6e69190fb05b9238eed2883e, including the earlier guest-root containment concern.The long-host-path route no longer creates a guest escape.
Resolve()normalizes path components beforeHostPath: a..only pops when the normalized component stack is non-empty, so leading/excess..stop at the guest root and never reachResolveHostPath({}, names, ...). For a path whose root-prefixed host spelling reachesPATH_MAX, the resulting normalized component vector is resolved relative to the process CWD, which is the emulator root for normal execution; the invariant is unchanged untilLoadExecreplaces the process.CanonicalHostPathlikewise canonicalizes the longest root-prefixed prefix that fits, then appends only existing non-symlink components, preserving the documentedENAMETOOLONGfallback for a symlink beyond the host limit.The current regression covers excess
..through the changed plain-path/AT_FDCWD route, while the real-directory-descriptor*atlimitation remains explicitly listed as debt. macOS M1/M4 evidence exercises the actual long-path route, Windows evidence verifies unchanged behavior and the traversal regression, and every exact-head hosted check is terminal/successful (with the unrelated Linux/pipe-write jobs intentionally skipped).I found no remaining blocker on this exact head.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T15:03:18Z.
Review: COMMENTED
Built and ran
guest_kernel_syson Linux with this head integrated. It passed. I traced the macOS path conversion to the root-relative operation used for long guest paths. The actual macOSPATH_MAXbehavior remains unverified here.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.