Repository navigation
fix(libkernel): fail an unhandled ioctl on a local or AF_INET6 socket with EOPNOTSUPP, as tcgetattr and FreeBSD 11.4's pru_control do - #28285
Conversation
… with EOPNOTSUPP, as tcgetattr and FreeBSD 11.4's pru_control do A request that FreeBSD's soo_ioctl hands to pru_control gave ENOTTY on a local socket and EADDRNOTAVAIL on an AF_INET6 socket. tcgetattr, which is the same ioctl on the console, was measured to give EOPNOTSUPP on a local socket pair (firmware 11.60), and the tc* exports already answer that. AF_INET keeps EADDRNOTAVAIL and groups i, r and f keep ENOTTY. The requests FreeBSD answers before that point keep their results: SIOCATMARK, SIOCSPGRP and SIOCGPGRP, and on AF_INET6 group u 106 to 109. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 8f9c4ba64c:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_kernel_fcntl_tests,guest_kernel_sys_testsbuilt cleanly. - CTest (
guest_kernel_sys,guest_kernel_fcntl):1/2 Test #6830: guest_kernel_fcntl ............... Passed 0.01 sec 2/2 Test #1050: guest_kernel_sys ................. Passed 0.07 sec 100% tests passed, 0 tests failed out of 2 - Negative control: with
core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/2 Test #6830: guest_kernel_fcntl ...............Subprocess aborted***Exception: 0.14 sec 2/2 Test #1050: guest_kernel_sys .................Subprocess aborted***Exception: 0.20 sec 0% tests passed, 2 tests failed out of 2 - Code reading:
- Verified ioctl_nid_postfix command variable usage in Udp.cpp:2679: command is in scope from line 2650 (const auto command = static_caststd::uint32_t(request)) and accurately reflects request's lower 32 bits
- Verified AnsweredBeforeInterfaceCheck covers socket-level ioctls (0x40047307, 0x80047308, 0x40047309: SIOCATMARK, SIOCSPGRP, SIOCGPGRP) and AF_INET6-specific control requests (0xc050756a - 0x8048756d) before rejecting with EADDRNOTAVAIL or ENOTTY
- Verified error code returns: ENOTTY (25) for groups 'i', 'r', 'f', EADDRNOTAVAIL (49) for AF_INET/handled commands, and EOPNOTSUPP (45) for unhandled protocol requests on local/AF_INET6 sockets per FreeBSD 11.4 behavior
- Verified AGENTS.md debt fragments: docs/dev/debt/changes/ entries are correctly formatted and accurately record the error code changes without comments in code
- Verified test coverage in GuestKernelFcntl.cpp and GuestKernelSys.cpp properly verifies tcgetattr, tcsetsid, interface flags, socket state, and protocol control requests across local and IPv6 socket descriptors
Looks Good To Me
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The reviewed change at 8f9c4ba64cbb9a45e6f631c9aad0c46f460270e3 has no verified blocking defects; the author-reported checks are not runs performed in this review.
What I ran
No commands or tests were run. I read the prepared diff and manifest, all changed lines in the six changed files, the relevant ioctl validation helper, and the review README. The review bundle excludes no changed files; no full repository files were listed as excluded.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed lines | passed | All changed lines read |
| Targeted source context | passed | Validation and test context read |
| Tests | not run | Only author-reported results available |
| Console behavior | not run | AF_INET6 behavior is inferred |
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build or tests were run. Windows, macOS, and console behavior were not independently verified. The description reports Linux WSL2 checks, including the focused tests and a broader ctest run; those results were not reproduced here. The changed files read were core/libs/prx/libkernel/Socket/src/Udp.cpp, core/libs/tests/GuestKernelFcntl.cpp, core/libs/tests/GuestKernelSys.cpp, docs/dev/debt/changes/fix-libSceNet-ioctl-inet-unknown-request.md, docs/dev/debt/changes/fix-libkernel-ioctl-pipe-unknown-request-enotty.md, and docs/dev/debt/changes/fix-libkernel-socket-ioctl-eopnotsupp.md. No changed file was excluded.
To get this to a good state
Nothing is required.
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
|
Some 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.
|
ligmaSec
left a comment
There was a problem hiding this comment.
Ran the focused Linux GuestKernelFcntl ioctl case at 8f9c4ba64c with actual local and IPv6 sockets. The unsupported protocol commands returned EOPNOTSUPP, the existing state and interface command exceptions retained their expected errors, and the readable-byte query still worked. The same fixture failed with the exact pre-change Udp.cpp.
AI-assisted: yes.
Plyxen
left a comment
There was a problem hiding this comment.
I read the diff at 8f9c4ba64c. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at b97867d3ce6 together with other open PRs (so not an isolated build).
guest_kernel_sysandguest_kernel_fcntl: pass on both.- Control (same tree and tests, the changed files of those PRs put back to
main's): both fail on both (guest_kernel_sysat line 106 on Linux with guest errno 25).
Not checked: a title.
AI-assisted: yes (Claude Code)
What
On a guest socket,
ioctlwith a request it does not handle and whose group is noti,rorffailed withENOTTYon a local socket andEADDRNOTAVAILon anAF_INET6socket (Udp.cpp:2672-2675). It now fails withEOPNOTSUPPon both, andAF_INETkeepsEADDRNOTAVAIL. That is the mappingTerminalErroralready givestcgetattrand the othertc*calls. Every result this PR changes becomes what FreeBSD 11.4 gives, and every request FreeBSD answers some other way keeps today's result.tcgetattr). docs(debt): record the tcgetattr and cfsetspeed results on firmware 11.60 #22168 measured firmware 11.60 from a payload process:tcgetattron both ends of a local socket pair gave 45 (EOPNOTSUPP). That this is the answer ofioctlassumes the console'stcgetattris FreeBSD 11.4's_ioctl(fd, TIOCGETA, t)(termios.c#L52-L55), a group-trequest.soo_ioctlpasses such a request topru_control, which a local socket leaves atpru_control_notsupp(uipc_domain.c#L144):return EOPNOTSUPP;. fix(libkernel): reject empty ioctl requests and answer INET socket requests as measured on a PS5 #11219 had keptENOTTYfor non-INET sockets "since they were not measured".AF_INET6(not measured on a console).in6_controlanswersSIOCGETSGCNT_IN6,SIOCGETMIFCNT_IN6,SIOCAADDRCTL_POLICYandSIOCDADDRCTL_POLICY(u106 to 109) first, then returnsEOPNOTSUPPfor any other request when there is no interface. Merged fix(libSceNet): follow FreeBSD 11.4's sys_ioctl for unhandled sceNetIoctl requests #22992 gives thatEOPNOTSUPPinsceNetIoctland says: "libkernel'sioctlstill givesEADDRNOTAVAILonAF_INET6; that is for a separate PR." This half rests on FreeBSD and can be split out.i,randfkeepENOTTYon every family.SIOCATMARK,SIOCSPGRPandSIOCGPGRPkeepEADDRNOTAVAILonAF_INETandAF_INET6andENOTTYon local sockets, andu106 to 109 keepEADDRNOTAVAILonAF_INET6: FreeBSD answers these before theEOPNOTSUPPpath, and they are not implemented here. On a local socketu106 to 109 go topru_control_notsupplike any other request and now giveEOPNOTSUPP.Who can reach it:
tcsetsid(Export.cpp:1385-1387) issuesTIOCSCTTYthrough thisioctl, so on a local socket it now givesEOPNOTSUPPlike the othertc*calls.sceNetIoctlon a libkernel socket forwards to thisioctl(libSceNet/Export.cpp:3886-3887). Such a call now gets 45 instead of 49 onAF_INET6and 45 instead of 25 on a local socket, which is what fix(libSceNet): follow FreeBSD 11.4's sys_ioctl for unhandled sceNetIoctl requests #22992 gives on libSceNet's ownAF_INET6sockets. They still differ inSIOCATMARK,SIOCSPGRPandSIOCGPGRP(49 here onAF_INETandAF_INET6, 25 there on every family) and inu106 to 109 onAF_INET6(49 here, 25 there).The debt entry records that Stremio Plus (PPSA74126) imports
_ioctlfor itstc*functions; whether it calls them on a local socket is not known.Tests:
guest_kernel_fcntl. On a local pair,TIOCGWINSZ, the void0x20047801andu106 to 109 fail withEOPNOTSUPP, and so doestcgetattron the same descriptor;FIONREADstill succeeds,SIOCGIFFLAGSstill givesENOTTY, and the threesrequests giveENOTTY. On anAF_INET6socket the first two giveEOPNOTSUPP, and the threesrequests andu106 to 109 giveEADDRNOTAVAIL.guest_kernel_sys:tcsetsidon a local pair givesEOPNOTSUPP. TheAF_INETchecks are unchanged.Debt: the libkernel
ioctl, _ioctlentry is already changed by the pending fragmentfix-libkernel-ioctl-pipe-unknown-request-enotty.md, and only one fragment may change an entry, so this edits its socket sentence in place; the last clause of the libSceNet entry infix-libSceNet-ioctl-inet-unknown-request.md(fix(libSceNet): follow FreeBSD 11.4's sys_ioctl for unhandled sceNetIoctl requests #22992), "libkernel'sioctlgivesEADDRNOTAVAILthere", is no longer true and is removed the same way (what libkernel'sioctlgives is in its own entry). A new fragment corrects the errors thetcsetsidentry inlibkernel_syslists.Neighbours: test(libkernel): audit socket ioctls FIONREAD, FIONBIO, SIOCGIFCONF, and FreeBSD error mapping #21020 (open, test only) expects
ENOTTYforSIOCGIFCONF, anirequest, on a unix pair, which is unchanged. fix(libkernel): fail sockatmark on a descriptor that is not a socket with ENOTTY, as FreeBSD 11.4 does #28202 changessockatmark, not this code.Tested
Linux (WSL2 Ubuntu 24.04, kernel 6.6.87.2), GCC 13.3, x86-64.
maind42e183ca3: a probe linked againstmain's libraries makes every call the new tests make. It gets 25 on the local pair and 49 onAF_INET6wherever the tests expect a changed result, and the pinned value for every unchanged one. With the first version of the new tests (before theu106 to 109 cases),guest_kernel_sysfails at line 106 (tcsetsidon the local pair, errno 25), andguest_kernel_fcntlaborts.guest_kernel_fcntl,guest_kernel_sys,guest_sce_net,guest_socket_pairandguest_terminalpass, and the probe gets the expected value for every call.ctest, on this branch beforeu106 to 109 were kept: 7117 of 7312 pass. Each of the 195 failures is on this machine's list of tests that also fail onmainhere (mostlyagc_*GPU tests on llvmpipe; the 6.6 WSL kernel has no write watch).python3 tools/check_conventions.py --base origin/mainpasses with twodebt-lengthwarnings: the libkernelioctlentry (1336 characters, 1221 onmain) and the libkernel_sys entry (1033, 1000 onmain).python3 tools/debt_fold.py --checkpasses.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
Summary by CodeRabbit