fix(libkernel): report EISCONN for an address on a connected socketpair end as FreeBSD does #14043

Merged
Ragbie merged 2 commits from upstream-pr/14043 into main 2026-11-07 16:38:16 +00:00
Ragbie commented 2026-10-31 16:55:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ragbie on 2026-10-31T16:55:57Z.


What

An address on a socketpair end is handled as FreeBSD 11.4 handles it on a connected AF_UNIX socket. Before this PR every such call reported EAFNOSUPPORT without reaching the host, on every host. Three cases differ:

  • connect on a stream or sequenced-packet end whose peer is open now returns EISCONN. soconnectat returns it for a connected socket of a connection-oriented protocol before it looks at the address. shutdown leaves the end connected, so this also holds after it. After the peer closes, unp_disconnect disconnects the end, and connect still reports EAFNOSUPPORT, as unp_connectat does for a non-AF_UNIX address.
  • sendto and sendmsg with an address on a datagram end whose peer is open now return EISCONN, as uipc_send does when unp_conn is set. The check comes after the flag, length and buffer checks and before waiting for send space, which a datagram end never needs in uipc_send. After the end's own shutdown(SHUT_WR) the send goes to the host and fails with EPIPE, as sosend_generic checks SBS_CANTSENDMORE first.
  • sendto and sendmsg with an address on a stream or sequenced-packet end now ignore the address and send, as uipc_send does on a connected end. Stream ends already did this while the host reported a peer; sequenced-packet ends reported EAFNOSUPPORT. After the peer closes the host send gives EPIPE, as FreeBSD's soisdisconnected sets SBS_CANTSENDMORE.

The pair end counts as connected while its guest peer object is alive. dup shares that object, so closing one alias keeps the end connected, as FreeBSD's file reference does.

bind keeps EAFNOSUPPORT, which uipc_bindat returns for a non-AF_UNIX address. connect on a datagram end is not changed.

The libkernel socketpair debt entry said all three calls should report the console's EISCONN. That entry came from #1711, which has no console measurement for it, and FreeBSD's source contradicts it for bind and for an addressed stream sendto. The entry now states the remaining differences:

  • An AF_UNIX path is not resolved: bind, and a connect or addressed sendto that FreeBSD passes to unp_connect, report EAFNOSUPPORT.
  • connect on a datagram end keeps it connected. FreeBSD disconnects it first and then fails.
  • A datagram over FreeBSD's 2048-byte limit (unpdg_sendspace) is not refused with EMSGSIZE.

The entry was over the 1000-character limit, so it is reworded to fit. Two sentences that describe no difference from the console are dropped: read/write going to the host, and the reason the loopback connection reports no POLLHUP.

Tested

guest_socket_pair gets CheckAddressOnPairEnd:

  • Stream:
    • connect with an AF_INET address returns EISCONN, also after shutdown(SHUT_RDWR), and EINVAL for a 1-byte address.
    • bind returns EAFNOSUPPORT.
    • An addressed sendto is delivered to the peer.
    • On a fresh pair whose peer is closed: connect returns EAFNOSUPPORT, and addressed sends end in EPIPE.
  • Datagram:
    • Addressed sendto and sendmsg return EISCONN, and the pair still exchanges data.
    • bind returns EAFNOSUPPORT.
    • After shutdown(SHUT_WR), sends with and without an address return EPIPE, also once the peer is closed.
  • Sequenced packet (Linux only, as the existing cases): connect returns EISCONN, an addressed sendto is delivered, and after the peer closes it returns EPIPE.

