fix(libkernel): check socket address arguments before the descriptor #8392
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8392"
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-20T12:03:52Z.
What
AddressLengthError(the length and null checks ofAddress(), i.e. FreeBSDgetsockaddr) now runs beforeLookup()inbind,connectandsendto(only when an address is given). Valid arguments on a closed descriptor still fail with EBADF; the family and short-AF_INET checks stay after the descriptor lookup.Fixes #8391
Follow-up to #8154 (socket address length).
setsockoptis not changed here; the pointer and length checks ofsetsockopt/getsockoptare in #7511.git merge-treeagainst the open socket PRs #7490, #7850, #7475 and #8312 is clean;pr_overlapwas not run.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on upstream/main
d50ec76da0+ this commit:guest_socket_address_lengthfails without the change toUdp.cpp(bind(-1)with a 1-byte address answers 9) and passes with it; 28 other socket and sceNet tests pass (29 of 29);python tools/check_conventions.py --base upstream/mainpasses. Not tested: Linux/macOS, a console, a title run.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T12:17:06Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/tests/GuestSocketAddressLength.cppL58, L70Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libkernel/Socket/src/Udp.cppImported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T12:43:36Z.
Overlap note: #7511 (validate the pointers of getsockopt and setsockopt like FreeBSD) adds the same null-value and negative-length checks for
setsockopt.git merge-treeof the two heads is clean, but thesetsockoptpart of this PR then repeats those checks; this PR only moves them in front of the descriptor lookup, which is whatkern_setsockoptdoes (uipc_syscalls.c:1414-1417). If #7511 lands first, I can rebase this to the descriptor-order change only. I should have listed #7511 in the description;pr_overlapwas not run before opening.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T14:26:18Z.
Thanks, the ordering matches FreeBSD's
getsockaddrbeforegetsock. One thing in the description: it sayssetsockoptnow rejects a null value with a non-zero length and a negative length before the descriptor, but the diff doesn't changesetsockopt, and it still looks the descriptor up first. Could you either drop that sentence or add the change with a test?Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T14:54:12Z.
Thanks, you are right: the diff changes only the address checks of
bind,connectandsendto;setsockoptstill looks the descriptor up first. Thesetsockoptsentence came from an earlier version of this change that I dropped because #7511 covers the pointer and length checks ofsetsockopt/getsockopt. I removed it from the description, the title and the linked issue. My earlier comment here about thesetsockoptpart overlapping #7511 was therefore also wrong: there is no overlap insetsockopt.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T03:40:15Z.
Linux data point for
ce8f7803ea(WSL2, Ubuntu 24.04, GCC 13.3, Release,-j4; a virtualised kernel, not bare-metal Linux): the socket and UDP tests pass on Linux (14 of 14). This replaces the "Linux not tested" line in the description for this head. Not tested: macOS.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T18:06:30Z.
Checked the order of
bind,connectandsendtoagainst FreeBSD 11.4 (getsockaddrbeforegetsock), the new test pins the length/null errors before EBADF and fails onmain, the family checks stay after the lookup, and Windows plus WSL2 runs are in the thread; merged.