libkernel: recvfrom on a TCP socket returns a fake 28-byte IPv6 sender address instead of length 0; fix branch ready #3942

Closed
opened 2026-10-11 19:27:37 +00:00 by husseinkad · 1 comment
husseinkad commented 2026-10-11 19:27:37 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-11T19:27:37Z.


recvfrom on a connected TCP socket with an address buffer reports an address length of 28 and fills in a made-up AF_INET6 address. FreeBSD 11.4 kern_recvit returns a sender address only for sockets that have one; a stream socket has none, so the length comes back 0 and the buffer is left alone. A guest that reads the length to decide whether a datagram sender is present is misled on TCP.

Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/kernel-socket-recvfrom-stream-address (one commit on current main, Socket/src/Udp.cpp and tests/GuestTcp.cpp). When the host reports no AF_INET or AF_INET6 sender, recvfrom now reports length 0, which is what recvmsg already does.

Checks:

  • The new guest_tcp case fails on main (assertion abort) and passes with the change; guest_(tcp|udp|poll|socket|dup) pass.
  • Probed through the guest exports on loopback, IPv4 and IPv6, against main. Only the TCP lines change: every case now returns length 0 with the buffer untouched, including MSG_PEEK, truncated and zero-length address buffers, zero-length data buffers and EOF on both ends. UDP IPv4 and IPv6 are byte-identical to main (sender address, family, port, sa_len, peek, truncated address buffer, zero-length datagram, connected socket). A null addrlen with a non-null address still gives EFAULT; Unix socketpairs are unchanged.
  • Two independent reviews found nothing wrong. check_conventions.py is clean and pr_overlap.py finds no overlap.

Not covered: a truncated address buffer still returns the full length (16 or 28) where FreeBSD returns the smaller of the two; that comes from GuestAddress and is the same on main, for recvmsg, accept and getsockname too. recvfrom on an unconnected TCP socket gives EINVAL where FreeBSD gives ENOTCONN, also unchanged. Only Windows was built and run.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5804393541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3942). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-11T19:27:37Z. --- `recvfrom` on a connected TCP socket with an address buffer reports an address length of 28 and fills in a made-up AF_INET6 address. FreeBSD 11.4 `kern_recvit` returns a sender address only for sockets that have one; a stream socket has none, so the length comes back 0 and the buffer is left alone. A guest that reads the length to decide whether a datagram sender is present is misled on TCP. Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/kernel-socket-recvfrom-stream-address (one commit on current main, `Socket/src/Udp.cpp` and `tests/GuestTcp.cpp`). When the host reports no AF_INET or AF_INET6 sender, `recvfrom` now reports length 0, which is what `recvmsg` already does. Checks: - The new `guest_tcp` case fails on main (assertion abort) and passes with the change; `guest_(tcp|udp|poll|socket|dup)` pass. - Probed through the guest exports on loopback, IPv4 and IPv6, against main. Only the TCP lines change: every case now returns length 0 with the buffer untouched, including `MSG_PEEK`, truncated and zero-length address buffers, zero-length data buffers and EOF on both ends. UDP IPv4 and IPv6 are byte-identical to main (sender address, family, port, `sa_len`, peek, truncated address buffer, zero-length datagram, connected socket). A null `addrlen` with a non-null address still gives `EFAULT`; Unix socketpairs are unchanged. - Two independent reviews found nothing wrong. `check_conventions.py` is clean and `pr_overlap.py` finds no overlap. Not covered: a truncated address buffer still returns the full length (16 or 28) where FreeBSD returns the smaller of the two; that comes from `GuestAddress` and is the same on main, for `recvmsg`, `accept` and `getsockname` too. `recvfrom` on an unconnected TCP socket gives `EINVAL` where FreeBSD gives `ENOTCONN`, also unchanged. Only Windows was built and run. AI-assisted: yes
oneandonlydean commented 2026-10-12 06:17:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T06:17:33Z.


Closing: fixed by #3957. recvfrom reports length 0 when the host returns no AF_INET or AF_INET6 sender (Socket/src/Udp.cpp). The truncated-length case you listed as not covered is in #4295.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6118862764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3942#issuecomment-6118862764). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T06:17:33Z. --- Closing: fixed by #3957. `recvfrom` reports length 0 when the host returns no AF_INET or AF_INET6 sender (`Socket/src/Udp.cpp`). The truncated-length case you listed as not covered is in #4295.
Sign in to join this conversation.
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#3942
No description provided.