fix(libkernel): reject empty ioctl requests and answer INET socket requests as measured on a PS5 #11219
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11219"
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 orezraey on 2026-10-25T22:03:24Z.
What
ioctlnow rejects an input or output request with length 0 as malformed (ENOTTY) on every descriptor. It also answers an unknown request on anAF_INETorAF_INET6socket withEADDRNOTAVAILwhen the request group is noti,rorf. A retail PS5 (firmware 13.60) does both. Measured with a homebrew probe from a payload process; the source and console log are in this gist (pioctl0).On the console:
Empty input request.
_IOC(IOC_IN, 'f', 127, 0)(0x8000667f) fails withENOTTY(25) on a file, a datagram socket, both pipe ends and a directory, with a null argument and with a pointer. FreeBSD'ssys_ioctlrejects such a request only when the kernel is built without the 4.3BSD/FreeBSD 4–5 compatibility options. The debt entry said which of these the PS5 kernel has was unknown.0x8000667fis the only empty input request the probe sent, and the test uses it. The check covers every other one by inference:sys_ioctltests only the direction bits and the length, not the request code. On the datagram socket this request gaveENOTTY, where the measuredTIOCGWINSZgaveEADDRNOTAVAIL; on the other descriptorsENOTTYalone would not tell the check apart from an unknown request.EFAULT.TIOCGWINSZon anAF_INETdatagram socket givesEADDRNOTAVAIL(49), where files, pipes and directories giveENOTTY. That is FreeBSD'ssoo_ioctlpassing a request outside theiandrgroups toin_control, which fails without an interface. AnyPS5 returnedENOTTY.i,randfother thanFIONBIOandFIONREAD, and non-INET sockets, keep returningENOTTY, since they were not measured. FreeBSD'ssoo_ioctlsends groupsiandrtoifioctlandrtioctlinstead ofin_control;fhas no such branch there, so keepingENOTTYfor it is a choice for lack of a measurement.Already matching:
FIONREAD(file 5 bytes past the offset, socket 0, pipe read end 3, write end 0);FIONBIO, which togglesO_NONBLOCKinF_GETFL;TIOCGWINSZon non-sockets.Still different.
FIONREADon a directory returns 65536 on the console and still throws here, because that number comes from the console's file system. The debt entry now starts with that gap.tcsetsidon anAF_INETsocket. #9713 issuesTIOCSCTTY(0x20007461, groupt) through thisioctland testedENOTTYon a UDP socket, which came from the old catch-all rather than a measurement. FreeBSD'ssys_ioctlandsoo_ioctldo not look at the direction, so that request takes the path measured forTIOCGWINSZ(also groupt):guest_kernel_sysnow expectsEADDRNOTAVAILthere, and thelibkernel_sysdebt entry says so.TIOCSCTTYitself was not measured. A null argument on a void request still does not giveEFAULT, as #9713 intended.Before and after
ioctlENOTTYENOTTYENOTTYEFAULTENOTTYTIOCGWINSZon anAF_INETsocketEADDRNOTAVAIL(49)ENOTTYEADDRNOTAVAILFIONREAD,FIONBIO,TIOCGWINSZon non-socketsFIONREADon a directoryTested
2e5675adfa:maine772fb25ccwas merged in, with #12646. Inguest_kernel_fcntlthe socket case keeps this PR's empty input request (ENOTTY) andTIOCGWINSZ(EADDRNOTAVAIL) checks, followed by #12646's eightEFAULTchecks forFIONBIOandFIONREADthroughioctland_ioctl.guest_kernel_fcntl,guest_tcp,guest_udpandguest_kernel_syspass three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC);check_conventionspasses.125a0d5c55:main3d5a2a5cddwas merged in, with #9713.Udp.cppkeeps #9713's null-argument check and this PR's request check.guest_kernel_fcntl,guest_tcp,guest_udpandguest_kernel_syspass three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC);check_conventionspasses.cf7da83495:mainwas merged in, with #13695. Only theioctldebt entry met: it keeps this PR's wording and now listsFIOCLEXandFIONCLEXas handled on a socket.guest_kernel_fcntl,guest_tcpandguest_udppass three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC);check_conventionspasses.Windows 11, WinLibs GCC 15.2, full build. The 109 tests matching
fcntl|ioctl|socket|directory|pipepass 3 times out of 3.guest_kernel_fcntlnow checks:ENOTTYon a socket (null argument), a file (null and pointer) and a pipe;TIOCGWINSZgivesEADDRNOTAVAILon anAF_INETsocket.After merging
main3498905cc0with #10767 (head397c39fce0):guest_kernel_fcntlandguest_kqueuepass 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and 3 times out of 3 on Linux (WSL Ubuntu, GCC).tools/check_conventions.pypasses.At head
896bb41323:guest_kernel_fcntlandguest_kqueuepass 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and 3 times out of 3 on Linux (WSL Ubuntu, GCC). With the malformed check put back to output requests only,guest_kernel_fcntlfails on Windows.tools/check_conventions.pypasses.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)ioctl, _ioctldebt entry); #15556 (BunnyFl) adds a sysmoduleflagsdebt entry next to thetcsetsidone; merge order only. #11223, #12646 and #15890 have mergedImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:07:29Z.
Review: APPROVED
Reviewed exact head
250ab52ce8eff60d4ed11c797345e5aa85240522and the linked firmware 13.60 probe source/log. The0x8000667fzero-length input request returnsENOTTYfor the measured file, datagram socket, both pipe ends and directory, with null and non-null arguments.TIOCGWINSZ(0x40087468) on the measured AF_INET datagram socket returnsEADDRNOTAVAIL; the other captured descriptor kinds returnENOTTY. The implementation applies the empty-length rule before descriptor argument handling and uses the measured ioctl group plus socket family to select the network error. The focused test updates cover the socket, file and pipe cases described in the PR.Local
git diff --checkpassed. Current-main conventions report no errors (one debt-length warning on the updated entry). I inspected the changed dispatch and tests, but did not run the kernel tests locally: the availablebuild-reviewconfiguration is relinker-only and has noGuestKernelFcntltarget. The PR reports 109 matching Windows tests passing three times; hosted product build jobs are skipped by path policy. Pairwise merge previews show the expectedGuestKernelFcntl.cpp/debt overlap with #11135 andUdp.cppoverlap with #9713; please keep the stated dependency order when landing.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T14:31:53Z.
Review: COMMENTED
Reviewed — no blocking findings
The head
397c39fce0changes two ioctl paths and their tests; the source reads consistently with its tests, but the firmware-probe evidence cited by the earlier approval uses a request code that differs from the one in this head's test, and the console claims are not verifiable here, so I withhold approval.What I ran
397c39fce0f97a36d834dd2be79b725d43b661e2. Base:3498905cc00bd27d8e49ab908ab02c589846c9bb. Earlier approved head:250ab52ce8eff60d4ed11c797345e5aa85240522(its approval text was read; its diff was not compared line by line).Results
git diff --check(base..head)possible-unregistered-cpp-testforGuestKernelFcntl.cpp; the file is registered atcore/libs/prx/libkernel/CMakeLists.txt:20270x8000667f(see Findings)Unedited precheck output (conventions)
Negative control
Not run: the changed tests are C++ and need a build, which this review does not do. The new assertions are checked against the source only.
Findings
Blocking: none.
Non-blocking:
250ab52ce8says the firmware probe measured the zero-length input request0x8000667freturningENOTTY. At this head the test usesEmptyInputRequest = 0x80006601(core/libs/tests/GuestKernelFcntl.cpp:69), and0x8000667fdoes not appear anywhere incore,toolsordocs. Either the probe or the test is using a different code. Please state which request the probe measured and make the test use it, or explain the difference.IoctlRequestMalformedchange (core/libs/prx/libkernel/File/src/DescriptorControl.cpp:553) now treats a zero-lengthRequestInrequest as malformed, not onlyRequestOut. That matches the new expectations in the test, but it is a behaviour change for every IN ioctl, so the firmware evidence needs to cover IN requests other than the one probed.EADDRNOTAVAIL(49) branch for other groups on AF_INET and AF_INET6 sockets (core/libs/prx/libkernel/Socket/src/Udp.cpp:1487-1491) is supported only by the console log cited in the earlier approval; the reason for the group listi,r,fis not explained in this diff.Sources
github.com/boykopovar/AnyPS5@397c39fce0/core/libs/prx/libkernel/File/src/DescriptorControl.cpp (L550-L556)github.com/boykopovar/AnyPS5@397c39fce0/core/libs/prx/libkernel/Socket/src/Udp.cpp (L1484-L1492)github.com/boykopovar/AnyPS5@397c39fce0/core/libs/tests/GuestKernelFcntl.cpp (L69)andgithub.com/boykopovar/AnyPS5@397c39fce0/core/libs/tests/GuestKernelFcntl.cpp (L202-L204)github.com/boykopovar/AnyPS5@397c39fce0/core/libs/prx/libkernel/CMakeLists.txt (L2027)Not verified
To get this to a good state
0x8000667for0x80006601) and align the test and the evidence with it.