fix(libkernel): reject port-zero connect on unconnected sockets #6884
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6884"
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 MarcZX10 on 2026-10-16T16:00:00Z.
What
Fixes #6880. Rejects
connect()to port zero on unconnected IPv4 and IPv6 stream or datagram sockets withEADDRNOTAVAIL(49), matching FreeBSD 11.4. A connected stream socket still reportsEISCONN; connected datagram behavior andsendto/sendmsgare unchanged. The implementation carries Hussein Kadhim’s two commits, preserving his authorship.Tested
guest_socket_port_zero_teststarget build passed.guest_socket_port_zeroand the non-GPU socket/network tests on Linux after locally applying the same stream-socket predicate; all those tests passed, with only the two known baseline file-writer failures in the full suite. That run was on the previous PR head plus their local patch, not this pushed follow-up.git diff --checkandpython3 tools/check_conventions.py --base upstream/mainpass for this follow-up.Checklist
main; no other open PR implements the same behaviorImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T16:11:58Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T17:12:19Z.
Review: COMMENTED
First native run of the new test on Linux (the description notes CTest could not execute it on the author's host).
Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON.Head
34425f6ebmerged ontomain66e290f1c.Results:
guest_socket_port_zerofails on Linux inCheckStream(2):connect to port 0 on an unconnected stream socket must fail with EADDRNOTAVAIL (49) (errno 61)The UDP IPv4 and IPv6 checks before it pass.
ECONNREFUSEDfor a TCPconnect()to127.0.0.1:0/[::1]:0(checked with a plain host probe: TCP ->ECONNREFUSED, UDP -> success). So "TCP already returns 49" holds on Windows, not on Linux.main(fix reverted): fails earlier, inCheckDatagram(2)with errno 2, as expected.-E "^agc|gpu|vulkan|video_out"): 648/651 with the PR vs 648/650 on base; the extra failure isguest_socket_port_zero. The other two are the knownfile_writer_binary/file_writer_textfailures on this host, also on base.FreeBSD's
in_pcbconnect_setup()(shared bytcp_connect()andudp_connect()) rejects port 0 withEADDRNOTAVAILfor both socket types, so extending the check to stream sockets would match FreeBSD on every host. I tried that locally by changing the type check inZeroPortDatagramConnectto accept type 1 and 2:guest_socket_port_zeroand the other 17 socket/UDP/net tests pass on Linux, and the full non-GPU suite is back to the 2 known failures. The connected-streamEISCONNandsendtochecks are unaffected, sincegetpeernamesucceeds there. The alternative is to drop the stream port-0 assertion, but then Linux keeps returning 61 where FreeBSD returns 49.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T17:18:03Z.
Thanks for the Linux matrix and source investigation. I broadened the predicate in
629c069c1to unconnected IPv4/IPv6 stream and datagram sockets, kept thegetpeernameguard so connected stream sockets retainEISCONN, and updated the debt note and PR scope. The Windows checks and builds I ran on the prior head did not cover Linux TCP; your Linux run exercised the corresponding widened predicate and reported the socket/network tests passing. I could not run the updated binary here: fresh configuration is blocked because this Linux host lacks XRandR support. Local conventions andgit diff --checkpass. Could you rerunguest_socket_port_zeroon the pushed head when convenient?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T17:20:40Z.
Correction to my previous validation note: I completed a fresh Linux configure and built
guest_socket_port_zero_testssuccessfully. CTest then stopped at AnyPS5’s host CPU guard before socket checks because this Xeon lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA. The PR description now records the corrected build/test status.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T19:59:31Z.
Thanks for the Linux run and the negative control. This confirms that the port-zero normalization currently applies only to datagram sockets: Linux returns
ECONNREFUSEDfor an unconnected stream while FreeBSD returnsEADDRNOTAVAIL. Your local extension to stream sockets passes the focused socket tests and restores the full non-GPU suite to its two baseline failures. I will update the PR to normalize unconnected stream port-zero connects too, preserving the connected-stream checks, and report the focused validation.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T20:00:16Z.
The stream normalization is now present in the PR head as commit
629c069c1b3a106abca3d6729874726266d792b6(fix(libkernel): match FreeBSD port-zero stream connects). It extends the unconnected zero-port check to stream sockets, leaving the connected-streamEISCONNandsendtobehavior intact.guest_socket_port_zero_testsbuilds locally; CTest is blocked before the test by this host’s PS5 CPU-feature guard (missing LZCNT, BMI1/2, MOVBE, AVX2 and FMA). The Linux review reported the focused socket and related tests passing with this change. Current PR checks: conventions, eligibility and report pass; full Linux/Windows and unrelated targeted jobs are skipped by workflow conditions.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T20:53:02Z.
I have opened #6950 for the distinct listening-socket
EOPNOTSUPPbehavior from #6923. I manually checked the sharedUdp.cpphunks: #6884 adds the port-zero helper/check, while #6950 adds the listener check after address conversion and before the family check. They can coexist; if either lands first, I will preserve both changes when rebasing. #6950 also notes the shared-file overlap and the test evidence/limits.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T05:03:27Z.
@MarcZX100 #6950 has merged and now conflicts with this PR in Udp.cpp. Could you rebase onto main? Please keep the listener check ahead of the port-zero check when you resolve it, since that order is what review passed. We'll run full CI on the new head and merge it once that's green.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T09:35:45Z.
Rebase handoff — rebased onto current
main(all commits, authorship unchanged). Three successive conflicts inUdp.cpp, all the same shape:main's newerListening()helper kept alongside this PR's evolving port-zero connect check (UnsetPort→ZeroPortDatagramConnect→ZeroPortConnectacross the series, each step's refinement preserved).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
ba915c253.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T11:19:57Z.
Review: COMMENTED
Rerun on the pushed head, as asked.
Machine: Linux x86_64, i7-8700 (passes the host CPU guard), Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build.Head
629c069c1merged ontomaind9b696ddb(clean merge).guest_socket_port_zeropasses, including the stream case that failed on34425f6eb.main: fails at the first check,connect to port 0 on an unconnected datagram socket must fail with EADDRNOTAVAIL (49), so the test still covers the change.ctest -R "socket|udp|^guest_sce_net$|refused", 18 tests): all pass.ctest -E "^agc|gpu|vulkan|video_out"): 649/651. The two failures arefile_writer_binaryandfile_writer_text, which fail the same way onmainon this machine (648/650).Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T12:42:49Z.
Rebased onto current
main(c9e6c45de) and incorporated the reviewed stream-socket port-zero handling from the rebase handoff. The two original commits remain authored by Hussein Kadhim; my follow-up commit remains authored by MarcZX100.guest_socket_port_zero_testsandlibkernelbuild on Linux,check_conventions.pyandgit diff --checkpass. I attemptedguest_socket_port_zero; this host stops at the project CPU guard because it lacks LZCNT, BMI1/2, MOVBE, AVX2 and FMA, so runtime assertions remain for CI. The new head is9452647ed.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T12:43:50Z.
The new CI run is now complete: conventions, eligibility and report pass, but Linux, Windows, register-context, relinker and write-watch jobs were skipped by the workflow path filter. Since the earlier handoff requested full CI on the rebased head, could a maintainer dispatch the full build/test workflow for
9452647ed?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T13:18:05Z.
Thanks for rerunning the pushed head. The focused port-zero test and all 18 socket/network tests now pass on Linux; the only two non-GPU suite failures match base. This resolves the earlier Linux runtime gap. The hosted PR workflow still skipped the full platform jobs, so I’ll retain that limitation in the PR status notes.
AI-assisted: yes (Codex); report reviewed.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T23:33:35Z.
Review: COMMENTED
Run on the rebased head
9452647ed, which the author's host cannot execute (CPU guard), and one ordering issue from the conflict resolution.Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build.Head
9452647edmerged ontomain5de7a46e0(clean merge).guest_socket_port_zeroandguest_socket_connect_listeningpass, as do the other socket/network tests (ctest -R "socket|udp|^guest_sce_net$|refused", 21 tests).main: fails atconnect to port 0 on an unconnected datagram socket must fail with EADDRNOTAVAIL (49) (errno 2), so the test still covers the change.ctest -E "^agc|gpu|vulkan|video_out"): 698/698, the 697 tests ofmainplusguest_socket_port_zero.Ordering: @oneandonlydean asked to keep the listener check ahead of the port-zero check. In
9452647ed,connect_nid_postfixcallsZeroPortConnect(Udp.cpp:1007) beforeif (socket->type == 1 && Listening(*socket)) return Fail(45);(Udp.cpp:1014). A listening stream socket has no peer, soZeroPortConnecttakes it and returnsEADDRNOTAVAIL. I added one line toCheckStreambefore the close,connect_nid_postfix(listener, zero.data(), size)expecting -1 with errno 45:errno 49;ZeroPortConnectline moved after theListeningcheck:guest_socket_port_zero(with that line) andguest_socket_connect_listeningpass.FreeBSD's
soconnectat()returnsEOPNOTSUPPfor a socket withSO_ACCEPTCONNbefore it reaches the protocol's connect, so 45 should win for a listener whatever the address.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:26:16Z.
I rebased #6884 onto current
main(cd20b7f6f) and addressed the listener ordering reported on the review:connect_nid_postfixnow returnsEOPNOTSUPPfor an already-listening stream socket before applying the port-zero rule.guest_socket_port_zeronow checks that connecting the listener to a zero-port address returnsEOPNOTSUPPfor IPv4 and IPv6.The rebased tree passes
tools/check_conventions.py --base upstream/mainandgit diff --check. The focused test target compiled in the existing Linux review build. CTest stopped before the assertions because this host lacks LZCNT, BMI1/2, MOVBE, AVX2 and FMA; that runtime result is not counted as a pass. Hosted checks for the new head are pending.