fix(libkernel): fail readv and writev on a socket with EFAULT for an unusable buffer #17248
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17248"
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:10:01Z.
What
readvandwritev(andsceKernelReadv,sceKernelWritev) on a guest socket gathered the caller's buffers with a rawmemcpyfrom, and scattered the received bytes with a rawmemcpyto, the guestiovecbases. The iovec array itself is already checked, but a base such as0x10or a read-only page crashed the host. FreeBSD 11.4'skern_writevandkern_readvmove the data withuiomove, so an unusable buffer fails withEFAULT(sosendandsoreceivereturn the error fromuiomove).GuestSockets::Writevnow gathers withGuestCopyIn_nid_no_patchandGuestSockets::Readvscatters withGuestCopyOut_nid_no_patch, and each returnsEFAULT(SCE_KERNEL_ERROR_EFAULTfrom thescecalls) when a copy fails. Awritevwhose gather fails sends nothing. Areadvhas already taken the bytes off the socket when the scatter fails, as in the kernel, wheresoreceivehas dequeued the data whenuiomovefaults, 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, onmainf5fe807353.guest_socket_read_write: new checks thatsceKernelWritevandwritevon a connected TCP socket fail withSCE_KERNEL_ERROR_EFAULTandEFAULTfor a base of0x10, that a vector with a usable first buffer and an unusable second one sends nothing (the peer is not readable), and thatreadvwith a base of0x10fails withEFAULTafter the 8 bytes sent beforehand (the socket is empty afterwards). WithSocket/src/Udp.cppreverted tomainthe test crashes (SegFault); with this change it passes, three runs out of three.python tools/check_conventions.py --base upstream/main: passes.Overlaps
cancel blocked POSIX writes with partial progress) and #12965 (support deferred cancellation in POSIX accept) replace the block aroundGuestSocketReadGuest_nid_no_patch,GuestSockets::Read,Write,ReadvandWritevinSocket/src/Udp.cpp, where this PR changes two lines each inReadvandWritev. Both already conflict withmain, sopr_overlap.pydid not compare them. This PR goes first and they rebase onto it (two lines); asked on both.Udp.cppandGuestSocketReadWrite.cpp, in other functions (SendError,WaitForTransfer,sendandrecv, socket state) and not inReadvorWritev; #11896, #15785, #16826, #7088 and #5021 touchUdp.cppelsewhere.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-08T23:41:17Z.
Review: COMMENTED
Windows run of head
fa596cd2ab, 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_read_writewith--repeat until-fail:5: 5 / 5 pass.main'sUdp.cppand this PR's test: 5 / 5 runs fail.