fix(libkernel): return EFAULT from getsockname and getpeername without a length pointer #7502
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7502"
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 Bonjourcestmatt on 2026-10-18T09:50:18Z.
What
getsocknameandgetpeernamewith a NULL length pointer now fail withEFAULT(14) before the descriptor is looked up, so an invalid descriptor with a NULL length reportsEFAULTinstead ofEBADF. FreeBSD 11.4 (sys/kern/uipc_syscalls.c, release/11.4.0):getsockname1()andgetpeername1()start witherror = copyin(uap->alen, &len, sizeof(len));and only then callkern_getsockname()/kern_getpeername(), wheregetsock_cap()rejects a bad descriptor. A NULL address with a valid length pointer still fails withEFAULTafter the lookup, so an invalid descriptor there still givesEBADF.Overlap: no open PR changes
getsockname_nid_postfixorgetpeername_nid_postfix(checked the diffs of the open PRs listed bytools/pr_overlap.py; #6884 and #7090 only call them in tests/other code).Tested
guest_socket_descriptors_testshas a newAddressQueryErrorscase (EFAULT with a NULL length on a valid and on an invalid descriptor, EBADF with a valid length on an invalid descriptor) and passes; full non-GPU suite 757 of 758, the one failure (patched_libraries) passed on two reruns alone, so it is flaky under the parallel run;python tools/check_conventions.py --base origin/mainpasses.mainwithout the fix; the invalid-descriptor checks fail there by reading the old code (the lookup came first and returned 9).Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryAI-assisted: yes
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T12:20:05Z.
Ran the negative control on Windows 11 (MinGW GCC 15.2) and Ubuntu 24.04 (GCC 13.3), with this PR merged onto
main9f25d0bf5. With onlyGuestSocketDescriptors.cppfrom this PR,guest_socket_descriptorsaborts onmainon both. With the PR it passes, and the socket/sce_net set passes (Windows 38/38, Linux 26/26).Two neighbouring cases in the same lines still differ from release/11.4.0. They predate this PR. I mention them because the description says a NULL address with a valid length "still fails with EFAULT after the lookup", and that only holds for a non-zero length on a connected socket. Probes at this head:
getsockname(fd, NULL, &len)withlen == 0gives -1/EFAULT. FreeBSD skips the copyout when the length is 0 (L1554) and returns 0.getpeernameon an unconnected TCP socket with a NULL address andlen = 16gives EFAULT. FreeBSD returnsENOTCONNfromkern_getpeername(L1683) before any copyout. With a real buffer this PR already gives 57.AI-assisted: yes (Claude Code); results above were run on this machine.
Pull request closed