Repository navigation
fix(libkernel): fail bind and connect of a stream socket to a multicast address with EAFNOSUPPORT - #14875
Conversation
…st address with EAFNOSUPPORT
|
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.
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.
|
BunnyFl
left a comment
There was a problem hiding this comment.
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_lengthaborts withtcp_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.
What
On e0caf13 (line numbers below refer to it) libkernel
bindandconnectpass 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 neitherconnect_nid_postfix(Udp.cpp:1446-1469) norbind_nid_postfix(Udp.cpp:1547-1561) looks at the address class before::connectand::bind. The guest errno therefore comes from the host. On Windows, a TCPbindto239.1.2.3fails withEADDRNOTAVAIL(49), a blockingconnectto224.0.0.1fails withEADDRNOTAVAIL, a non-blocking one returnsEINPROGRESS(36), and aconnectto224.0.0.1:0reachesZeroPortConnect'sEADDRNOTAVAIL(Udp.cpp:406-419). Other hosts answer with their own errors. FreeBSD 11.4 refuses a multicast address on a TCP socket withEAFNOSUPPORTintcp_usr_bind,tcp6_usr_bind,tcp_usr_connectandtcp6_usr_connect. Each check runs right after thesa_lencheck, beforein_pcbbindandtcp_connect.soconnectstill answersEOPNOTSUPPfor a listening socket andEISCONNfor a connected one first (uipc_socket.c), because those checks come beforepru_connect. The rule follows FreeBSD 11.4'stcp_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 streamsendtoon line 269, IPv4-mapped datagram addresses on line 270).Rule. For a stream socket,
bindandconnectfail withEAFNOSUPPORT(47) when the address is IPv4 multicast (224.0.0.0/4) or IPv6 multicast (ff00::/8). The check uses a newMulticast()helper next toPeerConnectedand runs before the host is asked:bindit runs right afterAddress(). A socket that is already bound gets 47, notEINVAL, because FreeBSD checks beforein_pcbbind.connectit runs afterAddress()and the Windows loopback hook, and beforeZeroPortConnect, so224.0.0.1:0gets 47. The existing listening check (Udp.cpp:1453) still answersEOPNOTSUPPfirst. A connected socket skips the new check and still gets the host'sEISCONN.Unchanged: datagram sockets (FreeBSD lets them bind or connect to a multicast address), an IPv4-mapped multicast address on an
AF_INET6socket (FreeBSD'sIN6_IS_ADDR_MULTICASTdoes not match it, so it still goes to the host) andsceNetBind/sceNetConnect. One gap is recorded indocs/dev/debt/libkernel.md. FreeBSD'skern_connectatreturnsEALREADYfor everyconnectwhile the socket isSS_ISCONNECTING, blocking or not, beforesoconnectruns. libkernel keeps no connecting state, and the new check is skipped only oncegetpeernamesucceeds. So aconnectto a multicast address while anotherconnecton the socket is still in progress (a blocking one in another thread, or a pending non-blocking one) now gets 47 instead ofEALREADY. Before this change that call went to the host; what the host answered was not measured.Tests.
guest_socket_address_lengthgainsStreamSocketsRefuseMulticastAddresses. It expects 47 for:bindto239.1.2.3:0and to[ff0e::1]:0;connectto224.0.0.1:8080and to[ff02::1]:8080;connectto224.0.0.1:0;127.0.0.1binding239.1.2.3.It also expects 45 for a listening socket and 56 for a loopback-connected socket that connects to
224.0.0.1:8080. It also expects a UDPbindto239.1.2.3:0not to fail with 47; it does not check the exact result, which depends on the host. UDP multicastconnectstays out of the test for the same reason. The test needs no network: every refusal happens before a host call, and the connected case uses loopback.Overlap.
pr_overlap.py --branchfinds shared lines with one open pull request: fix(libkernel): let a guest ignore or catch SIGPIPE on Linux #11002 (SIGPIPE on Linux) rewrites the twodocs/dev/debt/libkernel.mdentries right below the one this branch adds (lines 271-272 on e0caf13); the entries cover different functions, so whichever merges second only needs that file rebased. It cannot compare 40 open pull requests that do not merge withmainand shareUdp.cppordocs/dev/debt/libkernel.md(feat(libkernel): sceKernelRaiseException on macOS hosts #4630, feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, feat(libkernel): support SEEK_DATA and SEEK_HOLE in lseek #6936, feat(libkernel): support kevent read and write events on regular files #7088, fix(libkernel): return EACCES for unknown ranges on direct-memory release paths #7105, feat(libkernel): report open, read and close notes on watched files #7121, fix(libkernel): follow kern_cpuset for the base cpuset, level checks and interrupt targets #7135, fix(threads): run Windows pthread and small fiber stacks in guest VA range #7149, feat(libkernel): deliver host faults to sceKernelInstallExceptionHandler handlers #7192, feat(libc): support archive-backed stdio reads #7447, perf(agc): keep unimported label stores on the CPU #7464, fix(libkernel): accept an address buffer without a length pointer in recvfrom #7507, feat(libkernel): process, thread and clock queries on macOS hosts #7804, fix(libkernel): fail sendmsg with EFAULT on guest memory it cannot read #8463, feat(libkernel): implement four pthread_attr forms #9156, docs(debt): cite firmware 10.01 kernel data for four libkernel entries #9199, feat(libkernel): implement the named ksem semaphores #9293, feat(libkernel_sys): implement POSIX message queues #9297, feat(libkernel_sys): implement kmq_notify registration #9302, feat(libkernel_sys): implement sigqueue #9389, feat(libkernel): keep the SIGIO owner of a pipe for F_GETOWN and F_SETOWN #9557, feat(libkernel): answer tcgetpgrp and tcsetpgrp on a pipe with its SIGIO owner #9566, fix(libkernel): throw on an EV_CLEAR EVFILT_WRITE knote with NOTE_LOWAT above 1 on a Linux TCP socket #9843, fix(libkernel): honor caller-provided pthread stacks #9938, fix(libkernel): map unbacked AMM PRT pages to one read-only zero page on Windows #10025, fix(libkernel): report lookup errors when creating through a trailing slash #10319, perf(agc): store an unimported label at once when unfinished work leaves guest memory alone #10442, feat(relinker): execute supported scalar guest GS accesses on Windows #11628, feat(relinker): support short scalar guest GS instructions #11661, feat(relinker): support SSE guest GS memory accesses #11689, feat(relinker): support VEX guest GS memory accesses #11698, fix(libkernel): wait for the rest of a MSG_WAITALL stream receive in the guest layer #11896, feat(libkernel): implement sceKernelGetProcessAbiType #11939, docs(debt): correct eight entries that no longer match the code #12104, fix(libkernel): preserve DOS device names and trailing dots or spaces on Windows #12560, feat(libkernel): cancel blocked POSIX reads with owned operations #12682, fix(libkernel): preserve blocking sockets over nonblocking native transport #12688, feat(libkernel): cancel blocked POSIX writes with partial progress #12700, feat(libkernel): support deferred cancellation in POSIX accept #12965, docs(debt): separate entries with blank lines and drop derived export totals #14212). Checked by hand: a trial merge of this branch with each of them conflicts in exactly the files thatmainwith it already conflicts in, so this branch adds no conflict. My open fix(libkernel): return EFAULT from AIO poll, cancel and delete for invalid memory #14417 also adds adocs/dev/debt/libkernel.mdentry and merges cleanly with this branch. My pull request "fix(libkernel): connect an AF_INET6 socket to ::1 when the address is unspecified, as FreeBSD does" also changesconnect_nid_postfixinUdp.cppanddocs/dev/debt/libkernel.md, in other lines; a trial merge of the two branches is clean.Tested
Windows 11, WinLibs GCC 15.2.0, Ninja Release build with
BUILD_TESTING=ON, on this branch based on e0caf13:Udp.cppof e0caf13 (cmake --build build --parallel 4 --target guest_socket_address_length_tests) andbuild/tests/guest_socket_address_length_tests.exewas run. It aborts at the first new check withtcp_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.bindandconnectwith the addresses above and was run against the libkernel built from e0caf13 and from this branch:bindto239.1.2.3:0and to[ff0e::1]:0: 49 before, 47 after;connectto224.0.0.1:8080and to[ff02::1]:8080: 36 before, 47 after;connectto224.0.0.1:8080: 49 before, 47 after;bindto239.1.2.3:0: 49 both times (unchanged).socket->type == 1guard removed from thebindcheck, the test aborts withthe 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.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 HEADwith this title and description passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)