fix(libkernel): return EOPNOTSUPP when connecting to a listener #6950

Merged
MarcZX10 merged 2 commits from upstream-pr/6950 into main 2026-10-17 05:00:50 +00:00
MarcZX10 commented 2026-10-16 20:52:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T20:52:56Z.


What

Return FreeBSD's EOPNOTSUPP (45) when connect() targets a listening stream socket. Convert and validate the supplied address first, so null and short addresses keep their address errors; the listener check remains before the address-family check. Adds a focused regression test for listener errors, address-validation order, a cross-family address, and continued accept/connect behavior.

Closes #6923.

The two implementation commits preserve Hussein Kadhim's authorship. They were rebased onto current main (4986aca62e5984de1a34531648af7c987e40eb5d); the address-ordering commit needed a manual resolution in Udp.cpp to retain current main's Windows closed-loopback handling before the listener check.

#6884 also inserts a separate port-zero check in connect_nid_postfix and a helper in Udp.cpp. These behaviors are independent. If #6884 merges first, rebase this PR and retain both checks. The other Udp.cpp overlap reported with #6828 is in native socket lookup, separate from this connect behavior. Shared CMakeLists.txt hunks from the overlap report were manually checked; the other PRs add different source files, tests, or platform-specific handling.

Tested

  • The issue's reported Windows build and socket-group tests were run against the original two-commit branch before this rebase; they have not been rerun on this current-main head.
  • Local git diff --check and python3 tools/check_conventions.py --base upstream/main pass.
  • A fresh Linux CMake configure was attempted but could not complete: the SDL2 submodule checkout is absent, and the host does not provide XRandR development support. No local build or runtime result is claimed for this head.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4894144118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6950). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T20:52:56Z. --- ### What Return FreeBSD's `EOPNOTSUPP` (45) when `connect()` targets a listening stream socket. Convert and validate the supplied address first, so null and short addresses keep their address errors; the listener check remains before the address-family check. Adds a focused regression test for listener errors, address-validation order, a cross-family address, and continued accept/connect behavior. Closes #6923. The two implementation commits preserve Hussein Kadhim's authorship. They were rebased onto current `main` (`4986aca62e5984de1a34531648af7c987e40eb5d`); the address-ordering commit needed a manual resolution in `Udp.cpp` to retain current main's Windows closed-loopback handling before the listener check. #6884 also inserts a separate port-zero check in `connect_nid_postfix` and a helper in `Udp.cpp`. These behaviors are independent. If #6884 merges first, rebase this PR and retain both checks. The other `Udp.cpp` overlap reported with #6828 is in native socket lookup, separate from this connect behavior. Shared `CMakeLists.txt` hunks from the overlap report were manually checked; the other PRs add different source files, tests, or platform-specific handling. ### Tested - The issue's reported Windows build and socket-group tests were run against the original two-commit branch before this rebase; they have not been rerun on this current-main head. - Local `git diff --check` and `python3 tools/check_conventions.py --base upstream/main` pass. - A fresh Linux CMake configure was attempted but could not complete: the SDL2 submodule checkout is absent, and the host does not provide XRandR development support. No local build or runtime result is claimed for this head. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-16 21:04:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T21:04:33Z.


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.

Pull request Shared files not compared
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6222 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 6487 core/libs/prx/libkernel/CMakeLists.txt
PR 6828 core/libs/prx/libkernel/Socket/src/Udp.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224667462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6950#issuecomment-6224667462). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T21:04:33Z. --- <!-- pr-overlap --> 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. | Pull request | Shared files not compared | |---|---| | [PR 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/Socket/src/Udp.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/Socket/src/Udp.cpp` | | [PR 6487](https://www.github.com/boykopovar/AnyPS5/pull/6487) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6828](https://www.github.com/boykopovar/AnyPS5/pull/6828) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` |
Dextroid17 commented 2026-10-16 21:50:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-16T21:50:07Z.


Linux run of this head, since the description says no local build or runtime result is claimed for it (the Windows runs it cites were on the branch before the rebase).

Setup: head 0d188ba6b (based on main 4986aca62), Release, BUILD_TESTING=ON, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1. Tests ran under env -i with only HOME and PATH set (configure and build used the normal shell environment). Each arm ran ctest -R ^guest_socket (10 tests, guest_socket_connect_listening among them) 3 times.

  • Head: 10 of 10 pass in each of the 3 runs.
  • Revert arm: with Udp.cpp as on 4986aca62 (the 6 added lines removed) and the new test kept, guest_socket_connect_listening fails 3 of 3 with connect on a listening socket must fail with EOPNOTSUPP (45) (errno 56), and the other 9 pass. 56 is FreeBSD's EISCONN. By reading, without the check the call reaches the host connect, which on Linux fails with EISCONN for a listening TCP socket (__inet_stream_connect in net/ipv4/af_inet.c), and that is translated to 56.
  • Merged with main at e9a3343a2: clean merge, 10 of 10 pass in each of the 3 runs.

