libkernel: setsockopt/getsockopt with an unknown level fails with ENOPROTOOPT where FreeBSD 11.4 fails with EINVAL #8447

Closed
opened 2026-10-20 12:46:54 +00:00 by xXPBSXx · 0 comments
xXPBSXx commented 2026-10-20 12:46:54 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T12:46:54Z.


Repro

Any host. s = socket(AF_INET, SOCK_STREAM, 0), then setsockopt(s, 999, 1, &one, 4) or getsockopt(s, 999, 1, &v, &len).
Expected (FreeBSD 11.4): EINVAL (22). sosetopt/sogetopt pass a level other than SOL_SOCKET to the protocol; tcp_ctloutput forwards a level other than IPPROTO_TCP to ip_ctloutput (sys/netinet/ip_output.c:943-944), which answers EINVAL for every level but IPPROTO_IP. The same holds for ip6_ctloutput (sys/netinet6/ip6_output.c:1459) on an AF_INET6 socket and for uipc_ctloutput (sys/kern/uipc_usrreq.c:1228-1229) on an AF_UNIX socket.
Actual: ENOPROTOOPT (42), from if (level != 0xffff && level != 6 && level != 41) return Fail(42) in setsockopt_nid_postfix and getsockopt_nid_postfix.
Test: core/libs/tests/GuestSocketOptions.cpp (new case UnknownLevelsFollowFreeBsd; fails with errno 42 before the fix).
Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/sockopt-unknown-level-einval
AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5941889655 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8447). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T12:46:54Z. --- ### Repro Any host. `s = socket(AF_INET, SOCK_STREAM, 0)`, then `setsockopt(s, 999, 1, &one, 4)` or `getsockopt(s, 999, 1, &v, &len)`. Expected (FreeBSD 11.4): EINVAL (22). `sosetopt`/`sogetopt` pass a level other than SOL_SOCKET to the protocol; `tcp_ctloutput` forwards a level other than IPPROTO_TCP to `ip_ctloutput` (sys/netinet/ip_output.c:943-944), which answers `EINVAL` for every level but IPPROTO_IP. The same holds for `ip6_ctloutput` (sys/netinet6/ip6_output.c:1459) on an AF_INET6 socket and for `uipc_ctloutput` (sys/kern/uipc_usrreq.c:1228-1229) on an AF_UNIX socket. Actual: ENOPROTOOPT (42), from `if (level != 0xffff && level != 6 && level != 41) return Fail(42)` in `setsockopt_nid_postfix` and `getsockopt_nid_postfix`. Test: `core/libs/tests/GuestSocketOptions.cpp` (new case `UnknownLevelsFollowFreeBsd`; fails with errno 42 before the fix). Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/sockopt-unknown-level-einval AI-assisted (Claude Code).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#8447
No description provided.