fix(libkernel): fail SO_ACCEPTFILTER with EINVAL on a socket that is not listening #11006
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11006"
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 harisibrar1 on 2026-10-25T14:04:20Z.
What
setsockoptandgetsockoptofSO_ACCEPTFILTER(0x1000) on a socket that is not listening fail withENOPROTOOPT(42), where the console fails them withEINVAL(22).@orezraey measured this on a PS5 (firmware 13.60, payload process, non-listening TCP socket,
pinet4.log):#10330 recorded it as a remaining difference ("which AnyPS5 still answers with
ENOPROTOOPT"), and the getsockopt/setsockopt debt entry says the same. FreeBSD 11.4 agrees:do_getopt_accept_filteranddo_setopt_accept_filterreturnEINVALwhenSO_ACCEPTCONNis not set (uipc_accf.c, L206-L208, L264-L266).In
SocketOptions.cpp,SetSocketLevelOptionandGetSocketLevelOptionnow check option 0x1000 first:NativeListening), they returnErrorInvalid, and the output buffer is not written.NotImplemented_nid_no_patch. That case wasn't measured, and accept filters aren't modelled.The debt entry is updated to match.
Tested
Windows 11, WinLibs GCC 15.2.0 r7, full Release build on main
4017310678with this change: no failed steps.guest_socket_options,guest_socket_options_multicast,guest_socket_stream_options,guest_udp,guest_socket_descriptorsandguest_sce_netpass, 3 runs of 6/6.GuestSocketOptions.cpp: on a non-listening TCP socket, setting 5 or 0 fails withEINVAL, and a get fails withEINVALand leaves the 8-byte output untouched, as in the log.SocketOptions.cpp,guest_socket_optionsfails (2 runs).tools/check_conventions.py --base origin/mainpasses.NativeListeningalready has a path for each.Overlap
pr_overlaponly lists #7201 forSocketOptions.cpp; it conflicts with main and doesn't touch these functions. The debt-file rows are other entries.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 MarcZX10 on 2026-10-25T14:06:41Z.
Review: APPROVED
Reviewed the firmware 13.60 trace and the FreeBSD 11.4 behavior cited here. The non-listening set/get paths return EINVAL before mutating the output buffer, and the regression covers both accepted set values (0 and 5) plus the untouched get sentinel. The existing NativeListening helper uses getsockopt(SO_ACCEPTCONN) on Windows/Linux and proc_pidfdinfo on macOS, so the check follows the platform-specific listener detection already used by SO_ACCEPTCONN. The added code also preserves the explicit unimplemented path for listening sockets, which the trace does not cover. I verified the diff is clean and the changed translation units pass C++20 syntax checks locally. Windows runtime/build evidence is included in the PR; Linux and macOS product runtime tests remain unrun.
Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T15:31:17Z.
Review: COMMENTED
Reviewed head
e829b5con base4017310(current maind2b3ee3has no changes to these files). Linux: WSL2 Ubuntu 24.04, GCC 13.3, Release.What I ran:
guest_socket_optionsaborts early on my box at the refused-connectSO_ERRORcheck (a known WSL networking issue here, it fails on main too), so it never reaches your new case. I ran a local copy ofGuestSocketOptions.cppwith onlyReportsAndClearsTheConnectError()removed: passes 3/3 on this head. With main'sSocketOptions.cppit fails at "SO_ACCEPTFILTER on a socket that is not listening must fail with EINVAL (22) (errno 42)".setsockopt_nid_postfix/getsockopt_nid_postfix. On non-listening TCP and UDP sockets: int 5, int 0, NULL with length 0, a 256-byteaccept_filter_arg, and 8- and 256-byte gets all give EINVAL, and the get buffers stay untouched. On a listening TCP socket every case throws your NotImplemented.So the non-listening fix works on Linux for what the trace covers. One thing on the set path:
FreeBSD 11.4 doesn't check listening first when the value is non-NULL.
do_setopt_accept_filterrunssooptcopyin(sopt, afap, sizeof *afap, sizeof *afap)first (uipc_accf.c L232;sooptcopyinreturns EINVAL when the length is under minlen, uipc_socket.c L2474-L2475). Thenaccept_filt_getreturns ENOENT for a name that isn't registered (L239-L243), and only then comes theSO_ACCEPTCONNcheck (L264-L268). The trace sets 4-byte ints, so it fails at the size check and can't tell the two apart.Example: a 256-byte
{af_name = "bogus"}set on a non-listening socket is ENOENT on FreeBSD 11.4 and EINVAL here. Same for"dataready"if the console doesn't register accf_data, and we don't know which filters it has.Suggestion: keep EINVAL for a NULL value and for a length under 256 (FreeBSD and the trace agree there), and throw for a full-size value until someone measures it. The debt line would match then too; right now it says the set behaves as
do_setopt_accept_filterdoes, which only holds for those two cases.Optional, since you chose to throw on listening sockets: FreeBSD has exact answers for some of those. A get with no filter attached is EINVAL (L178-L181), and nothing here can attach one. A NULL set is 0 (the delete path, L204-L223), and a short set is EINVAL from the size check. Fine as a follow-up.
Limits: Linux only, no console. The PS5 kernel could differ from FreeBSD here; all of the above comes from the source, not a measurement.