fix(libkernel): read the APR resolver paths and write its outputs through guest copies #21585
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21585"
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 milescoviello on 2026-11-16T12:57:01Z.
What
The APR path resolvers touched most of their guest arguments in place:
sceKernelAprResolveFilepathsToIdshanded eachpaths[index]pointer straight toResolvePath, which reads the string in place, wroteids[index]through_resolve, and stored*error_indexdirectly....AndFileSizesforms and the four...ForEachforms readpaths[index]and builtstd::string(prefix) + paths[index]in place. TheForEachforms also wroteids,sizesandresultsdirectly.So an unreadable
pathstable, path or prefix, or an unwritable output array, crashed the host. Three forms already copied their outputs out (AndFileSizes,WithPrefixToIdsAndFileSizes,WithPrefixToIds); their inputs did not.Now all eight forms go through two helpers,
_resolveAll(stop at the first miss,error_index) and_resolveForEach(resolve every path,results):CopyGuestPath_nid_no_patch.GuestCopyIn_nid_no_patchas the loop reaches it, and each path is copied withCopyGuestPath_nid_no_patch.ids,sizes,resultsanderror_indexare written withGuestCopyOut_nid_no_patch.EFAULTat that index; the indices before it were already written, as before. A path or prefix past the 1024-byte path limit resolves to nothing, like a missing file.What stays the same: the
EINVALchecks for nullprefix,paths,idsandsizes, a null element counting as a missing file at its own index, the invalid id and size 0 in a failing slot,error_indexleft untouched on success, the stop at the first miss, theForEachreturn count, and the plain prefix concatenation. These are what the "APR resolve argument checks and prefix join" debt entry describes. A new debt entry records theEFAULTfallback.What changes besides the checked copies: a path or prefix longer than 1024 bytes (the guest
PATH_MAX, fromCopyGuestPath_nid_no_patch) now resolves to nothing, as a missing file does, where before it was passed through in full. The debt entry records this.Tested
Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON:guest_ampr_markers(theguest_ampr_testsbinary) gains nine cases inTestResolveFailures. Each returns -1 with the guesterrnoatEFAULT(14):0x10)pathstable;ForEachandAndFileSizesforms;WithPrefixToIdsandWithPrefixToIdsForEach;ids,sizesorresultsarray;error_index, where the missing second path still gets the invalid id before the fault.guest_ampr_markerspasses, 3 runs of 3.main'sApr.cppand the new cases,guest_ampr_markersends infatal SIGSEGV (code 1) at address 0x0000000000000010.tools/check_conventions.pypasses on the branch and this body. The fragment folds;tools/debt_fold.py --checkfails only onmain's owndocs-nkwebkit-drop-readded-count-lines.md, which #21458, #21512 and #21531 fix.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 PrivacyOnion on 2026-11-16T13:01:04Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
3299b61e76:tools/check_conventions.pypassed;git diff --checkclean.guest_ampr_testsbuilt cleanly.guest_ampr_markers):core/libs/prx/libkernel/Apr/src/Apr.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T13:21:46Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and added fault cases support merging.
What I ran
Reviewed head
3299b61e768816cb074958430c19b2952fda6cad. I read the prepared diff and all three changed files, then checked the affected APR wrappers and guest string-copy helper at the pinned head. I did not run commands or tests.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No checks were run. Test and negative-control results in the description are author-reported.
files.jsonwas unavailable; the manifest and review-folder listing show three changed files, all included and read. No other changed files were excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T13:25:09Z.
Review: APPROVED
Reviewed — looks good
The eight
sceKernelAprResolveFilepaths*forms now read and write guest memory through checked copies, and the code I read is sound. Nothing blocks this; the points below are optional.Head reviewed:
421155f04d47a4927523d801c55ee2fcd198fa4b.What I ran
No build and no test binary in this review. I read the changed code at the head and the callers it touches, using
repo_read.py:Files read:
core/libs/prx/libkernel/Apr/src/Apr.cpp(changed hunks, the fourForEachcallers at lines 1055–1070),core/libs/tests/GuestAmpr.cpp(changed hunk and the setup it relies on, lines 776–826), anddocs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md. Files excluded by rule: none. Files reviewed: 3 of 3 read.Results
guest_ampr_markersmainFindings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/Apr/src/Apr.cpp:171and:179: a path or prefix over 1024 bytes now resolves to nothing, like a missing file. Before this change it was passed through in full. The debt entry records this, but the description's "What stays the same" list does not. Worth one line in the PR body so the behaviour change is visible.core/libs/tests/GuestAmpr.cpp:809:auto** const unreadableTablededucesconst char**correctly, butconst char** const unreadableTablesays the same thing more plainly.core/libs/tests/GuestAmpr.cpp:809–826: no new case covers the over-long path or prefix that the debt entry describes. A test with a 1025-byte path would pin that behaviour.Not verified
guest_ampr_markerscases, were not run here. The 3-of-3 passes and themainnegative control (SIGSEGV at0x10) are the author's reports.CopyGuestString_nid_no_patchwas not read. The 1024 limit and the return codes (0,Fault,63for unterminated) are taken fromCopyGuestPath_nid_no_patchand its test inGuestKernelSys.cpp.tools/check_conventions.pyandtools/debt_fold.py --checkwere not run.ForEachforms were checked only through their callers atApr.cpp:1055–1070; their argument checks were not re-read beyond those lines.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T15:32:54Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Head
436d2fe349bc099a7fb486ab3884538f04e2e2ff, basemain. Static review only: I readdiff.patchin full, then the head code around the changed helpers and their callers throughrepo_read.py. I did not build or run any test.Results
guest_ampr_markerscheck_conventions.py,debt_fold.pyFindings
Blocking
None.
Non-blocking
Apr.cpp:195andApr.cpp:221: both helpers copy the prefix before the loop, so withcount0 an unreadable prefix now returnsEFAULT. The old code returned 0 without reading it. This is not in the list of changes in the description. The smallest fix is to copy the prefix only whencountis greater than 0, or to list the case in the debt entry.Apr.cpp:161:PathPrefix::presentis set atApr.cpp:167and never read._entryPathuses onlyfitsandtext. Remove the field and its assignment.Sources
github.com/boykopovar/AnyPS5@436d2fe349/core/libs/prx/libkernel/Apr/src/Apr.cpp (L157-L229)github.com/boykopovar/AnyPS5@436d2fe349/core/libs/tests/GuestAmpr.cpp (L809-L838)github.com/boykopovar/AnyPS5@436d2fe349/core/libs/prx/libc/src/General.cpp (L588-L590)Not verified
guest_ampr_markersrun, the negative control, andcheck_conventions.pyanddebt_fold.pyare author-reported. I did not run them.EFAULTfallback. The debt entry says it is not measured, and I did not check it.std::string, and a separate copy-out per output. Startup resolves thousands of paths (comment atApr.cpp:60). Not measured.CopyGuestString_nid_no_patchreturning a non-zero code for an over-long string. I read only the call inGeneral.cpp:588-590, not its body. The existingGuestKernelSystest expects 63 for an unterminated string, which fits a non-zero code.docs/dev/debt/changes/and the "APR resolve argument checks and prefix join" entry were not checked against the repository's convention or existing debt files.validate_review_body.pywas not checked, so it was not run.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T16:32:36Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
6665f8219e65a0dd9760235733013e78cedbd9b0, basemain.Results
Author-reported results (not reproduced here)
guest_ampr_markers, 3 runs of 3, passed.main'sApr.cpp:fatal SIGSEGV at address 0x10.tools/check_conventions.pypassed;tools/debt_fold.py --checkfails only on amainfragment.Findings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/Apr/src/Apr.cpp:169:_copyPrefixsetsfits = error == 0, so every non-EFAULT error means "does not fit".CopyGuestString_nid_no_patchalso returns 12 when its buffer allocation fails (core/libs/prx/libc/src/General.cpp:565-567). A failed allocation would then resolve to nothing, like a missing file, instead of returning ENOMEM._entryPathhas the same pattern atApr.cpp:180. Smallest fix: return ENOMEM when the error is 12.core/libs/tests/GuestAmpr.cpp:831: the new "too long" cases coverWithPrefixToIdsandToIdsonly. TheForEachandAndFileSizesforms share_resolveForEachand_resolveAll, which now resolve an over-long path to nothing, and no test checks that.Not verified
6665f8219e65: status unknown to me. Formal approval waits for them to pass.tools/check_conventions.pyandtools/debt_fold.pywere not run. The debt fragment's heading was not compared with other fragments.Apr.cpp(the diff hunks, the head helpers, theForEachwrappers and search hits for the other forms) andGuestAmpr.cpp(the diff and lines 776-812). The rest of each file was not read.General.cpp:564). The cost is not measured.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T16:49:18Z.
Review: COMMENTED
fix(libkernel): read the APR resolver paths and write its outputs through guest copies — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
97c8dd2f5adacf4deda6100ae93cf684a22ac1c4, basemain.Results
guest_ampr_markerstestsCopyGuestPath_nid_no_patch,GuestCopyIn_nid_no_patch,GuestCopyOut_nid_no_patchmatch their call sitessceKernelAprResolveFilepaths*forms go through_resolveAllor_resolveForEachFindings
Blocking
None.
Non-blocking
None in the code I read.
Not verified
GuestAmpr.cpptest run. The 3-of-3 pass and the SIGSEGV negative control are the author's report, not my run.CopyGuestPath_nid_no_patch(core/libs/prx/libc/src/General.cpp, line 588) was not read. The new tests and the debt entry assume it.## add Unknown function info) against the debt conventions indocs/dev/CONVENTIONS.md.Files read:
core/libs/prx/libkernel/Apr/src/Apr.cpp,core/libs/tests/GuestAmpr.cpp,docs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md. Files excluded: none.To get this to a good state
Nothing is required.