fix(libkernel): accept an nfds above 1024 in select and pselect, as a PS5 does #19631
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19631"
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 brajankw on 2026-11-13T16:59:23Z.
What
selectfailed annfdsabove 1024 withEINVAL, where a PS5 (firmware 13.60) accepts 1025 (theselectentry indocs/dev/debt/libkernel.md).selectnow takes anynfdsfrom 0 up.KernelSelectCheckSets_nid_no_patchreads the bits from descriptor 1024 up to the byte of bitnfds - 1, in chunks of 4096 bytes, and one byte at a time after a chunk fails. A set bit on a descriptor that is not open failsEBADF, and an unreadable byte failsEFAULT. FreeBSD 11.4'sselect_check_badfddoes the same past its last open descriptor.nfdsup to 1024, otherwise 1024 or the highest set descriptor plus one. This bounds the copied sets by the open descriptors, whatevernfdsis.KernelSelectCheckedSets_nid_no_patchcopies that range in, runs the existing scan and copies it back. Sets up to 1024 bits stay on the stack.pselect: when a caught signal interrupts it,ScanAfterCaughtSignalchecks the sets once. It saves and restores the range the scan writes, instead of handing annfdsabove 1024 toselect.EINVALfor 1025 (GuestSelect.cpp,GuestSelectWait.cpp,GuestSceNet.cpp) now expect the console's answer.GuestSelect.cppandGuestKernelSysPselect.cpphold 2048 bits.GuestSelect.cpp, above 1024:nfds1025;EBADFfor the closed descriptor 1500 in the read set and in the except set;dup2'd to 1500, reported as ready in the read set and the write set;GuestSelect.cpp, sets at the end of a mapping:nfds1025 succeeds, 1033 failsEFAULT, and with descriptor 1025 set, 1033 failsEBADFbefore reaching the unreadable byte;nfdsofINT_MAXover one mapped page failsEFAULT.GuestKernelSysPselect.cpp: a caught signal with descriptor 1500 in the set returnsEINTRand leaves the set as it was, andEBADFonce 1500 is closed.EBADF,EFAULTandEINVAL;Tested
Linux (Debian 13, GCC 14.2.0, Release), on
mainfc69f49ce4.ctest -R '^(guest_kernel_sys_pselect|guest_select|guest_select_wait|guest_sce_net.*|guest_poll|guest_socket_descriptors|guest_sp_syscall_wrapper)$': 14/14 passed,guest_sce_net_kernel_forwardsincluded.main's libkernel fail. All four ofguest_select,guest_select_wait,guest_sce_netandguest_kernel_sys_pselectfail. The page-edgenfds1025 case and theEBADF-before-fault case also fail on the previous headd3e86ee87d, which read whole words.ctest(5811 tests,-j 12, RTX 3060) on this head: 5795 passed. Of the 16 failures, five areagc_drivercases that also failed onmainin the same environment and ten need a.gitdirectory, network or a passwd entry for the user.agc_driver_image_table_packed_guardspassed when rerun on its own.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch fix/libkernel-select-nfds-above-1024: failed closed on 30 pull requests that conflict withmain. None of their diffs touchesselect,pselector theselectdebt entry.17bebb404fin the comments; the rebase changed no line of the patch. Not tested on macOS. No title.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-13T17:26:30Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d3e86ee87d:tools/check_conventions.pypassed;git diff --checkclean.guest_kernel_sys_pselect_tests,guest_sce_net_tests,guest_select_tests,guest_select_wait_testsbuilt cleanly.guest_kernel_sys_pselect,guest_sce_net_linger,guest_sce_net_keepalive,guest_sce_net_kernel_forwards,guest_sce_net,guest_sce_net_reuseport_ipv4,guest_sce_net_reuseport_ipv6,guest_sce_net_listen_ipv4,guest_sce_net_listen_ipv6,guest_select_wait,guest_select):Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T18:42:01Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
17bebb404f:tools/check_conventions.pypassed;git diff --checkclean.guest_kernel_sys_pselect_tests,guest_sce_net_tests,guest_select_tests,guest_select_wait_testsbuilt cleanly.guest_kernel_sys_pselect,guest_sce_net_linger,guest_sce_net_keepalive,guest_sce_net_kernel_forwards,guest_sce_net,guest_sce_net_reuseport_ipv4,guest_sce_net_reuseport_ipv6,guest_sce_net_listen_ipv4,guest_sce_net_listen_ipv6,guest_select_wait,guest_select):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T20:24:10Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
bfd794fa71:tools/check_conventions.pypassed;git diff --checkclean.guest_kernel_sys_pselect_tests,guest_sce_net_tests,guest_select_tests,guest_select_wait_testsbuilt cleanly.guest_kernel_sys_pselect,guest_sce_net_linger,guest_sce_net_keepalive,guest_sce_net_kernel_forwards,guest_sce_net,guest_sce_net_reuseport_ipv4,guest_sce_net_reuseport_ipv6,guest_sce_net_listen_ipv4,guest_sce_net_listen_ipv6,guest_select_wait,guest_select):core/libs/prx/libkernel/Socket/include/SocketPoll.hpp,core/libs/prx/libkernel/Socket/src/Pselect.cpp,core/libs/prx/libkernel/Socket/src/Socket.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 PrivacyOnion on 2026-11-15T20:24:11Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
bfd794fa71:tools/check_conventions.pypassed;git diff --checkclean.guest_kernel_sys_pselect_tests,guest_sce_net_tests,guest_select_tests,guest_select_wait_testsbuilt cleanly.guest_kernel_sys_pselect,guest_sce_net_linger,guest_sce_net_keepalive,guest_sce_net_kernel_forwards,guest_sce_net,guest_sce_net_reuseport_ipv4,guest_sce_net_reuseport_ipv6,guest_sce_net_listen_ipv4,guest_sce_net_listen_ipv6,guest_select_wait,guest_select):core/libs/prx/libkernel/Socket/include/SocketPoll.hpp,core/libs/prx/libkernel/Socket/src/Pselect.cpp,core/libs/prx/libkernel/Socket/src/Socket.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 PrivacyOnion on 2026-11-16T09:40:46Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
715f629a37:tools/check_conventions.pypassed;git diff --checkclean.guest_kernel_sys_pselect_tests,guest_sce_net_tests,guest_select_tests,guest_select_wait_testsbuilt cleanly.guest_kernel_sys_pselect,guest_sce_net,guest_select_wait,guest_select):core/libs/prx/libkernel/Socket/include/SocketPoll.hpp,core/libs/prx/libkernel/Socket/src/Pselect.cpp,core/libs/prx/libkernel/Socket/src/Socket.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me