Windows 11 Pro, Intel Core i5-14600KF, WinLibs GCC 15.2.0, full Release build:

  • Without the fix (main's Udp.cpp): guest_socket_pair aborts.
  • With the fix:
    • guest_socket_pair passes with --repeat until-fail:5, and the 156 tests matching socket|tcp|udp|kqueue|equeue|guest_net|select|poll|net_|recv|send|shutdown (without the select_tests_* tests of the test-selection tool) pass with --repeat until-fail:3.
    • Full ctest on main 474030e58: 99% tests passed, 2 tests failed out of 3191. Both fail on main on this machine too:
      • guest_wide_formatting: %Z gives the host's non-ASCII zone name, which #10987 addresses.
      • agc_driver_image_plane_address_on_line.
    • check_skips.py reports one skip, guest_fopen_errors. It skips itself on this machine because creating symbolic links needs Developer Mode.

Linux (Ubuntu 24.04 container, GCC 13.3.0): without the fix guest_socket_pair aborts; with it, it passes with --repeat until-fail:5, and the 117 tests matching the same pattern pass with --repeat until-fail:3. Full Linux ctest was not run.

macOS: not tested. The changed code is shared, and macOS has no sequenced-packet pair.

Overlaps: none. #7090 (SCM_RIGHTS) and #11896 (MSG_WAITALL) change other parts of Udp.cpp; #13742 changes socketpair's result-pointer check.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5099624265 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14043). Originally posted by [Ragbie](https://github.com/Ragbie) on 2026-10-31T16:55:57Z. --- ### What An address on a socketpair end is handled as FreeBSD 11.4 handles it on a connected `AF_UNIX` socket. Before this PR every such call reported `EAFNOSUPPORT` without reaching the host, on every host. Three cases differ: - `connect` on a stream or sequenced-packet end whose peer is open now returns `EISCONN`. [`soconnectat`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c#L1002-L1005) returns it for a connected socket of a connection-oriented protocol before it looks at the address. `shutdown` leaves the end connected, so this also holds after it. After the peer closes, `unp_disconnect` disconnects the end, and `connect` still reports `EAFNOSUPPORT`, as [`unp_connectat`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_usrreq.c#L1336-L1337) does for a non-`AF_UNIX` address. - `sendto` and `sendmsg` with an address on a datagram end whose peer is open now return `EISCONN`, as [`uipc_send`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_usrreq.c#L881-L889) does when `unp_conn` is set. The check comes after the flag, length and buffer checks and before waiting for send space, which a datagram end never needs in `uipc_send`. After the end's own `shutdown(SHUT_WR)` the send goes to the host and fails with `EPIPE`, as `sosend_generic` checks `SBS_CANTSENDMORE` first. - `sendto` and `sendmsg` with an address on a stream or sequenced-packet end now ignore the address and send, as `uipc_send` does on a connected end. Stream ends already did this while the host reported a peer; sequenced-packet ends reported `EAFNOSUPPORT`. After the peer closes the host send gives `EPIPE`, as FreeBSD's `soisdisconnected` sets `SBS_CANTSENDMORE`. The pair end counts as connected while its guest peer object is alive. `dup` shares that object, so closing one alias keeps the end connected, as FreeBSD's file reference does. `bind` keeps `EAFNOSUPPORT`, which [`uipc_bindat`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_usrreq.c#L473-L474) returns for a non-`AF_UNIX` address. `connect` on a datagram end is not changed. The libkernel `socketpair` debt entry said all three calls should report the console's `EISCONN`. That entry came from #1711, which has no console measurement for it, and FreeBSD's source contradicts it for `bind` and for an addressed stream `sendto`. The entry now states the remaining differences: - An `AF_UNIX` path is not resolved: `bind`, and a `connect` or addressed `sendto` that FreeBSD passes to `unp_connect`, report `EAFNOSUPPORT`. - `connect` on a datagram end keeps it connected. FreeBSD disconnects it first and then fails. - A datagram over FreeBSD's 2048-byte limit (`unpdg_sendspace`) is not refused with `EMSGSIZE`. The entry was over the 1000-character limit, so it is reworded to fit. Two sentences that describe no difference from the console are dropped: `read`/`write` going to the host, and the reason the loopback connection reports no `POLLHUP`. ### Tested `guest_socket_pair` gets `CheckAddressOnPairEnd`: - **Stream:** - `connect` with an `AF_INET` address returns `EISCONN`, also after `shutdown(SHUT_RDWR)`, and `EINVAL` for a 1-byte address. - `bind` returns `EAFNOSUPPORT`. - An addressed `sendto` is delivered to the peer. - On a fresh pair whose peer is closed: `connect` returns `EAFNOSUPPORT`, and addressed sends end in `EPIPE`. - **Datagram:** - Addressed `sendto` and `sendmsg` return `EISCONN`, and the pair still exchanges data. - `bind` returns `EAFNOSUPPORT`. - After `shutdown(SHUT_WR)`, sends with and without an address return `EPIPE`, also once the peer is closed. - **Sequenced packet** (Linux only, as the existing cases): `connect` returns `EISCONN`, an addressed `sendto` is delivered, and after the peer closes it returns `EPIPE`. Windows 11 Pro, Intel Core i5-14600KF, WinLibs GCC 15.2.0, full Release build: - **Without the fix (`main`'s `Udp.cpp`):** `guest_socket_pair` aborts. - **With the fix:** - `guest_socket_pair` passes with `--repeat until-fail:5`, and the 156 tests matching `socket|tcp|udp|kqueue|equeue|guest_net|select|poll|net_|recv|send|shutdown` (without the `select_tests_*` tests of the test-selection tool) pass with `--repeat until-fail:3`. - Full `ctest` on `main` `474030e58`: `99% tests passed, 2 tests failed out of 3191`. Both fail on `main` on this machine too: - `guest_wide_formatting`: `%Z` gives the host's non-ASCII zone name, which #10987 addresses. - `agc_driver_image_plane_address_on_line`. - `check_skips.py` reports one skip, `guest_fopen_errors`. It skips itself on this machine because creating symbolic links needs Developer Mode. Linux (Ubuntu 24.04 container, GCC 13.3.0): without the fix `guest_socket_pair` aborts; with it, it passes with `--repeat until-fail:5`, and the 117 tests matching the same pattern pass with `--repeat until-fail:3`. Full Linux `ctest` was not run. macOS: not tested. The changed code is shared, and macOS has no sequenced-packet pair. **Overlaps:** none. #7090 (`SCM_RIGHTS`) and #11896 (`MSG_WAITALL`) change other parts of `Udp.cpp`; #13742 changes `socketpair`'s result-pointer check. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!14043
No description provided.