fix(libkernel): check the send and recv buffers as sendto and recvfrom do #24382
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24382"
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 Dr-Coconut on 2026-11-20T15:30:42Z.
What
sendandrecvhanded the guest buffer to the host call without the checkssendtoandrecvfrommake, so an unreadable or unwritable buffer got whatever the host did, a gap the libkernel debt file records. FreeBSD 11.4's libc implements them assendtoandrecvfromwithout an address, so this gives them the same checks, reusing the helpers already inUdp.cpp:sendrejects a buffer that is not wholly readable withEFAULTthroughSourceFaults, assendto's connected path does. That also prepares guest memory for the host read, whichsendskipped.recvreceives only into the writable prefix (GuestPrefix), and fails withEFAULTwhen the pending data does not fit it (PendingFits), leaving stream data queued and dropping a datagram (DropDatagram), asrecvfromdoes.sendtoandrecvfrom. macOS is unchanged:recvfromdrops a faulted datagram there andrecvstill does not; I could not build or test macOS, so the debt fragment records that difference.The new
CheckSendReceiveFaultsinGuestUdp.cppmirrorsCheckPointerFaultsforsendandrecvon connected stream and datagram sockets: null, unmapped, unreadable, read-only and page-crossing buffers, a receive whose last writable byte takes a one-byte message, and a datagram that does not fit (dropped, the next one received). The debt fragment rewrites the entry to cover all four calls without the gap.Tested
Commit
2c7575b2eaonmain7fa48cd1c6, Release, in a workflow on my fork: https://github.com/Dr-Coconut/AnyPS5/actions/runs/44762193787windows-latest, WinLibs GCC 15.2.015.2.0posix-14.0.0-ucrt-r7), with the change:guest_udp,guest_tcp,guest_socket_pairandguest_kernel_socket_dontwaitpass.Udp.cpprestored tomainand the new test kept:guest_udpaborts (0xc0000409); the other three pass.main's ownguest_udppasses, so the abort is in the newCheckSendReceiveFaultscases.ubuntu-latest, image ubuntu-26.04, GCC 15.2.0), with the change: all four pass. The change does not alter Linux, so this shows the new cases hold there.Not run on macOS. No title tested.
tools/check_conventions.pyandtools/debt_fold.py --checkpass.tools/pr_overlap.py --branchmerged 25 open pull requests that share files with this branch and reported one conflict: #23341 changes the same two lines ofrecv(ReceiveShuttoReceiveEnded, andWSAEMSGSIZEfor type 5), as it does inrecvfrom, so whichever lands second keeps both. It could not compare six that conflict withmain; compared by hand, #8605 changesGuestSockets::Stat, and #11896, #12682, #12688, #12700 and #12965 restructurerecvwithout adding these checks, so they overlap textually only.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T15:38:17Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
2c7575b2ea:tools/check_conventions.pypassed.guest_udp_testsbuilt cleanly.guest_udp):core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T15:45:13Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
2c7575b2ea4aa42758afab92764912096e789aefusing the prepared diff andrepo_read.py. I did not run commands or tests. The description reports Windows and Linux test runs; these were not independently run. I readcore/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/tests/GuestUdp.cpp, anddocs/dev/debt/changes/fix-libkernel-send-recv-buffer-checks.md.Results
Findings
Blocking
None.
Non-blocking
MSG_WAITALLcan still produce a short success where FreeBSD would returnEFAULT(Udp.cpp:1981-1987). The debt entry accurately records this limitation.Not verified
To get this to a good state
Nothing is required. The optional stream receive edge case is documented in the debt entry.