fix(libkernel): return EFAULT from AIO poll, cancel and delete for invalid memory #14417
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14417"
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 roboterspinne on 2026-11-01T11:52:56Z.
What
On
26fa1212b8(line numbers below refer to it)sceKernelAioPollRequest,sceKernelAioPollRequests,sceKernelAioCancelRequest,sceKernelAioCancelRequests,sceKernelAioDeleteRequestandsceKernelAioDeleteRequestscrash the host when a guest passes a non-null id array or output that is not mapped or not writable. Each checks its pointers only for null (the single forms inline, the batch forms throughValidateIds,core/libs/prx/libkernel/Aio/src/Aio.cpp:249-253) and then writes*ret,*state,ret[i]andstate[i]and readsid[i]with plain host accesses (Aio.cpp:276,284-285,293,301-302,353,429), so a state pointer of0x10or a read-only page takes an access violation inlibkernel.prxinstead of returning an error. The repository's rule for guest pointers in these libraries is the checked copy:GuestCopyOut_nid_no_patch(core/libs/prx/libc/src/General.cpp:823-854) checks the destination withVirtualQueryon Windows,process_vm_writevon Linux andmach_vm_writeon macOS, andGuestCopyIn_nid_no_patch(General.cpp:856-861) reads throughCopyGuestBytes(General.cpp:86); a failed copy returnsSCE_KERNEL_ERROR_EFAULT, assceKernelQueryMemoryProtectionandsceKernelIsStackdo (#13904,docs/dev/debt/libkernel.md:76). The nullEFAULTchecks these six exports already have are that rule for a null pointer only.GuestCopyIn; the single and batch forms run the existingReportLocked,CancelLockedorDeleteLockedcalls in the same order under the registry lock, into local states, and copy the states out with oneGuestCopyOut. A failed copy returnsSCE_KERNEL_ERROR_EFAULT. Everything else is unchanged:ValidateIdsstays as it is, because the waits share it, so a null pointer still returnsEFAULTand a count outside 1 to 128 still returnsEINVALbefore anything is read or written; a pending id still throws before anything is written; unknown ids still getESRCH. Because the operations still run one id after the other, duplicate ids keep their results:{x, x}gives{3, 0x10003}for an unreported finished request insceKernelAioPollRequestsand{0, ESRCH}insceKernelAioDeleteRequests. The states are copied out after the registry changed, so when the copy faults a poll has already marked the request reported and a delete has already removed it (a cancel changes nothing), as #13904 leaves earlier outputs written; the new debt entry says so and that console fault behaviour is unmeasured.sceKernelAioWaitRequest(s)(changed by open #13224) and the submit calls are left for a follow-up and named in the entry.guest_aiogains checks next to the existing null checks: an id array at0x10returnsEFAULTfrom the three batch forms and leaves the states untouched (a count of 0 still returnsEINVALfirst); with a state or ret pointer of0x10and with a read-only page (VirtualAllocwithPAGE_READONLYon Windows,mmapwithPROT_READelsewhere, so the protection check runs and not only the unmapped one) every one of the six exports returnsEFAULTand the page stays 0; afterwards a request whose poll faulted polls0x10003and one whose delete faulted deletes withESRCH, which pins the order above, and one whose cancel faulted polls 3; and the duplicate-id results of the batch forms.guest_aio_registry_testsneeds one test-only change: its host-read hookHoldAioSource(core/libs/tests/GuestAioRegistry.cpp:164-170, installed at 183) parks every caller of the guest-arena host-read hook until the main thread releases it, andGuestCopyIngoes through that hook (General.cpp:86-87). With this change the main thread's ownsceKernelAioCancelRequestsandsceKernelAioDeleteRequestschecks (lines 200-206) read their ids through it and wait on the gate they are meant to observe, soguest_aio_processingandguest_aio_processing-rollbackabort after 5 s at line 168. The hook now holds only the read of the submitter's source byte (g_aioGateSource, set to its address before the hook is installed), which is the transfer the test parks; the test checks the same things as before.pr_overlap.py --branchfinds no shared lines with the open pull requests it can compare, including #13224, and cannot compare 46 open pull requests that do not merge withmain: #7121, which also changesAio.cppanddocs/dev/debt/libkernel.md, and 45 that change onlydocs/dev/debt/libkernel.mdof this PR's files. Checked by hand: a trial merge of this branch with each of the 46 conflicts in exactly the files thatmainwith it already conflicts in, soAio.cppanddocs/dev/debt/libkernel.mdadd no conflict.Tested
Windows 11, WinLibs GCC 15.2.0, Ninja Release build (
BUILD_TESTING=ON) of the targetsguest_aio_testsandguest_aio_registry_testsonc2bd5e5a1f(based on26fa1212b8):cmake --build build --parallel 6 --target guest_aio_tests guest_aio_registry_tests, thenctest --test-dir build -R '^guest_aio' --output-on-failure(8 tests:guest_aio,guest_aio_bad_descriptorsand the sixguest_aio_registry_testsmodesidentity,admission,rollback,identity-exhaustion,processingandprocessing-rollback).Aio.cppof26fa1212b8:guest_aiofails withException: SegFault,FATAL: unhandled exception 0xc0000005,rip ... libkernel.prx+0xb3cf0,read of 0x0000000000000010(the first check with a count of 2 and the id array at0x10); the other 7 pass, so the hook change keeps the registry tests green onmain.Aio.cppchange and the registry test of26fa1212b8:guest_aio_processingandguest_aio_processing-rollbackfail withExit code 0xc0000409after about 5.2 s, which is the timeout of the hook'swait_for(line 168 on26fa1212b8); the other 6 pass.c2bd5e5a1fonly in one sentence ofdocs/dev/debt/libkernel.md:77, so the code and the tests are identical.c2bd5e5a1f: 8 of 8 pass (guest_aio0.28 s, the other seven 0.02 to 0.12 s), includingguest_aio_bad_descriptors.c2bd5e5a1fmerged intomain(run 41303851668, job 124842517716): it builtguest_aio_testsandguest_aio_registry_testsand ranguest_aioand the six registry modes, all passed;guest_aio_bad_descriptorswas not among the tests it selected.linuxjob runs only onpushor on aworkflow_dispatchwithlinuxenabled, so themmap/PROT_READbranch of the test and theprocess_vm_writev/mach_vm_writepaths ofGuestCopyOutare untested.python tools/check_conventions.py --base 26fa1212b8with this title and description passed.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 MarcZX10 on 2026-11-01T12:17:16Z.
Review: COMMENTED
Reviewed — no blocking findings, two evidence gaps
The change routes the six AIO poll, cancel and delete exports through checked guest copies and keeps the existing registry order, but the Tested section reports runs on an earlier head (2198bfcd71), and the POSIX branch of the new test has not been run.
What I ran
c2bd5e5a1f14847c88fe7425e57152a6668b062d(one commit on26fa1212b8). Base for the mergeability check:ba627802e2210187d417deb64c8f2fed8e33011f(currentmain). No merged-preview build was run.python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14417from/marc/AnyPS5(no build). Diff check, conventions and PR template, and the live stack check passed. The ABI and test-quality steps failed only becausetools/pr_abi_audit.pyandtools/pr_test_quality.pyare not in the head tree./marc/AnyPS5:python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base ba627802e2210187d417deb64c8f2fed8e33011f --head c2bd5e5a1f14847c88fe7425e57152a6668b062d --json(status passed, 15 symbols, 0 findings; lexical only).python3 tools/pr_test_quality.py --root <export of c2bd5e5a1f> --json core/libs/tests/GuestAio.cpp core/libs/tests/GuestAioRegistry.cpp. Twopossible-unregistered-cpp-testfindings, both false positives: the tests are registered incore/libs/prx/libkernel/CMakeLists.txtthrough${LIBS_INCLUDE_DIR}/tests/....c2bd5e5a1fonly:Aio.cpp,General.cpp(GuestCopyOut/GuestCopyIn),GuestAio.cpp,GuestAioRegistry.cpp,build.yml.Results
The
linuxjob inbuild.ymlruns only onpushor a manual dispatch, so it does not run for this pull request.ABI audit (by hand) — raw output
Findings
Blocking
None.
Non-blocking
The Tested section is tied to a head that is no longer the PR head. It reports the
guest_aioandguest_aio_registry_testsruns on2198bfcd71and saysc2bd5e5a1fonly rewords the debt entry.2198bfcd71is not reachable from this PR, which has one commit,c2bd5e5a1f, so that statement cannot be checked here. Please either rerun the two targets onc2bd5e5a1fand restate the results against that SHA, or give the exact diff from2198bfcd71that the body relies on.The POSIX branch of the new test has not been run.
GuestAio.cppadds<sys/mman.h>and a read-only anonymous page throughmmapandmunmap(PROT_READ) for the fault cases. The fault results on Linux and macOS depend onprocess_vm_writevandmach_vm_writeinGuestCopyOut. The Tested section reports Windows only, and the hosted Linux job does not run on pull requests. Please runguest_aioon Linux or macOS and report the result againstc2bd5e5a1f, or name the run that covers it.Sources
Permalinks at
c2bd5e5a1f14847c88fe7425e57152a6668b062d:ApplyToIds: the ids are copied in withGuestCopyIn, the registry operations run under the lock, and the states are copied out after it:github.com/boykopovar/AnyPS5@c2bd5e5a1f/core/libs/prx/libkernel/Aio/src/Aio.cpp (L259-L275)CancelLockeddoes not write the registry, which is why a faulting cancel changes nothing:github.com/boykopovar/AnyPS5@c2bd5e5a1f/core/libs/prx/libkernel/Aio/src/Aio.cpp (L142-L146)GuestCopyOuton Windows rejects read-only pages, and on Linux and macOS it usesprocess_vm_writevandmach_vm_write:github.com/boykopovar/AnyPS5@c2bd5e5a1f/core/libs/prx/libc/src/General.cpp (L823-L854)linuxjob condition (pushorworkflow_dispatchonly):github.com/boykopovar/AnyPS5@c2bd5e5a1f/.github/workflows/build.yml (L434-L436)Not verified
2198bfcd71.process_vm_writev,mach_vm_write) and of the POSIX test branch.To get this to a good state
c2bd5e5a1f, or give the exact diff from2198bfcd71that the body relies on.guest_aioon Linux or macOS, or name the run that covers the POSIX branch.The hosted Windows job at the head is the remaining gate; if the head changes, the new diff will be read again.