fix(libkernel): fail getsockname and getpeername with EFAULT on an unusable pointer #11281
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11281"
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-10-25T23:40:10Z.
What
getsocknameandgetpeernamewrote the address and the length through the guest pointers directly, so an unreadable or unwritable one crashed the host instead of failing. FreeBSD 11.4'sgetsockname1andgetpeername1copy the length in first (copyin,EFAULT, ahead of the descriptor lookup and itsEBADF), look the socket up (ENOTCONNfor an unconnectedgetpeername), copy the address out only when its truncated length is not 0 (EFAULTfor an unwritable or null address), and copy the length out last (EFAULT). The calls now do the same with the newGuestCopyIn_nid_no_patch(the read counterpart ofGuestCopyOut_nid_no_patch) andGuestCopyOut_nid_no_patch. A null address with a zero length now succeeds, as on FreeBSD, where it used to fail withEFAULT; a null address with a non-zero length still fails withEFAULT. The results for readable pointers are otherwise unchanged.acceptis left alone (#7485 and #7507 cover its pointers).Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, on currentmain.guest_tcp: newSocketNameFaults, for both calls, an unreadable and a null length (EFAULT, also with the descriptor -1, which pins the order againstEBADF), the descriptor -1 with readable pointers (EBADF), an unreadable, a null and a read-only address with the length left unchanged (EFAULT), a length on a read-only page after the address was written (EFAULT), a null or unreadable address with a zero length (success, length 0), and a readable call (16 bytes); plus an unconnected socket (ENOTCONN, andEFAULTfor an unreadable length ahead of it). Onmainthe test segfaults; with this change it passes, three runs out of three.pr_overlap_encoding,agc_host_import_cut_lifetime,agc_driver_depth_plane_partial_store).guest_selectpassed in that full run but now fails on this machine at line 143 (20 selects of 1 ms must take under 200 ms), as it does in other branches of mine that do not touch sockets: the host timer resolution, not this change.python tools/check_conventions.py --base upstream/main: passes.Overlaps
GuestCopyIn_nid_no_patchdeclaration and definition, line for line: proposed on it that it goes first and this PR rebases (the duplicate then drops out).sysctl) and #11273 (signal calls), both mine, add the sameGuestCopyIn_nid_no_patchlines: they were opened first, so they go first and the duplicate drops out when this PR rebases.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 MarcZX10 on 2026-10-25T23:41:49Z.
Review: CHANGES_REQUESTED
The Overlaps section says this PR must follow #10975, #11264 and #11273 because they add the same
GuestCopyIn_nid_no_patchhelper, but its checklist saysDepends on: noneand then lists those PRs only after a semicolon.CONTRIBUTING.mdexpects the prerequisites on the checklist line. Please setDepends on: #10975, #11264, #11273(plus any other actual prerequisites) or revise the stated order if it is not required. I have not compared or reused code from any of those branches.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:45:15Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
09746b556e6fca208357b1cb60c397a5e06125a8. The checklist still saysDepends on: nonewhile Overlaps states this must follow #10975, #11264 and #11273; please put the actual prerequisites on that checklist line. I also found a behavior mismatch inGuestAddress()/CopyAddressOut():GuestAddress()writes the copied byte count into*length, and that value is returned to the guest. The PR cites FreeBSD 11.4, where the truncated length is used for copying the address, then the full sockaddr length is returned. Therefore capacity 0 should succeed with required length 16 for IPv4 (28 for IPv6), and a short buffer should still report the full required length. The current tests expect 0; please preserve capacity separately, return required length, and add zero/short-buffer assertions. Hosted eligibility, conventions, intake, labels and report checks pass; ASan and Ubuntu relinker pass, with Windows/macOS jobs pending. The focused Windows run is author-reported.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T00:05:42Z.
Review: APPROVED
Correction to my earlier review: my zero/short-buffer finding was wrong. I checked FreeBSD 11.4's
kern_getsocknameandkern_getpeernameimplementations directly: both set*alen = MIN(*alen, (*sa)->sa_len), and the syscall copies that truncated length back. The PR's zero-capacity expectation is therefore consistent with the cited 11.4 behavior. Thanks for pointing me to the correct kernel path. The dependency checklist is also now consistent with the overlap section.I re-reviewed exact head
09746b556e6fca208357b1cb60c397a5e06125a8. The new wrapper copies the input length before descriptor lookup, uses that capacity to bound the address copy, and writes back the truncated length last; the tests cover the pointer faults and error ordering described. Current hosted conventions, intake, eligibility, labels, relinker, ASan, register-context, and write-watch checks pass; product Linux/Windows jobs are skipped by path policy. The focused Windowsguest_tcprun is author-reported, not independently reproduced here. I found no remaining blocker and approve this head.