fix(libSceNet): refuse a connect to a loopback port held without listening on macOS #22442
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22442"
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 011010 on 2026-11-17T16:19:42Z.
What
guest_sce_netfails on macOS atRequire(Failed(sceNetConnect(refused, closedAddress.data(), closedAddress.size()), 61))withsceNet errno 35(EAGAIN) instead of 61 (ECONNREFUSED), when the destination is a loopback port that another guest socket bound without listening.The cause is the host. XNU sends no reset for a SYN to a port a socket holds without
listen; it drops it. A nonblockingconnectthenpoll(POLLOUT, 1500)on macOS 27.0.1 getspoll0 withSO_ERROR0 after 1501 ms for that port, andPOLLHUPwithSO_ERROR61 at once for a port no socket holds. Soconnect_withinwaits out the timeout and reports the expiry. FreeBSD resets the connection, which is what the console reports.A blocking
sceNetConnectto a loopback address now fails withECONNREFUSEDwhen a guest socket in the same family holds that port on the loopback or wildcard address without listening. Nothing else changes: a port with a listener still connects, a port no guest socket holds still goes to the host (which refuses it at once on macOS), and a retry after an expired connect still returnsEADDRINUSEfirst.The debt fragment records what is not covered: a non-blocking connect to such a port still waits for the host's TCP connect timeout, a port held by a host socket outside the guest set is not detected, and the listen backlog below.
Tested
main1adc0e2f4b.guest_sce_net check failed at line 1188, sceNet errno 35.CheckConnectTimeoutExpirywithconnect timeout expiry: no connect stayed pending after 64 completed connects (last result 0x0, threw 0, 0 ms), which is a separate macOS gap, not this one; it is the second debt entry and gets its own issue.guest_socket_optionsfails with and without this change (a connect after a refused nonblocking one must fail with ECONNREFUSED (61), not start another attempt (errno 56)), so it is unrelated.guest_socket_pair,guest_tcp,guest_udpandguest_net_ctlpass.poll/SO_ERRORtable above, andlisten(0)followed by 64 connects, which completes all 64 with none refused.python3 tools/check_conventions.py --base origin/main: all conventions checks passed.python3 tools/pr_overlap.py --names GuestHoldsUnlistenedLoopback: not declared onmainand on no open pull request.python3 tools/pr_overlap.py --branch fix/macos-refuse-unlistened-loopback-connect: five open pull requests sharelibSceNet/Export.cpp, all libkernel cancellation work that callssceNetConnectfrom its tests; none of them edits the function.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)