fix(libkernel): validate the pointers of getsockopt and setsockopt like FreeBSD #7511
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7511"
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-18T10:30:19Z.
What
setsockoptandgetsockopton a libkernel socket now validate their pointers in the order FreeBSD 11.4 does:setsockoptwith a null value and a non-zero length fails withEFAULTbefore the descriptor is checked, and a length aboveINT32_MAXwithEINVAL(kern_setsockopt).getsockoptwith a value but no length pointer fails withEFAULTbefore the descriptor is checked (sys_getsockopt). With no value it reads a zero length, returns the option's own errors first (EBADF,ENOPROTOOPT), then fails withEFAULTon the final copyout. A null value with a length pointer succeeds and writes a zero length.EINVALwhere FreeBSD givesEFAULTis updated.Tested
Windows 11, WinLibs GCC 15.2.0 UCRT, Release. New
NullPointersFollowFreeBsdinGuestSocketOptions.cpp(fails onmain, passes here), the socket/udp/sce_net tests, and the full non-GPU suite (758/758, rebuilt on currentmain9caecfd2d).python tools/check_conventions.py --base origin/mainpasses. Linux and macOS were not run here; the change uses no host call that differs per platform.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T12:20:00Z.
Tested on Windows 11 (MinGW GCC 15.2) and Ubuntu 24.04 (GCC 13.3), both with this PR merged onto
main9f25d0bf5.guest_socket_optionswith the newNullPointersFollowFreeBsdfails onmain'sUdp.cppand passes with this PR on both. The socket/sce_net/equeue set passes (Windows 38/38, Linux 26/26).Two places still differ from the order the description cites (release/11.4.0). Probes at this PR's head:
kern_getsockoptrejects a negative*valsizewithEINVAL(uipc_syscalls.c:1495-1498) beforegetsock_cap(L1517) and before the protocol sees the level. Here the check runs afterLookupand after the level check:getsockopt(-1, SOL_SOCKET, SO_KEEPALIVE, &v, &len=0xffffffff)gives errno 9; FreeBSD gives 22.getsockopt(tcp, 0 /*IPPROTO_IP*/, 1, &v, &len=0xffffffff)gives errno 42; FreeBSD gives 22.Moving
availableand its< 0check aboveLookup(value && lengthis already guaranteed there) would match.The two new
setsockoptchecks sit below theKernelSetSocketOption_nid_no_patchbridge. So for a socket fromsceNetSocket,setsockopt_nid_postfix(net, SOL_SOCKET, SO_KEEPALIVE, nullptr, 4)still returns -1 with errno 22, wherekern_setsockoptreturnsEFAULTbefore the descriptor is looked up (L1414-L1415,getsock_capat L1436). The updated debt sentence states the EFAULT-first order without that exception. Moving the two lines above the bridge call would cover it.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by Bonjourcestmatt on 2026-10-19T06:38:30Z.
Thanks for the probes. Both differences are real and now fixed in
3ad71a4ed:getsockoptrejects a negative*valsizewithEINVALbefore the descriptor lookup and before the level check (kern_getsockopt:if ((int)*valsize < 0) return (EINVAL);runs beforegetsock_cap), so the check moved aboveLookup.getsockopt(-1, SOL_SOCKET, SO_KEEPALIVE, &v, &len=0xffffffff)andgetsockopt(tcp, 0, 1, &v, &len=0xffffffff)now give 22.setsockopt's two checks (val == NULL && valsize != 0then(int)valsize < 0) moved above theKernelSetSocketOption_nid_no_patchbridge, so asceNetSocketdescriptor getsEFAULTandEINVALfirst as well.New checks: the two
getsockoptcases inGuestSocketOptions.cpp, and the twosetsockoptcases on asceNetSocketdescriptor inGuestSceNet.cpp(which already linkslibSceNet). With the oldUdp.cppbothguest_socket_optionsandguest_sce_netabort; with the change they pass.Windows 11, MinGW-w64 GCC 15.2.0 UCRT, head merged onto
mainb44d0127d: the full non-GPU suite builds and the socket, UDP, TCP, poll and select tests pass (31/31). Not run on Linux or macOS.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T07:44:46Z.
Re-tested
3ad71a4edmerged ontomainc1ca83479on Windows 11 (MinGW GCC 15.2) and Ubuntu 24.04 (GCC 13.3).The three probes now give the FreeBSD 11.4 errnos on both platforms:
getsockopt(-1, SOL_SOCKET, SO_KEEPALIVE, &v, &len=0xffffffff)gives 22.getsockopt(tcp, 0, 1, &v, &len=0xffffffff)gives 22.setsockopt(<sceNetSocket fd>, SOL_SOCKET, SO_KEEPALIVE, nullptr, 4)gives 14.On
mainthey give 9, 42 and 22. A plain socket still gets 14, and a validsetsockopt(SO_REUSEADDR,SO_RCVTIMEO) on a sceNetSocket descriptor still returns 0.guest_socket_optionsandguest_sce_netabort withmain'sUdp.cppand with theUdp.cppfrom58371fb8e, and pass with this one.The socket/udp/tcp/poll/select/equeue/sce_net set passes: Windows 54/54, Linux 40/40.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by Bonjourcestmatt on 2026-10-19T09:04:21Z.
Merged current
origin/maininto the branch to resolve the conflict (no textual conflicts, only the merge). Rebuiltguest_socket_options_testsandguest_sce_net_testson Windows (WinLibs GCC 15.2 UCRT): both pass;check_conventions.py --base origin/mainpasses. Linux/macOS were not run.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Bonjourcestmatt on 2026-10-19T09:24:15Z.
Merged
origin/mainagain (conflict with the newIPV6_V6ONLYhandling ingetsockopt/setsockoptand the debt entry). Rebuilt on Windows (WinLibs GCC 15.2 UCRT):guest_socket_optionsandguest_sce_netpass,check_conventionspasses. Linux and macOS did not run here.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T09:41:19Z.
Rebase handoff for the 71-commit getsockopt-null-pointers series — rebased onto current
main(all commits, authorship unchanged). This was a long series with main-merges; the notable resolutions:getsockoptpointer validation (the null-length and negative-available guards) merged with theIPV6_V6ONLYlevel-41 branch — main's available-length form kept with your null checks before itmain's 2x2-gridRequire— I initially keptmain's Require (wrong direction) and corrected it: the fallback replaces the Require, withmain's(state.samples > 1 || state.customSampleLocations)enabled condition preserved, and the grid rejection expectation replaced by your fallback acceptanceatomic || fmask → Uintmerged ahead ofmain'snativeRepacked → FloatclauseSetAddressCopyLimitdeclarations unioned throughoutVerified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
30afd0f91.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T00:40:20Z.
@Bonjourcestmatt a merge-order note: #9515 adds a call at the start of
getsockopt_nid_postfixthat hands a descriptor libkernel doesn't own to the option getter libSceNet registers, at the spot where this PR adds its pointer and length checks. This one goes first: #9515 lists it under Depends on and, when it rebases, puts its call after your two checks, so a libSceNet socket fails a bad pointer or length the same way.Pull request closed