fix(libkernel): dissolve a UDP association on connect to AF_UNSPEC #4498
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4498"
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 milescoviello on 2026-10-12T13:37:59Z.
What
connect()on a guest datagram socket rejected an address whose family isAF_UNSPEC(a null address) withEAFNOSUPPORTbefore touching the socket, so the socket stayed connected:getpeername()still returned the old peer,send()without an address still went there, and datagrams from any other sender never arrived.FreeBSD 11.4 disconnects a connected datagram socket first and only then rejects the address.
sys/kern/uipc_socket.c,soconnectat():udp_disconnect()(sys/netinet/udp_usrreq.c) clears the peer and keeps the local port (in_pcbdisconnect(inp); inp->inp_laddr.s_addr = INADDR_ANY;), andin_pcbconnect_setup()(sys/netinet/in_pcb.c) then returnsEAFNOSUPPORTfor the 16-byte address, the error main already returns.connect(2): "Datagram sockets may dissolve the association by connecting to an invalid address, such as a null address." libuv'suv__udp_disconnect()(src/unix/udp.c) disconnects with exactly this call and expectsEAFNOSUPPORTorEINVALon BSD.Now a connected internet datagram socket given a family byte of 0 is disconnected on the host first (
AF_UNSPECon Linux, a zeroed address on Windows), and the call then fails as before. Linux also drops an ephemeral local port on that disconnect, so the port is bound again on the wildcard address, which is what FreeBSD leaves. A host failure during the disconnect is returned as the call's error. Stream sockets and the socketpair sockets keep the previous path.Tested
Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on
mainc6efe068.guest_udpgained a case: a socket bound to127.0.0.1:0is connected to a peer, then connected to{16, AF_UNSPEC}; it must fail withEAFNOSUPPORT, then reportENOTCONNfromgetpeername, keep its local port with the wildcard address (on Linux and macOS, asudp_disconnect()resetsinp_laddrtoINADDR_ANY), failsend()without an address withEDESTADDRREQ, and receive a datagram from an unrelated socket.Udp.cppthe test aborts (getpeernameafter the disconnect returns 0 with the old peer; the unrelated datagram never arrives).guest_udppasses; allguest_*tests exceptguest_video_out_*: 306/306 passed.Not tested on Windows.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T15:32:25Z.
Review: COMMENTED
Also built and run here (CachyOS / GCC 16.2.1 — the head passes, the parent aborts). Your body already publishes the Red/Green pair, so the useful part is three readings rather than the differential:
[1] == 0guard is exact, and I checked the layout rather than assuming endianness:GuestAddresswrites the guest sockaddr asbytes[0] = length(16 or 28) andbytes[1] = family(2 or 28),Address()reads the family back frombytes[1]and fails with 47 otherwise, and the only other families in play areGuestUnix(a family byte of 1) plus those two — so[1] == 0is AF_UNSPEC and nothing else.EAFNOSUPPORT(47),getpeernameENOTCONN(57), the local port kept,sendEDESTADDRREQ(39), and the unrelated sender's datagram arriving. The last is the one that shows the host-level disconnect; the errno checks alone would also pass on a socket that merely reported an error.Disconnectreturns 0 whengetpeernameitself fails, i.e. "cannot query a peer" is treated as "not connected". That is right for a socket that never connected and it is what makes the guard cheap — one clause, so the early return does not read as a swallowed error._WIN32branch at all — thewindowsjob in.github/workflows/build.ymlis gated topush/workflow_dispatch, so it runs after merge rather than on this PR.Written with AI assistance.
Hermes Agent 🤖 at your service
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T15:33:22Z.
Windows test of head
9d4bbee7fmerged onto currentmain(d592d54e1, clean merge; built together with two other open PRs, so the run is for the combination): Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build 0 errors,-j2.guest_udp(the test this PR changes) passes. The 22 tests matchingguest_udp|guest_kernel_fcntl|guest_time_conversion|guest_ioctl|guest_socket|guest_dup|guest_pollall pass.Not checked: that the test fails without the change, Linux, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T17:46:17Z.
Your run closes the gap my review named, at the same head (
9d4bbee7f): thewindowsjob in.github/workflows/build.ymlis gated topush/workflow_dispatch, so PR CI never compiles the_WIN32branch this change lives in. That is why the Linux green I posted could not answer the Windows question, and yours does.Two things worth keeping in the record:
guest_udpagainst the parent'sUdp.cppwith this test kept is the missing half; on this host that same pair aborts atGuestUdp.cpp:228.Written with AI assistance.