fix(libkernel): fail sendmsg control data in unreadable guest memory with EFAULT #14970
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14970"
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-11-02T06:24:41Z.
What
sendmsgon anAF_UNIXsocket reads the control data (SCM_RIGHTS) inPassedDescriptorsstraight from guest memory withmemcpy, so amsg_controlpointer into unmapped or inaccessible memory crashed the host.SendPassingnow checks the length and copies the buffer with the checkedReadGuestthatrecvmsguses, and fails as FreeBSD 11.4 does inkern_senditandsockargs:EINVALwhenmsg_controllenis belowsizeof(struct cmsghdr)(12: three 4-byte members,socket.hL457-L462) or aboveMCLBYTES(2048,param.hL171-L174), andEFAULTwhen the copy fails. AcontrolLengthabove 2048 now fails withEINVAL, assockargsdoes in FreeBSD 11.4 (MCLBYTES); before, this path accepted larger lengths. The existingguest_socket_rightstest, which passes descriptors, still passes. The newguest_sendmsg_controltest, registered outside Windows only, covers an unmapped pointer, an inaccessible page, a buffer that runs into one, and the lengths 8, 11 and 2049.Depends on: #8463 (landing order only; same function). No console run has checked these results.
Tested
Linux (WSL, Ubuntu 24.04, GCC 13.3), 05:51 UTC to 05:52 UTC on 2026-11-02, on
main926f7dd492b0plus this commit: the build exits 0 andguest_sendmsg_control,guest_socket_pair,guest_recvmsg_memoryandguest_socket_rightspass in 3 of 3 runs. WithUdp.cpptaken frommainand the test kept (rebuilt, exit 0),guest_sendmsg_controlcrashes with a segmentation fault in 3 of 3 runs while the other three pass; with the file restored they pass again in 3 of 3 runs.python tools/check_conventions.py --base 926f7dd492b0passes on this head, and the head merges withmain4569fe654awithout a conflict (checked 2026-11-02 06:22 UTC). Not run: Windows (the test is not registered there, andsendmsgwith control data throws there), macOS, a console, a title.Overlap
Checked on 2026-11-02 against
main926f7dd492b0b432d9287f4d6faaaf1c9d3c86c5(1898 open pull requests, listed at 04:56 UTC; the merge checks ran from 04:56 UTC to 05:38 UTC, and again for this head from 05:50 UTC to 05:53 UTC). I took the changed files of each fromgit diff --name-onlyagainst its merge base (one ref, #13454, could not be fetched; the GitHub file list shows it changes none of the three files). 86 of them change at least one ofSocket/src/Udp.cpp,tests/GuestSocketPair.cppandlibkernel/CMakeLists.txt.git merge-treeof this head with each of the 86: 21 conflict, and 20 of those also conflict withmainon their own. The remaining one is #8463, which changes the same function; hence theDepends on. I placed the new test function beforeCheckReceiveMessageFaultsbecause directly after it, it conflicted with #14043. None of the 9 pull requests opened since that list (#14959 to #14969, listed at 06:23 UTC) changes one of the three files.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T10:37:00Z.
Review: APPROVED
Looks right to me. I checked it against the cited FreeBSD 11.4 source.
sendit(uipc_syscalls.catrelease/11.4.0), a non-nullmsg_controlwithmsg_controllen < sizeof(struct cmsghdr)isEINVALbefore any copy.sockargsthen fails withEINVALaboveMCLBYTESand withEFAULTwhen thecopyinfails.SendPassingnow does the same in that order, and copies the control buffer once with the checkedReadGuestbeforePassedDescriptorsparses it. Only the copy is parsed, so the parser's rawmemcpys no longer touch guest memory.PROT_NONEpage and a buffer running into one forEFAULT, and lengths 8, 11 and 2049 forEINVAL. The 8-byte case with an unmapped pointer shows the length check comes before the copy, as insendit.ReadGuestbuilds on Linux. It is defined outside any platform guard further down, so the forward declaration links there, andSendPassingitself sits in the non-Windows block.Non-blocking, and older than this PR: FreeBSD enters the control path whenever
msg_controlis non-null, so a non-null pointer withmsg_controllen == 0isEINVALthere.sendmsg_nid_postfixrequires both to be set, so that call still goes throughsendtohere. It could be a follow-up or a debt line.I couldn't run the new test, which is registered outside Windows only, and this machine has no Linux. This review is from reading the code and the FreeBSD source, plus your Linux runs and their negative control.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T19:51:43Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the stated behavior is implemented and the supplied Linux checks report passing results.
What I ran
Reviewed head
b1b9e36f94ad29f81367636dac53ccbfd6e0e584using the prepared diff and repository reader. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full repository files and tests were not executed.
files.jsonwas unavailable; the manifest identifies three changed files, all included and read. No files were excluded by the manifest.To get this to a good state
Nothing is required.