fix(libkernel): fail bind and connect with EFAULT on an unreadable address #17253
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17253"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-11-08T16:19:32Z.
What
bindandconnectread the guestsockaddrthrough the raw pointer after only checking the length and the null pointer, so an unusable address such as0x10or an unreadable page crashed the host. FreeBSD 11.4'ssys_bindandsys_connectcallgetsockaddrbefore they look the descriptor up: a length aboveSOCK_MAXADDRLEN(255) givesENAMETOOLONG, a length below the size ofsa_familygivesEINVAL, and an address that cannot be copied in givesEFAULT. Both functions now copy the address into a local 255-byte buffer withGuestCopyIn_nid_no_patchright afterAddressLengthError, returnEFAULTwhen that fails and use the copy from then on, which is whatsendtoalready does. The existing order is kept, sobind(-1, ...)andconnect(-1, ...)with an unreadable address giveEFAULTbeforeEBADF, as in the kernel, and every later read stays within the copiedlength.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, onmainf5fe807353.guest_socket_address_length: new checks thatbindandconnectfail withEFAULTfor the address0x10and an unreadable page on an invalid descriptor, on a stream socket and on a datagram socket. WithSocket/src/Udp.cppreverted tomainthe test fails (an unreadable address on a valid socket crashed the host, and on descriptor -1mainansweredEBADF); with this change it passes, three runs out of three.python tools/check_conventions.py --base upstream/main: passes.Overlaps
preserve blocking sockets over nonblocking native transport), #12700 and #12965 (a stack by one author) rewriteconnect_nid_postfixinSocket/src/Udp.cpp, where this PR adds three lines at the top ofconnectandbind. They already conflict withmain, sopr_overlap.pydid not compare them. This PR goes first and they rebase onto it (three lines each); asked on #12688.GuestSockets::ReadvandWritevin the same file, far frombindandconnect. #11896 changesrecv; #12682, #15785, #16826, #7088 and #5021 touch other parts ofUdp.cpp.Checklist
main; no other open PR implements the same functionNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-09T08:52:32Z.
Review: COMMENTED
Windows run of head
9ca464d50a, merged ontomain286b14d2f7in one tree with 47 other small open PRs that touch different files. Setup: Windows 11, WinLibs GCC 15.2 r7 (x86_64-ucrt-posix-seh, the CI toolchain), Release,BUILD_TESTING=ON.guest_socket_address_lengthwith--repeat until-fail:5: 5 / 5 pass.main'sUdp.cppand this PR's test: 5 / 5 runs fail.