By reading the FreeBSD 11.4 source (not checked on PS5 hardware), the PR's order matches it: sys_connect runs getsockaddr first (null-address and length errors), then kern_connectat → soconnect → soconnectat returns EOPNOTSUPP for SO_ACCEPTCONN. That is before the protocol connect runs: tcp_usr_connect checks the address length, and in_pcbconnect_setup checks the family.

git merge-tree of this head with #6884 (629c069c1) reports a conflict in Udp.cpp, as the description anticipates. Whichever merges second needs a rebase that keeps both checks.

Not checked: Windows on this head, where RefuseClosedLoopbackAtOnce_nid_no_patch runs before the listener check (by reading, a loopback address with no listener on the port gets SIO_TCP_INITIAL_RTO set on the listening socket before EOPNOTSUPP returns; the new test does not reach that case). Also not checked: macOS, an IPv6 listener (the test's listener is IPv4), datagram sockets (the check applies only when socket->type == 1), and behaviour on PS5 hardware.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225354727 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6950#issuecomment-6225354727). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-16T21:50:07Z. --- Linux run of this head, since the description says no local build or runtime result is claimed for it (the Windows runs it cites were on the branch before the rebase). **Setup:** head `0d188ba6b` (based on `main` `4986aca62`), Release, `BUILD_TESTING=ON`, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1. Tests ran under `env -i` with only `HOME` and `PATH` set (configure and build used the normal shell environment). Each arm ran `ctest -R ^guest_socket` (10 tests, `guest_socket_connect_listening` among them) 3 times. - **Head:** 10 of 10 pass in each of the 3 runs. - **Revert arm:** with `Udp.cpp` as on `4986aca62` (the 6 added lines removed) and the new test kept, `guest_socket_connect_listening` fails 3 of 3 with `connect on a listening socket must fail with EOPNOTSUPP (45) (errno 56)`, and the other 9 pass. 56 is FreeBSD's `EISCONN`. By reading, without the check the call reaches the host `connect`, which on Linux fails with `EISCONN` for a listening TCP socket (`__inet_stream_connect` in `net/ipv4/af_inet.c`), and that is translated to 56. - **Merged with `main` at `e9a3343a2`:** clean merge, 10 of 10 pass in each of the 3 runs. By reading the FreeBSD 11.4 source (not checked on PS5 hardware), the PR's order matches it: `sys_connect` runs `getsockaddr` first (null-address and length errors), then `kern_connectat` → `soconnect` → `soconnectat` returns `EOPNOTSUPP` for `SO_ACCEPTCONN`. That is before the protocol connect runs: `tcp_usr_connect` checks the address length, and `in_pcbconnect_setup` checks the family. `git merge-tree` of this head with #6884 (`629c069c1`) reports a conflict in `Udp.cpp`, as the description anticipates. Whichever merges second needs a rebase that keeps both checks. Not checked: Windows on this head, where `RefuseClosedLoopbackAtOnce_nid_no_patch` runs before the listener check (by reading, a loopback address with no listener on the port gets `SIO_TCP_INITIAL_RTO` set on the listening socket before `EOPNOTSUPP` returns; the new test does not reach that case). Also not checked: macOS, an IPv6 listener (the test's listener is IPv4), datagram sockets (the check applies only when `socket->type == 1`), and behaviour on PS5 hardware. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. AI-assisted: yes
MarcZX10 commented 2026-10-16 22:14:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T22:14:39Z.


Thanks for the independent Linux run and the revert comparison. The three repeated guest_socket runs pass on this head, and the revert consistently exposes the EISCONN versus EOPNOTSUPP difference; the clean merge-tree result with #6884 is useful too. I have noted the limits you called out: Windows/macOS, IPv6, datagram sockets, and PS5 hardware were not covered. I have not run those checks locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225721812 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6950#issuecomment-6225721812). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T22:14:39Z. --- Thanks for the independent Linux run and the revert comparison. The three repeated `guest_socket` runs pass on this head, and the revert consistently exposes the `EISCONN` versus `EOPNOTSUPP` difference; the clean merge-tree result with #6884 is useful too. I have noted the limits you called out: Windows/macOS, IPv6, datagram sockets, and PS5 hardware were not covered. I have not run those checks locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6950
No description provided.