Skip to content

fix(libkernel): fail bind and connect with EFAULT on an unreadable address - #17253

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Gruzzberry:fix/socket-bind-connect-efault
Nov 16, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Gruzzberry:fix/socket-bind-connect-efault

Conversation

@Gruzzberry

Copy link
Copy Markdown
Contributor

What

bind and connect read the guest sockaddr through the raw pointer after only checking the length and the null pointer, so an unusable address such as 0x10 or an unreadable page crashed the host. FreeBSD 11.4's sys_bind and sys_connect call getsockaddr before they look the descriptor up: a length above SOCK_MAXADDRLEN (255) gives ENAMETOOLONG, a length below the size of sa_family gives EINVAL, and an address that cannot be copied in gives EFAULT. Both functions now copy the address into a local 255-byte buffer with GuestCopyIn_nid_no_patch right after AddressLengthError, return EFAULT when that fails and use the copy from then on, which is what sendto already does. The existing order is kept, so bind(-1, ...) and connect(-1, ...) with an unreadable address give EFAULT before EBADF, as in the kernel, and every later read stays within the copied length.

Tested

Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON, on main f5fe807.

  • guest_socket_address_length: new checks that bind and connect fail with EFAULT for the address 0x10 and an unreadable page on an invalid descriptor, on a stream socket and on a datagram socket. With Socket/src/Udp.cpp reverted to main the test fails (an unreadable address on a valid socket crashed the host, and on descriptor -1 main answered EBADF); with this change it passes, three runs out of three.
  • The other socket, UDP, TCP, connect, bind, poll and select tests that build here (91 tests) pass.
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux, macOS, a console, a title run, the full suite.

Overlaps

Checklist

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

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 11896 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12682 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12688 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12700 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12965 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 14970 core/libs/prx/libkernel/Socket/src/Udp.cpp

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 9ca464d50a, merged onto main f35f1e5eca (35049e0dc6, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_socket_address_length passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@gabichuuuuu gabichuuuuu 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 run of head 9ca464d50a, merged onto main 286b14d2f7 in 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_length with --repeat until-fail:5: 5 / 5 pass.
  • Negative control, with main's Udp.cpp and this PR's test: 5 / 5 runs fail.

…dress

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Gruzzberry
Gruzzberry force-pushed the fix/socket-bind-connect-efault branch from c4491af to 55c6c6e Compare November 15, 2026 21:24
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 15, 2026
@oneandonlydean
oneandonlydean merged commit ce25fed into boykopovar:main Nov 16, 2026
15 checks passed
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.

5 participants