fix(libkernel): validate address family against socket family in bind #9169
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9169"
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 slopgobblercobbler on 2026-10-21T14:09:54Z.
What
bindnow validates that the sockaddr family matches the socket family (native.ss_family != (socket->family == 2 ? AF_INET : AF_INET6)), returning-1withEAFNOSUPPORT(47) on mismatch like FreeBSD 11.4 and consistent withconnectandsendto. Also extendedGuestSocketAddressLength.cppwith tests for family mismatches and unknown address families acrossbind,connect, andsendto.Tested
Windows 10/11 x64:
GuestSocketAddressLength.cppverifies:bindwith an AF_INET6 address on an AF_INET socket fails withEAFNOSUPPORT(47).bindwith an AF_INET address on an AF_INET6 socket fails withEAFNOSUPPORT(47).connectandsendtofamily mismatch paths fail withEAFNOSUPPORT(47).EAFNOSUPPORT(47).bindwith a short AF_INET6 address (< 28) fails withEINVAL(22).python tools/check_conventions.py --base upstream/main --head HEAD: All conventions checks passed (0 findings, 0 errors).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 repositoryImported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T16:44:19Z.
Linux data point for
ad7d9abec4: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release,BUILD_TESTING=ON, PR head alone (not merged ontomain; its merge-base is1fd67185b).ctest -R '^guest_socket_address_length$'passes 3 of 3.libkernel/Socket/src/Udp.cpprestored to the merge-base (the PR's tests kept): fails (Subprocess aborted).Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:56:53Z.
Review: COMMENTED
Checked against main
99feaf0eb8and FreeBSD 11.4 (releng/11.4)sys/netinet/in_pcb.c,tcp_usrreq.c,udp_usrreq.c,sys/netinet6/in6_pcb.c,udp6_usrreq.c:Udp.cppbind and inGuestSocketAddressLength.cpp(3-waygit merge-tree), so the rebase requested above is still needed.tcp_usr_bind(tcp_usrreq.c:301-310) andudp_bindonly testsa_len, and thesin_family != AF_INETcheck inin_pcbbind_setupsits under#ifdef notdef(in_pcb.c:584-591, "old programs incorrectly fail to initialize it"). Sobind(AF_INET socket, {16, 99, ...}, 16)binds on FreeBSD 11.4, whileconnectdoes fail withEAFNOSUPPORT(in_pcbconnect_setup, in_pcb.c:1031-1032). Main already returns 47 for that bind fromAddress(), so the new assertion pins behaviour the source disagrees with. Could you drop it or link a console measurement?Address()already returns 47 for unknown families andLongAddressErrorreturns 22 for 28-byte AF_INET6 addresses. For AF_INET6,in6_pcbbindcheckssa_len != 28(EINVAL) beforesa_family != AF_INET6(EAFNOSUPPORT) (in6_pcb.c:141-147), so 47 is right for a 28-byte AF_INET address and 22 for a 16-byte one.docs/dev/debt/libkernel.md(line 213), since none of it is measured on a console?Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.