fix(libkernel): fail sendmsg with EFAULT on guest memory it cannot read #8463
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8463"
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 xXPBSXx on 2026-10-20T13:03:46Z.
What
sendmsg_nid_postfix(Udp.cpp) read the message header, the iovec array, the buffers and the address from guest memory without a check, so a pointer into unmapped or inaccessible memory crashed the host. It now copies each of them with the checkedReadGuestthatrecvmsguses (#7675) and fails withEFAULT, ascopyindoes insys_sendmsg,copyiniov,getsockaddranduiomove. The descriptor is looked up after the header, the iovec array and the address are read and before the buffers, which is the order ofsenditandkern_sendit. The vector count and length checks ofMessageLengthrun on the copy.The branch is 3 commits: the fix
5e88a2bdcf33and two merges ofmain(f4b87cbb57fb,a84f4c3dc4a5). The last merge brings inmain3aa0ac20df30with one conflict, inGuestSocketPair.cpp, wheremainand this PR each added a function at the same place; both are kept and nothing of the PR changed. Againstmainthe PR is still 3 files, +81 -9, the same added and removed lines as before the merge.Fixes #8462
Overlap (P2, 2026-11-08, list of open pull requests from 04:42 UTC,
main62e7ca8676, checked 04:42-04:48 UTC, heada84f4c3dc4a5): of the 59 open pull requests that changecore/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/prx/libkernel/CMakeLists.txtorcore/libs/tests/GuestSocketPair.cpp, each was merged with and without this branch. Three conflict only with this branch: #14970 (ours,Depends on: #8463, same insertion point inGuestSocketPair.cpp), and #12965 and #12700 (accept and write cancellation, which also changeUdp.cpp); whichever lands second rebases. 17 conflict withmainwithout this branch as well; the other 39 merge cleanly with and without it. The head of #8448 (58a3e046e80f) merges cleanly with this branch, and both heads merge cleanly withmain8eb293447e.Tested
Ubuntu 24.04 on WSL2 (Linux 6.18.54.1, AMD Ryzen 7 5800X3D), GCC 13.3.0, Release with
BUILD_TESTING=ON, at heada84f4c3dc4a5on 2026-11-08 at 03:13 UTC, one run of each:guest_socket_pair,guest_recvmsg_memoryandguest_sendmsg_memorypass.net_dontwait_blocking_send,_sendto,_sendmsg) did not run because their executable was not built; built and rerun at 03:14 UTC, all 11net_dontwaitcases pass.python tools/check_conventions.py --base upstream/mainatmain3aa0ac20df30: passes.maincf528e78c6+ the fix commit):guest_sendmsg_memory(new, registered in CMake) crashes with 0xc0000005 without the change toUdp.cpp(reverted tomain, test kept, fresh build; 3 of 3 runs) and passes with it (3 of 3 runs);guest_socket_pairandguest_recvmsg_memorypass with and without it (3 of 3 runs each). The test covers a header, an iovec array, an iovec base (also as the second vector) and a name on an unmapped address and on an inaccessible page,EBADFfor a bad descriptor with unreadable buffers, nothing queued after the failures, and a send from a read-only page.64b5aa11f4(the later heads only rename the iovec and msghdr types), others measured: Filip722 on Debian 13.7 (Linux 7.2.9, AMD Ryzen 5 7640HS, GCC 15.2.0): ten socket cases pass 3 of 3 each, andguest_sendmsg_memorysegfaults withUdp.cppof the merge base; jotitadev on macOS 27.2 (Apple M2 Max, x86_64 under Rosetta 2, on #8658):guest_sendmsg_memorysegfaults without theUdp.cppchange and passes 3 of 3 with it, the same ten cases pass.Checklist
main; no other open PR implements the same checks (#14970 adds the control-data check and depends on this PR).mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T06:34:26Z.
Review: APPROVED
The copied header, vector array, name and payload data now go through the same checked
ReadGuestpath as receive-side guest memory handling. I checked the length/error path and independently ran Linux C++ syntax compilation ofUdp.cppon this head; conventions and whitespace checks pass. The reported runtime regression covers unreadable ranges on Windows. I did not run the socket test binary on Linux in this workspace.Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-21T09:56:09Z.
Full-project Linux runtime follow-up at exact head
64b5aa11f440addaff35ebb748907bae427b6666: the new regression prevents a reproducible Linux host segfault.guest_sendmsg_memory,guest_recvmsg_memory,guest_socket_pair,guest_poll,guest_tcp,guest_udp,guest_select,guest_select_wait,guest_socket_error, andguest_socket_descriptors.EFAULT; the existing queue-empty and read-only-send checks still pass. This extension passed 3/3. A syscall trace also confirms realprocess_vm_readvpartial reads on these cases, not only wholly unreadable ranges.Udp.cppwith merge-base44e3389c882c8ee3249e16933aad6479c3e00d08, and rebuilt libkernel.guest_sendmsg_memoryfails with SEGFAULT (CTest exit 8). Restoring the PR source and rebuilding makes it pass again.Environment: Debian 13.7 x86-64, Linux
7.2.9-x64v3-xanmod1, AMD Ryzen 5 7640HS, GCC 15.2.0, CMake 3.31.6. Full Release configuration withBUILD_TESTING=ON,ANYPS5_RELINKER_ONLY=OFF, bundled dependencies; built libkernel, selected test executables and dependencies with two jobs.Tracked source restored to the named head. No new Windows/macOS, title, PS5 hardware, GPU or full repository test-suite run. This adds runtime coverage beyond the earlier Linux syntax check.
AI-assisted testing and report.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T04:27:28Z.
Review: COMMENTED
macOS run of the
mach_vm_read_overwritepath, which the description lists as not tested.feat/macos-port) @81490845d2(main does not build the runtime on macOS yet), plus this PR's diff @ 64b5aa11f4 (applies cleanly).guest_sendmsg_memoryUdp.cppchangeSegFault(host crash)With the change, the same ten cases Filip722 ran on Linux pass on macOS (
guest_sendmsg_memory,guest_recvmsg_memory,guest_socket_pair,guest_poll,guest_tcp,guest_udp,guest_select,guest_select_wait,guest_socket_error,guest_socket_descriptors: 10/10). So the checked read givesEFAULTon all three hosts.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.