fix(libkernel): return EFAULT from poll for an unreadable or unwritable descriptor array #12462
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12462"
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 babyhuey on 2026-10-28T14:46:28Z.
What
pollread and wrote the guestpollfdarray in place, so a non-null array in unmapped or read-only memory crashed the host. FreeBSD'ssys_pollcopies the array in withcopyinand the results out withcopyout, returningEFAULTif either fails.PollDescriptors, which now runs on a local copy.poll_nid_postfixkeeps the existingtimeout < -1(EINVAL) and null-array (EFAULT) checks first, copies the array in withGuestCopyIn_nid_no_patch, callsPollDescriptors, and on success copies it back withGuestCopyOut_nid_no_patch. Either copy failing returnsEFAULT(14). A failed poll copies nothing back.Tested
core/libs/tests/GuestPoll.cppadds: an unmapped array (0x10) fails withEFAULT, and a read-only array holding one valid entry fails withEFAULTat the copy-out and is left unchanged.anyps5-buildCI image, Ubuntu 24.04, GCC 13, Release,BUILD_TESTING=ON), this head364a28eb2d7onmain2227f136618:guest_pollpasses; the fullctestpasses (2,696 of 2,696), andcheck_conventions.pypasses. Withmain'sUdp.cppthe same test segfaults.BUILD_TESTING=ON, this head: full build andlibssucceed;guest_pollpasses 3 of 3 alone; withmain'sUdp.cppit crashes (0xc0000005). CI's test selection for this change (2,348 tests): 1,621 pass, 726 skip, and the one failure ischeck_main_synctiming out at 120 s under--parallel 4(it takes 97-100 s under the same load onmain); alone on this head it passes 3 of 3 in 53-63 s.check_conventions.pypasses.#11223 also edits the body of
poll; it doesn't touch the lines this changes, and its current head merges with this one without conflicts.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-10-28T14:51:22Z.
Review: CHANGES_REQUESTED
Blocking: the kqueue retry path still calls the public
poll_nid_postfixwrapper from insidePollDescriptors. After this refactor,descriptorsthere points to the wrapper's localstd::vector, not guest memory. When an open kqueue is not readable, either recursive call at lines 1986/1988 sends that host pointer toGuestCopyIn_nid_no_patch; the call then fails withEFAULTinstead of waiting/rechecking, sopollon a non-readable kqueue returns early. Please route this internal retry throughPollDescriptorsitself (or otherwise keep the guest-copy boundary only at the exported entry point), and add/extend a test for an open, initially non-readable kqueue with both finite and infinite waits if the harness supports it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T15:24:35Z.
Review: APPROVED
Reviewed exact head
364a28eb2d7e403b4d91655787055ac81d37b5f7. The wrapper preserves timeout/null validation order, copies the guest descriptor array in, runs the existing poll logic on the local copy, and copies results back only after a successful poll. The new tests exercise both an unmapped input and a read-only output array, including the unchanged-output expectation. Hosted Linux full CTest and Windowsguest_pollresults are reported in the PR; my independentgit diff --checkand merge-tree check against currentmainalso pass.I previously raised a concern about the kqueue retry with the local vector and then withdrew it after confirming the guest-copy helpers support host-side vector storage. I found no remaining blocker in this change.