fix(libkernel): fail F_DUPFD_CLOEXEC and make F_DUP2FD_CLOEXEC ignore its target as measured on a PS5 #11135
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11135"
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-25T19:18:46Z.
What
F_DUPFD_CLOEXEC(17) now fails withEOPNOTSUPP(45,0x8002002dthroughsceKernelFcntl) instead of duplicating the descriptor withFD_CLOEXECset, as a retail PS5 (firmware 13.60) does. Measured with homebrew probes from a payload process through bothfcntlandsceKernelFcntl; the sources and console logs are in this gist (pkfcntl,pkfcntl2).On the console:
F_DUPFD_CLOEXECfails withEOPNOTSUPPfor a start of 0, 200 and -1, so the start is not checked first.EBADFfirst.F_DUPFDon the same descriptors duplicates normally, which is unchanged here.The file path (
File::Fcntl) and the guest socket path (fcntlinUdp.cpp) both fail the command now. The socket helper loses its close-on-exec parameter, which only this command used.Left as they are, and recorded in a new
docs/dev/debt/libkernel.mdentry:SHM_ANONdescriptor the console returns 0 without settingerrno, whatever the start. Descriptor 0 was already open, so whether anything is duplicated is not known. Here it fails like the other kinds, because on Windows an anonymous shared memory descriptor cannot be told apart from a temporary file.F_DUP2FD_CLOEXEC(18) is now handled too: a later probe (gist,pdup2cx) showed what it does on the console. It ignores the target: it neither opens nor closes it, for 300, 301, 20,INT_MAX, -1, -2, the source itself and an open descriptor alike. It returns a new descriptor for the same open file (same inode, shared offset, sameF_GETFL) withoutFD_CLOEXEC, numbered somewhere from 17 to 1012 with no visible pattern. A bad source getsEBADF. Here the file and socket paths now return a new duplicate at the lowest free number (the console's numbering is not modelled), withoutFD_CLOEXEC, and leave the target alone;F_DUP2FD(10) is unchanged.The
sceKernelFcntlentry now records what was measured: the same return values asfcntl, and0x80020000plus the errno, which is also set, forF_GETFD,F_SETFD,F_GETFL,F_DUPFD,F_DUPFD_CLOEXEC,F_GETLK, an unknown command and bad descriptors. AnyPS5 already matched all of these exceptF_DUPFD_CLOEXEC. Sockets created through libSceNet take their own status path, which still answers every command exceptF_GETFLandF_SETFLwithEINVAL; the probes used libkernel sockets only, so that path is unchanged.Before and after
fcntl/sceKernelFcntlF_DUPFD_CLOEXECon a file, socket or pipeEOPNOTSUPP(0x8002002d)FD_CLOEXECEOPNOTSUPP(0x8002002d)F_DUP2FD_CLOEXECFD_CLOEXECFD_CLOEXECFD_CLOEXECEBADFF_DUPFD,F_GETFD,F_GETFLand the others listed aboveF_DUPFD_CLOEXEConSHM_ANONFD_CLOEXECEOPNOTSUPP(debt)Tested
Windows 11, WinLibs GCC 15.2, full build.
85a1bf2b31(main9f386f3a29merged in): only thefcntldebt entry met; it keepsmain's newO_FSYNCwording and dropsF_DUPFD_CLOEXECfrom the socket path list and the lowest-descriptor sentence as before.guest_kernel_fcntl,guest_socket_descriptorsandguest_socket_descriptor_flagspass three runs in a row on Windows and on Linux (WSL Ubuntu, GCC), and the 189 Windows tests matchingfcntl|descriptor|shm|socket|dup|pipe|kqueue|net_|fsync|syncpass.guest_kernel_fcntl,guest_socket_descriptorsandguest_socket_descriptor_flagspass 3 times out of 3. They checkEOPNOTSUPPon a file for starts 0, 20, 200 and -1, on a socket, on both pipe ends and on anSHM_ANONdescriptor, through both entry points, andEBADFfor -1 and 9999.fcntl|descriptor|shm|socket|dup|pipe|kqueue|net_pass.tools/check_conventions.pygives one warning: the existingfcntlentry is over 1000 characters (3872). This PR only removesF_DUPFD_CLOEXECfrom it.With the
F_DUP2FD_CLOEXECchange the three tests pass 3 times out of 3 again. They check that the command returns a new descriptor different from the target and the source, withoutFD_CLOEXEC, for targets that are open, the source itself, -1, -2 and 300, on a file, a socket and both pipe ends. They also check that the target keeps its flags, that the offset is shared, and that a bad source (-1, 9999) getsEBADF.Head
0868498fc2onmaincceb6c3c41.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)fcntldebt entry this PR edits), #9566 (it edits thefcntlandioctldebt entries) and #10319 (it edits the entry between the two this PR edits); merge order onlyImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:22:11Z.
Review: APPROVED
Reviewed the file and kernel-owned socket dispatch at this exact head: invalid descriptors are rejected as
EBADFbefore the unsupported-command result, while valid descriptors returnEOPNOTSUPP;F_DUPFDremains on its existing duplication path. The updated tests cover both entry points and descriptor classes, including the measured start-value precedence. GCC 12.2 syntax compilation passed for the changed implementation and test translation units. The Windows 11 runtime suites and retail PS5 probe results are author-reported; hosted functional jobs are skipped by path policy. The documentedSHM_ANONdiscrepancy remains explicit rather than being represented as measured parity.