Skip to content

fix(libkernel): fail bind and connect of a stream socket to a multicast address with EAFNOSUPPORT - #14875

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
roboterspinne:fix/libkernel-tcp-multicast-address
Nov 3, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
roboterspinne:fix/libkernel-tcp-multicast-address

Conversation

@roboterspinne

Copy link
Copy Markdown
Contributor

What

On e0caf13 (line numbers below refer to it) libkernel bind and connect pass a stream socket's multicast address to the host. Address() (core/libs/prx/libkernel/Socket/src/Udp.cpp:285-311) checks only the length and the family, and neither connect_nid_postfix (Udp.cpp:1446-1469) nor bind_nid_postfix (Udp.cpp:1547-1561) looks at the address class before ::connect and ::bind. The guest errno therefore comes from the host. On Windows, a TCP bind to 239.1.2.3 fails with EADDRNOTAVAIL (49), a blocking connect to 224.0.0.1 fails with EADDRNOTAVAIL, a non-blocking one returns EINPROGRESS (36), and a connect to 224.0.0.1:0 reaches ZeroPortConnect's EADDRNOTAVAIL (Udp.cpp:406-419). Other hosts answer with their own errors. FreeBSD 11.4 refuses a multicast address on a TCP socket with EAFNOSUPPORT in tcp_usr_bind, tcp6_usr_bind, tcp_usr_connect and tcp6_usr_connect. Each check runs right after the sa_len check, before in_pcbbind and tcp_connect. soconnect still answers EOPNOTSUPP for a listening socket and EISCONN for a connected one first (uipc_socket.c), because those checks come before pru_connect. The rule follows FreeBSD 11.4's tcp_usrreq.c. It was not measured on a PS5. The file's other address checks were measured on a PS5 (docs/dev/debt/libkernel.md:269); where the console was not measured, it follows FreeBSD 11.4 (connected stream sendto on line 269, IPv4-mapped datagram addresses on line 270).

Tested

Windows 11, WinLibs GCC 15.2.0, Ninja Release build with BUILD_TESTING=ON, on this branch based on e0caf13:

  • Counter-check: the new test was built against the untouched Udp.cpp of e0caf13 (cmake --build build --parallel 4 --target guest_socket_address_length_tests) and build/tests/guest_socket_address_length_tests.exe was run. It aborts at the first new check with tcp_usr_bind refuses an IPv4 multicast address, so bind to 239.1.2.3 must fail with EAFNOSUPPORT (47) (errno 49). The existing checks pass before it.
  • The test stops at its first failure, so the connect cases were checked separately with a small probe linked against libkernel and libc. It calls bind and connect with the addresses above and was run against the libkernel built from e0caf13 and from this branch:
    • bind to 239.1.2.3:0 and to [ff0e::1]:0: 49 before, 47 after;
    • non-blocking connect to 224.0.0.1:8080 and to [ff02::1]:8080: 36 before, 47 after;
    • blocking connect to 224.0.0.1:8080: 49 before, 47 after;
    • UDP bind to 239.1.2.3:0: 49 both times (unchanged).
  • Counter-check of the UDP case: with the socket->type == 1 guard removed from the bind check, the test aborts with the multicast check is in tcp_usr_bind only, so a datagram bind to 239.1.2.3 must not fail with EAFNOSUPPORT (47) (errno 47); with the guard restored it passes.
  • With the change: the same test build and run exits 0.
  • ctest --test-dir build -R '^(guest_socket_address_length|guest_socket_port_zero|guest_tcp|guest_poll)$' --output-on-failure: 4 of 4 passed (0.02 s, 0.05 s, 0.21 s, 0.40 s).
  • python tools/check_conventions.py --base e0caf13600 --head HEAD with this title and description passed.

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 (Claude Code)

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 11002 docs/dev/debt/libkernel.md L276-278

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 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7088 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7135 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7447 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7804 docs/dev/debt/libkernel.md
PR 9156 docs/dev/debt/libkernel.md
PR 9199 docs/dev/debt/libkernel.md
PR 9293 docs/dev/debt/libkernel.md
PR 9297 docs/dev/debt/libkernel.md
PR 9302 docs/dev/debt/libkernel.md
PR 9389 docs/dev/debt/libkernel.md
PR 9557 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9843 docs/dev/debt/libkernel.md
PR 9938 docs/dev/debt/libkernel.md
PR 9948 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 10025 docs/dev/debt/libkernel.md
PR 10319 docs/dev/debt/libkernel.md
PR 10442 docs/dev/debt/libkernel.md
PR 11896 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 11939 docs/dev/debt/libkernel.md
PR 12104 docs/dev/debt/libkernel.md
PR 12560 docs/dev/debt/libkernel.md
PR 12682 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 12688 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 12700 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 12965 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 12970 docs/dev/debt/libkernel.md
PR 13560 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 14103 docs/dev/debt/libkernel.md
PR 14128 docs/dev/debt/libkernel.md
PR 14212 docs/dev/debt/libkernel.md
PR 14264 docs/dev/debt/libkernel.md
PR 14310 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 14832 docs/dev/debt/libkernel.md
PR 14854 docs/dev/debt/libkernel.md
PR 14886 docs/dev/debt/libkernel.md
PR 14894 docs/dev/debt/libkernel.md

@BunnyFl BunnyFl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows 11, WinLibs GCC 15.2.0 r7, Release. Head 14fe943 merged into upstream/main 93dbd0f:

  • guest_socket_address_length, guest_socket_port_zero, guest_tcp, guest_udp, guest_socket_connect_listening, guest_socket_error: 6/6 passed.
  • Negative control: with main's Udp.cpp, guest_socket_address_length aborts with tcp_usr_bind refuses an IPv4 multicast address, so bind to 239.1.2.3 must fail with EAFNOSUPPORT (47) (errno 49).
  • Merged together with #14876: clean, 6/6 pass.

I checked the v4-mapped claim against FreeBSD 11.4's tcp_usrreq.c. tcp6_usr_bind and tcp6_usr_connect refuse only IN6_IS_ADDR_MULTICAST, and the v4-mapped branch of tcp6_usr_connect has no IN_MULTICAST check (that's only in the IPv4 functions). So leaving ::ffff:224.x to the host matches the source. The EALREADY gap you recorded in the debt entry is the right thing to write down.

@oneandonlydean oneandonlydean self-assigned this Nov 3, 2026
@oneandonlydean
oneandonlydean merged commit 7a3d08c into boykopovar:main Nov 3, 2026
12 checks passed
@roboterspinne
roboterspinne deleted the fix/libkernel-tcp-multicast-address branch November 3, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants