fix(libkernel): check socket address families and lengths as measured on a PS5 #10299
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10299"
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 orezraey on 2026-10-23T16:37:46Z.
What
socket,bindandconnectmeasured on a retail PS5 (firmware 13.60) throughlibkernel_sys.sprxfrom a payload process. The source and console log are in this gist (pinet; the socket option cases in the same log are for a separate PR). The debt entries had these answers from the FreeBSD 11.4 source only.The console:
fails an
AF_INETaddress of any length but 16 withEINVAL, 17, 28 and 255 included, and anAF_INET6address of any length but 28 (24, 27, 29, 64); 256 is stillENAMETOOLONG;fails another family on an
AF_INETsocket withEAFNOSUPPORT(AF_INET6,AF_UNIX,AF_UNSPEC), and takes the length, notsa_len, as the size;disconnects a connected datagram socket when
connectto port 0 fails withEADDRNOTAVAIL, so a followingsendfails withEDESTADDRREQ(#9105 has since landed this onmain; this PR now only adds the measurement to its debt entry);fails
SOCK_SEQPACKETlikeSOCK_RDMand an unknown type:EPROTOTYPEwith protocol 0,EPROTONOSUPPORTwith another.AnyPS5 accepted longer addresses, checked the length before the socket's family, and failed
SOCK_SEQPACKETwithEPROTONOSUPPORTfor protocol 0.Addressnow takes the socket's family and checks it in the order FreeBSD'sudp_bindandin6_pcbbinddo;connectstill refuses a listening socket withEOPNOTSUPPfirst, assoconnectdoes. The one exception, kept from #9108, is an IPv4-mapped address longer than 28 bytes on anAF_INET6datagram socket withIPV6_V6ONLYcleared:bindand nowconnectuse its first 28 bytes, as FreeBSD'sudp6_bindandudp6_connecthand it toin_pcbbindandin_pcbconnectas asockaddr_in; the console was measured only with::1andIPV6_V6ONLYat its default, so this has its own debt entry, andsendtostill fails it withEINVAL. Every address case was measured on datagram sockets, so the address debt entry says stream sockets follow the same order unmeasured, and the order tests use datagram sockets. No probe gavebindorconnecton anAF_INETsocket another family with a wrong length, so their family-first order is listed as unmeasured too (FreeBSD 11.4'stcp_usr_bindandtcp_usr_connectcheck the length first) and is not tested. A connected stream socket'ssendtonow checks only the address length and ignores the address, as FreeBSD'stcp_usr_senddoes once the connection has started, instead of failing a 17-byte address withEINVAL.AF_UNSPECwas tried only with 127.0.0.1, so itsINADDR_ANYbind, which FreeBSD accepts, is listed as unmeasured. Thesocket, address and port 0 debt entries now say what was measured and what still differs (SOCK_RAW,IPPROTO_UDPLITEandAF_UNIXsockets, which the console created).Tested
Windows 11, MinGW (winlibs), and Linux (WSL Ubuntu, GCC), at head
20b38adb09(mainmerged again after #9363 landed; only themlockallandsocketdebt lines met, keepingmain'smlockallwording and this PR's measuredsocketentry). At this head the 30 Windows tests matching^guest_(socket|udp|tcp)and the six Linux tests below pass three runs in a row. Earlier,mainwas merged after #9169 landed in65e712b9c6. #9169'sMismatchedAndUnknownFamiliesFailis kept with its unknown-family cases and theAF_INETaddress on anAF_INET6socket; its three cases that order the length and family checks of anAF_INETsocket the other way (bindandconnectof a 28-byteAF_INET6address on a stream socket expectingEINVAL,sendtoof one on a datagram socket expectingEAFNOSUPPORT) were dropped, because the console failssendtowithEINVAL, asLongAddressesAndOtherFamiliesFailchecks; thebindandconnectorder of a wrong family and length on anAF_INETsocket was not measured, so the debt entry lists it as unmeasured and no test asserts it.Windows: the 30 tests matching
^guest_(socket|udp|tcp)pass three runs in a row. Linux:guest_socket_address_length,guest_socket_port_zero,guest_udp,guest_tcp,guest_socket_connect_listeningandguest_socket_errorpass three runs in a row.guest_socket_address_lengthchecks the longer addresses and the other families, and #9108's long mappedbind(plusconnect) on a dual-stack datagram socket, andsendtowith a 17-byte address on a connected stream socket (it fails without the change);guest_socket_port_zerochecks the disconnect, with #9105's test kept after mergingmain. The socket tests pass three runs in a row (guest_kqueuefailed under-j 8each time and passes alone, as onmain).The full suite (
-E "^agc_|^select_tests$") passes apart fromwindows_diagnostic_fixture_isolation, which timed out under load and passes alone.tools/check_conventions.pypasses.tools/pr_overlap.py: #7475, #8728, #8921, #9105, #9108, #9169, #9363 touch nearby lines; whichever lands second keeps both.Checklist
Based on current
main; no other open PR implements the same functionsOne topic per PR; follow-ups go in a new PR
No comments in code except technical debt
Unimplemented paths throw (
NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt fileNo notes, investigation
.mdfiles or images added to the repository (attach them to this PR)New third-party code is a submodule built from source
Generic behaviour, not specific to one title
Depends on: #7475 (merge order only: it edits the same lines; this PR is refreshed after it; #9363 has merged); #11002 and #11042 edit the debt entries next to this PR's (merge order only)
Fixes: none
Unblocks: none
GPUs tested: n/a
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:19:11Z.
Review: COMMENTED
Checked against main
7966e590ef, FreeBSD 11.4/13.2 sources (in_pcb.c,udp_usrreq.c,tcp_usrreq.c,in6_pcb.c,udp6_usrreq.c) and thepinet/pinet5logs in your gist:pinet.logandpinet5.logmatches the newAddressorder, and the length/EFAULT checks still come before EBADF/ENOTSOCK. The console looks like a hybrid: family-first on AF_INET bind/connect matches 13.xudp_bind/udp_connect(11.4'sin_pcbbind_setuphas the family check under#ifdef notdef), while length-first on AF_INET6 and on AF_INETsendtomatches 11.4. The measurement is the right source here.pinet.c/pinet5.cuseSOCK_DGRAM. For TCP the sources disagree: 11.4tcp_usr_bind/tcp_usr_connectcheck the length first and ignore the family, while 13.2tcp6_usr_bind/tcp6_usr_connectcheck the family first. Could the debt entry say the order was measured on datagram sockets only?GuestSocketAddressLength.cpp:95,98,102assert the stream order as if it were measured.sendtoon a connected stream socket: FreeBSD (11.4tcp_usr_sendL955, 13.2 L1021) only reads the address whilet_state < TCPS_SYN_SENT. With this PR,sendto(connected_tcp, "x", 1, 0, &sin, 17)now fails with EINVAL fromAddress(..., true)(Udp.cpp:1429), while main accepted the 17-byte address and passed it on to the host.sendmsgforwards to it too. Maybe skip the address checks for a connected stream socket, or keep the old debt note that streamsendtoisn't checked.sa_family == AF_UNSPECandINADDR_ANYis accepted by both 11.4 (no family check) and 13.2 (theudp_bind/tcp_usr_bindcompatibility branch). The probe only triedAF_UNSPECwith 127.0.0.1, so I'd mark that case as unmeasured in the debt entry rather than listing it under "another family fails with EAFNOSUPPORT".Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:18:35Z.
Review: CHANGES_REQUESTED
The previously identified behavior gaps now appear addressed in this head: datagram tests distinguish family/length precedence, the connected-stream
sendtocase is covered, and the unmeasuredAF_UNSPEC/stream scope is recorded. The Windows socket test runs are useful and accurately report the unrelatedguest_kqueueparallel failure.Please correct one test-report discrepancy: the body says Linux is covered by CI, but the current hosted
linuxandwindowsproduct checks are bothSKIPPED; the reported socket runs are local Windows runs. Either record Linux as not tested or add an actual Linux run after integration.The declared merge-order PRs #7475, #9363 and #9169 are all still open. This branch is based on
7f3e661, 6,670 commits behind currentmain, and the changed socket/test/debt paths have moved since. After the stated order is resolved, please refresh onto currentmain, preserve the measured cases and run the focused socket tests plus conventions/overlap checks on the final head. I found no new functional issue in the current diff.