fix(libkernel): let recvfrom with an address buffer and no length pointer receive without the address, as FreeBSD 11.4 does #18167
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18167"
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-10T17:32:19Z.
What
recvfrom(s, buf, len, flags, from, NULL)(an address buffer but no length pointer) fails withEFAULTbefore it receives anything, on the native path (core/libs/prx/libkernel/Socket/src/Udp.cpp:2066onb8194198cf; line numbers below refer to it) and on the path forwarded to a libSceNet socket (Udp.cpp:2053; onmaindc19132bacthe two checks are atUdp.cpp:2107and:2094): both runif ((!buffer && length) || (address && !addressLength)) return Fail(14);. FreeBSD 11.4, the kernel behind the PS5'srecvfrom, receives such a call normally; this is read from the FreeBSD source and not measured on the console.sys_recvfromcopies in*fromlenaddronly whenfromlenaddris not NULL and otherwise setsmsg_namelen = 0, keepsmsg_name = fromand callsrecvit.kern_recvitthen sets the address length to 0 becausemsg_namelen <= 0, so no address is copied out.recvitwrites the length back onlyif (namelenp != NULL). The call returns the byte count and writes neitherfromnor a length. The check came in with9cbefb7e04(tracked UDP sockets) and was carried over to the forwarded path by7a4fa3865b; neither cites a console measurement, anddocs/dev/debt/libkernel.mdhas no entry for it.recvfromno longer rejects a non-nullfromwith a nullfromlen; it receives as usual and returns the byte count without writingfrom. The rest ofrecvfromalready handles a null length pointer: the native path writes the address only throughReportAddress(Udp.cpp:533-535), and every call to it is behindaddressLength(:2071,:2078,if (!addressLength) return result;at:2098). The forwarded path hands libSceNet its ownnamebuffer andreported(= 0, becausecapacitystays 0) and returns atif (!addressLength) return received;(:2059);sceNetRecvfromwith a zero length writes no address (core/libs/prx/libSceNet/Export.cpp:1615-1617,native_to_guest_addressat:309). These cases still fail withEFAULT: an unreadablefromlen(the copy-in atUdp.cpp:2049, ascopyinfails insys_recvfrom); an unwritablefromwith a nonzero*fromlen, after the receive, throughReportAddress(:2060,:2110), as the addresscopyoutfails inkern_recvit(covered bycore/libs/tests/GuestUdp.cpp:482-484); and a null buffer with a nonzero length. That last one faults here before the receive, where FreeBSD faults only on copyout; the timing is a separate topic and stays as it is. Also unchanged: libSceNet's ownsceNetRecvfrom, which rejects the same pair withNET_EINVAL(Export.cpp:1598) as an SCE API, andacceptandgetsockname, where FreeBSD requires the length pointer.guest_sce_net_kernel_forwards(core/libs/tests/GuestNetKernelForwards.cpp) runsCheckDatagramandCheckArgumentsfor a native socket and for a libSceNet socket, so both paths are covered.CheckDatagramgains a case after the existing capacity loop and the receive without an address: it sends a datagram, clears the receive buffer, and receives with a 16-bytefromfilled with 0xAA and a null length pointer; the call must return the payload size, deliver the payload, and leavefromunchanged. #18474, merged after this PR was opened, addedconnectchecks at the same place; the merge withmain(b5b8dabba0) keeps both blocks unchanged and puts this case first (GuestNetKernelForwards.cpp:77-83onb5b8dabba0, theconnectchecks at:84-91), because the case sends with a destination address and FreeBSD 11.4'sudp_outputrefuses that withEISCONNonce the UDP socket is connected. The oldEFAULTassertion for this pair inCheckArguments(GuestNetKernelForwards.cpp:108onb8194198cf,:135onb5b8dabba0) would now block on the bound, empty UDP socket, so it usesMSG_DONTWAIT(0x80) and expectsEAGAIN(35), as the assertion at:113(:140) does, and requires the address bufferlocalunchanged. TheEFAULTcases for an unreadable length pointer (:109-110,:136-137) stay.pr_overlap.py --branch, run on the merge commitb5b8dabba0, reports no shared lines or exports with the open pull requests it can compare. It cannot compare #11896, #12682, #12688, #12700, #12965 and #17253, which sharecore/libs/prx/libkernel/Socket/src/Udp.cppbut do not merge withmain. Checked by hand onb5b8dabba0againstmaindc19132bac: a trial merge of this branch with each of them conflicts in the same files asmainwith it (identical sets for all six), and theUdp.cppconflicts are the same hunks with and without this branch (five for #11896, three for #12965, two for #12700, one each for #12682, #12688 and #17253), and none of them touches the two changed(address && !addressLength)lines. None of the six changes the(address && !addressLength)check inrecvfromor editsGuestNetKernelForwards.cpp, so none implements this change. #16577 (a test-only audit of listen backlogs) asserted the old behaviour (core/libs/tests/GuestSocketBacklog.cpp:189on its branch requiredrecvfromwith an address buffer and a null length pointer to fail withEFAULT); it was closed unmerged on 2026-11-11, andmaindoes not contain that file. #7507 proposed the same change earlier and was closed unmerged on 2026-11-02 by its author, after #13756 (merged) reworked therecvfromEFAULT handling; its review found that removing the check let theReceiveAnsweredHereearly return write through a null length pointer. Onb8194198cfevery write of the length is guarded byaddressLength(Udp.cpp:2059,:2071,:2078,:2098; onb5b8dabba0:2100,:2112,:2119,:2145), so that case cannot recur.Tested
Windows 11, WinLibs GCC 15.2.0, build directory configured with Ninja, Release and
BUILD_TESTING=ON, on this branch based onc5488026ab; the rebase ontob8194198cfchanges none of the files this change touches or this text cites (git diff --statbetween the two bases is empty for them), so the runs below were not repeated. Each test executable was run frombuild/testswithbuild/core/libs/libs/unpatched,build/core/libs/libsand the MinGWbinonPATH:c5488026ab(the twoUdp.cpplines put back):cmake --build build --parallel 4 --target guest_net_kernel_forwards_tests, thenguest_net_kernel_forwards_tests.exeaborted withfailed at line 82, errno 14, the newrecvfrom(receiver, received, sizeof(received), 0, from.data(), nullptr)assertion on the native socket.cmake --build build --parallel 4 --target guest_net_kernel_forwards_tests guest_udp_tests guest_socket_address_length_tests guest_socket_timeouts_tests guest_tcp_tests guest_socket_pair_tests guest_socket_on_non_socket_tests guest_underscore_entry_tests guest_datagram_receive_tests guest_socket_host_write_tests, then the eight executablesguest_net_kernel_forwards_tests(0.35 s),guest_udp_tests,guest_socket_address_length_tests,guest_socket_timeouts_tests,guest_tcp_tests,guest_socket_pair_tests,guest_socket_on_non_socket_testsandguest_underscore_entry_testspassed 8/8, and the 18 runs registered asguest_datagram_*andguest_socket_host_write_*(guest_datagram_receive_testswithrecv,recvfrom,sceNetRecv,sceNetRecvfrom;guest_socket_host_write_testswithrecv,recvfrom,read,sceKernelRead,sceNetRecv,sceNetRecvfrom,sceNetRecvmsg, each for UDP and withtcp) passed 18/18.maindc19132bacinb5b8dabba0, which the two runs above predate: git reported one conflict, theCheckDatagramhunk described under Tests;Udp.cppmerged without one and differs frommainonly in the two changed lines (git diff dc19132bac2 b5b8dabba0 --stat:2 files changed, 11 insertions(+), 3 deletions(-)). In a fresh build directory with the same options, the ten targets above built, and the same 26 runs passed 26/26 in onectestrun (guest_sce_net_kernel_forwards,guest_udp,guest_socket_address_length,guest_socket_timeouts,guest_tcp,guest_socket_pair,guest_socket_on_non_socket,guest_underscore_entriesand the 18guest_datagram_*andguest_socket_host_write_*runs). Counter-check onb5b8dabba0withUdp.cppchecked out fromdc19132bac:guest_sce_net_kernel_forwardsaborted withfailed at line 82, errno 14, the new assertion; withUdp.cpprestored it passed again.sys/kern/uipc_syscalls.candsys/netinet/udp_usrreq.cfetched fromrelease/11.4.0.python tools/check_conventions.py --base upstream/main --head HEAD(upstreammain=dc19132bac, HEAD at the merge commitb5b8dabba0) with 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 PrivacyOnion on 2026-11-10T19:37:09Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d4c7fcf10f:tools/check_conventions.pypassed;git diff --checkclean.pipe-write (macos-15-intel),pipe-write (macos-15).guest_net_kernel_forwards_testsbuilt cleanly.guest_sce_net_kernel_forwards):core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T20:23:44Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b5b8dabba0:tools/check_conventions.pypassed;git diff --checkclean.guest_net_kernel_forwards_testsbuilt cleanly.guest_sce_net_kernel_forwards):core/libs/prx/libkernel/Socket/src/Udp.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:23:44Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b5b8dabba0:tools/check_conventions.pypassed;git diff --checkclean.guest_net_kernel_forwards_testsbuilt cleanly.guest_sce_net_kernel_forwards):core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me