fix(libkernel): drop a datagram whose receive faulted on macOS #19520
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19520"
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 imellag on 2026-11-13T13:04:48Z.
What
On macOS a datagram whose receive faults loses its source address but stays queued. When the guest's
recvfrombuffer is not writable, the hostrecvfromfails withEFAULT. XNU then leaves the datagram's data at the head of the queue without its address record, so the nextrecvfromreturns that data with an address length of 0. A title that asks who sent a packet gets an empty address, and AnyPS5 writes nothing to the address output (so a bad address pointer is not even reported). This is whyguest_udpfails on macOS atrecvfromwith address0x10, which returns 2 instead of failing withEFAULT.FreeBSD 11.4's
soreceive_dgramtakes the whole record off the socket buffer before copying it out, so a faulted receive loses that datagram, and Linux'sudp_recvmsgdrops it as well. The Windows path ofrecvfromalready does the same throughDropDatagram.Measured on macOS 27.2 (x86-64 under Rosetta 2) with a native program on a loopback UDP socket:
recvfrominto aPROT_READpageEFAULTrecvfromwith an addressMSG_PEEKfaultingrecvmsginto aPROT_READpage, thenrecvfromOn macOS, after the host
recvfromof a datagram socket fails withEFAULTand the guest did not ask forMSG_PEEK, the remnant is dropped with a 1-byte non-blockingrecv, so the next receive gets the next datagram with its address. Linux, whose kernel already dropped the datagram, and Windows are unchanged.recvmsgneeds nothing: it receives into a host buffer and copies out afterwards, so the host never faults there.The open #12682, #12688 and #12700 restructure this
recvfrom; whichever lands second carries the four lines over.Tested
macOS 27.2, Apple M4 Pro, x86-64 build under Rosetta 2,
maind4556df8a8:main:guest_udpaborts; with a print in the test, therecvfromwith address0x10returns 2 with address length 0, and with a print inrecvfromthe host reports family 0, size 0 for that datagram.guest_udppasses.ctest -R "^(guest_(udp|socket|sce_net|net|tcp|kqueue|poll|recv|send|http|ssl|unix|select|equeue)|net_)" -j6after a full incremental build: 120 of 128 pass. The failures are the onesmainalready has on macOS (guest_sce_net_linger#19488,guest_kqueue#19490,guest_socket_options#17879,guest_socket_port_zero#17878,guest_sce_net,guest_net_ctl,net_reuseport_patchednot run), plusguest_socket_read_write, which failed once under-j6and passes 5 of 5 runs on its own.Not run on Linux or Windows.
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)