Skip to content

fix(libkernel): fail readv and writev on a socket with EFAULT for an unusable buffer - #17248

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Gruzzberry:fix/socket-readv-writev-efault
Nov 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Gruzzberry:fix/socket-readv-writev-efault

Conversation

@Gruzzberry

Copy link
Copy Markdown
Contributor

What

readv and writev (and sceKernelReadv, sceKernelWritev) on a guest socket gathered the caller's buffers with a raw memcpy from, and scattered the received bytes with a raw memcpy to, the guest iovec bases. The iovec array itself is already checked, but a base such as 0x10 or a read-only page crashed the host. FreeBSD 11.4's kern_writev and kern_readv move the data with uiomove, so an unusable buffer fails with EFAULT (sosend and soreceive return the error from uiomove). GuestSockets::Writev now gathers with GuestCopyIn_nid_no_patch and GuestSockets::Readv scatters with GuestCopyOut_nid_no_patch, and each returns EFAULT (SCE_KERNEL_ERROR_EFAULT from the sce calls) when a copy fails. A writev whose gather fails sends nothing. A readv has already taken the bytes off the socket when the scatter fails, as in the kernel, where soreceive has dequeued the data when uiomove faults, so those bytes are lost. The null-base check, the length checks and the zero-length cases are unchanged. There is no debt entry because the errors follow the source.

Tested

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

  • guest_socket_read_write: new checks that sceKernelWritev and writev on a connected TCP socket fail with SCE_KERNEL_ERROR_EFAULT and EFAULT for a base of 0x10, that a vector with a usable first buffer and an unusable second one sends nothing (the peer is not readable), and that readv with a base of 0x10 fails with EFAULT after the 8 bytes sent beforehand (the socket is empty afterwards). With Socket/src/Udp.cpp reverted to main the test crashes (SegFault); with this change it passes, three runs out of three.
  • The other socket, UDP, TCP and vector I/O tests that build here (54 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 7088 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 11896 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12682 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestSocketReadWrite.cpp
PR 12688 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestSocketReadWrite.cpp
PR 12700 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestSocketReadWrite.cpp
PR 12965 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestSocketReadWrite.cpp
PR 17603 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 18167 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 18197 core/libs/prx/libkernel/Socket/src/Udp.cpp

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head fa596cd2ab, merged onto main f35f1e5eca (aeec0f2829, 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_read_write 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 fa596cd2ab, 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_read_write with --repeat until-fail:5: 5 / 5 pass.
  • Negative control, with main's Udp.cpp and this PR's test: 5 / 5 runs fail.

@adriadam10 adriadam10 self-assigned this Nov 12, 2026
…unusable buffer

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Gruzzberry
Gruzzberry force-pushed the fix/socket-readv-writev-efault branch from fa596cd to 6be7099 Compare November 12, 2026 17:46
@oneandonlydean
oneandonlydean merged commit 44ca50d into boykopovar:main Nov 12, 2026
14 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