fix(libkernel): set and clear close-on-exec with FIOCLEX and FIONCLEX on a socket #13695
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13695"
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 Retr0G28 on 2026-10-31T00:35:42Z.
What
On a guest socket,
ioctl(fd, FIOCLEX)andioctl(fd, FIONCLEX)failed: with a null argument, the usual call for these_IOrequests, they returnedEFAULT, and with a pointerENOTTY. The socket path ofioctlchecks the argument and then accepts onlyFIONBIOandFIONREAD. On files and pipes,File::Ioctlalready handles both requests.FreeBSD 11.4's
kern_ioctlhandlesFIOCLEXandFIONCLEXfor every descriptor before calling the file'sfo_ioctl. It sets or clearsUF_EXCLOSEand returns 0, sosoo_ioctlnever sees them, andF_GETFDthen reports the flag.The socket path of
ioctl_nid_postfixnow handles both requests after the descriptor lookup and before the argument check. They insert into or erase fromcloseOnExecDescriptors, the set that the socketfcntlF_GETFDandF_SETFDalready read and write. The request is compared on its low 32 bits, asFile::Ioctldoes. The debt entry now lists the two requests withFIONBIOandFIONREAD.libSceNet sockets are not changed. Their
fcntlanswers onlyF_GETFLandF_SETFL, so they have no close-on-exec flag to set yet.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0, CMake + Ninja, Release,
-DBUILD_TESTING=ON, onmain7ceda1326c.guest_kernel_fcntlnow checks, on anAF_INETdatagram socket, thatFIOCLEXreturns 0 andF_GETFDreports 1, and thatFIONCLEXreturns 0 andF_GETFDreports 0. Each request is tried with a null argument and with a pointer.main'sUdp.cpp, the new checks fail (exit 0xc0000409 from the failedRequire). With this PR they pass.fcntl|ioctl|socket|recvmsg|sendfile|^guest_udp$|^guest_poll$pass.python tools/check_conventions.py --base origin/mainreports no errors. Its one warning is the length of theioctldebt entry, which was 1650 characters onmainand is 1672 here.Overlap (
tools/pr_overlap.py): it reports no conflict among the PRs it could compare. Of the rest, and the PRs that change the same function:ioctlrequests and answers unknown INET socket requests as measured on a PS5. It edits the sameioctldebt entry, so the two conflict there; the code merges cleanly. It keeps groupfrequests other thanFIONBIOandFIONREADon sockets unchanged, so it does not cover these two. Proposed order: #11219 first, then this PR rebases the debt sentence onto its wording, asked on #11219.if (!argument)check right after the lines added here, to let a void request through with a null argument. It still answers anything butFIONBIOandFIONREADwithENOTTY, so it does not implement these requests. It already conflicts withmain; whichever merges second keeps both changes.FIONBIObranch further down the same function, not these lines.Udp.cppor other entries oflibkernel.md.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T01:07:02Z.
Review: APPROVED
Reviewed — looks good
The socket
ioctlpath sets and clears the same descriptor flag reported byF_GETFD, and the added checks cover both request forms and null/non-null arguments.What I ran
Reviewed head
4b3b93f0ec292d978f4bbb038c4f2ad59aa3275cagainst PR basef0c0b2d19a6ab6bfb11de584bfc38895816ccaf5; GitHub reports it mergeable and clean. The stack preview used current targetbff0289787c98570491c8f175179c8a5651c8017; #13695 and #11219 preview individually cleanly, while their combined preview conflicts only in the debt file. Environment: Linux 6.1, Python 3.11.2, GCC 12.2.0. No build or compile was run.Results
guest_kernel_fcntlis registered incore/libs/prx/libkernel/CMakeLists.txt. The heuristic's possible-unregistered warning is a false positive.docs/dev/debt/libkernel.md. The declared chain also includes #9713, which currently conflicts with the target.Relevant raw output
Negative control
FIOCLEX/FIONCLEXsocket assertionsUdp.cppimplementationFindings
Blocking: None found.
Non-blocking: The
#11219dependency has not landed. Its declared order should be retained; resolve the debt-file conflict when that dependency is integrated.Sources
kern_ioctl, pinned source handlesFIOCLEX/FIONCLEXbefore dispatching to the descriptor operation.ioctlimplementation and added socket assertions.Not verified
I did not build or run C++ tests locally, test Linux behavior, or verify behavior on PS5 hardware. Linux and specialized hosted jobs were skipped. The Windows test results above are author/CI evidence, not local runs.
To get this to a good state
No code change is needed for this review. Keep the declared dependency order and reconcile the debt-file wording when #11219 lands; I can recheck the integrated head then.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-31T04:11:15Z.
Review: COMMENTED
Linux run of this head (
4b3b93f0ec), merged ontomain6475267b45(local only). Ubuntu 26.04 LTS (kernel 7.0), Intel Core i7-8700, GCC 15.2.0, Ninja, Release,BUILD_TESTING=ON.guest_kernel_fcntlpasses 3 of 3;public_headerspasses;ctest -R "fcntl|socket|net_|ioctl|guest_poll"50/50.Udp.cppback tomain(test kept):guest_kernel_fcntlaborts 3 of 3.Together with #13738, which also changes
Udp.cpp, onmain2364892547: clean merge, full build passes,guest_kernel_fcntlandguest_pollpass 3 of 3, the socket/poll/fcntl subset 52/52 andpublic_headerspass.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.