fix(libkernel): pass ioctl on a sceNetSocket socket to libSceNet #15890
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15890"
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-11-04T22:17:23Z.
What
ioctland_ioctlon a socket created bysceNetSocketdid not reach libSceNet, thoughfcntlon the same descriptor does, throughKernelSetSocketStatusControl. The kernel took the descriptor as a file. On Linux the descriptor is a duplicate of the host socket, soFIONBIOswitched the hostO_NONBLOCKbut not the library'sSO_NBIOstate, whichsceNetRecv,F_GETFLandSO_NBIOread. On Windows it is aNULplaceholder, soFIONREADand enablingFIONBIOthrew as on a character device. This was the debt entryioctl, _ioctl ... do not pass a sceNetSocket socket to libSceNet as fcntl does.FreeBSD 11.4's
kern_ioctlhandles every socket the same way throughfo_ioctl, that issoo_ioctl, whereFIONBIOsets the socket's non-blocking state andFIONREADreports its queued bytes.sceNetIoctlalready implements both on asceNetSocketsocket.SocketPoll.hppandSocket.cppadd anIoctlControlhook next toStatusControl, withKernelSetSocketIoctlControl_nid_no_patchandKernelControlSocketIoctl_nid_no_patch.ControlSocketIoctlForKernel. It returnsfalsefor a descriptor that isn't one of its sockets. Otherwise it callssceNetIoctland hands itserrnoback, asControlSocketStatusForKerneldoes forfcntl.ioctl_nid_postfixfinds a libSceNet socket with the existingKernelFindSocketNative_nid_no_patchlookup. It then applies the checks a kernel socket gets: a malformed request fails withENOTTY, and a null argument for a request with a length fails withEFAULT. Then it passes the request to the hook.FIOCLEXandFIONCLEXkeep their current path to the descriptor beneath the socket.fcntl'sF_GETFDandF_SETFDon such a socket still fail withEINVAL, so the socket has no close-on-exec flag to set yet. The debt entry now records that gap in place of the fixed one.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0, CMake + Ninja, Release,
-DBUILD_TESTING=ON, onmainc3a5290c7d.guest_sce_net'sCheckIoctlnow callsioctl_nid_postfixon asceNetSocketdatagram socket. It checks that:FIONBIOwith 0 and 3 setsSO_NBIOto 0 and 1, andF_GETFLreportsO_RDWRandO_RDWR | O_NONBLOCK;FIONREADreports 5 with a 5-byte datagram queued and 0 after it is received;FIONBIOandFIONREADwith a null argument fail withEFAULT.main'sUdp.cppand the rest of this PR,guest_sce_netfails (exit 0xc0000409). With this PR it passes.guest_sce_net,guest_sce_net_kernel_forwardsandguest_kernel_fcntlpass.python tools/check_conventions.py --base origin/mainpasses.Overlap (
tools/pr_overlap.py), checked withgit merge-treeagainst this branch:EADDRNOTAVAIL. Its code merges cleanly with this PR. The debt file conflicts on lines only: #11219 rewrites theioctlentry directly above the one changed here. Whichever merges second keeps both entries. With #11219, asceNetSocketsocket still answers other requests throughsceNetIoctlwithENOTTY, as thesceNetIoctlentry inlibSceNet.mdrecords.EFAULTfor invalid socketioctlpointers) merges cleanly.mainin the same files. This PR adds no conflict to their code: #12688, #12700 and #12965 change the kernel socketFIONBIObranch, not the path added here.libkernel.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)