fix(libkernel): return EFAULT from socket ioctl for invalid memory pointers #12646
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12646"
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 slopgobblercobbler on 2026-10-29T00:01:57Z.
What
argumentpointer passed toioctl_nid_postfixand_ioctl_nid_postfixfor guest sockets usingGuestCopyIn_nid_no_patch(forFIONBIO/ 0x8004667e) andGuestCopyOut_nid_no_patch(forFIONREAD/ 0x4004667f).-1witherrno = 14(EFAULT) whenargumentpoints to unmapped, invalid, or read-only guest memory, preventing host access violations.sys_ioctl(sys/kern/sys_generic.c), whereIOC_INrequests copy the argument viacopyinandIOC_OUTrequests copy the result viacopyout, returningEFAULTimmediately if memory access fails.DescriptorControl.cpp).GuestKernelFcntl.cpp,GuestTcp.cpp, andGuestUdp.cppverifyingEFAULTon invalid pointers with bothioctland_ioctl.Tested
python tools/check_conventions.py --base upstream/main --head HEADreports 0 findings.python core/libs/tests/test_public_headers.py --audit-onlypassed (373 libraries, 13414 exports verified).guest_kernel_fcntl,guest_kernel_fcntl_sync,guest_tcp, andguest_udppassed 3/3 runs; negative control confirmed failing against baseUdp.cpp.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 rooklz on 2026-10-29T02:19:34Z.
Review: COMMENTED
Host-side review of ac2f2b0fc0 (macOS 26 arm64 and Ubuntu 24.04 glibc 2.39, no console). The full guest build was not run here because submodules are not initialised.
Method. I extracted
ioctl_nid_postfixverbatim from head and from main (3a2b919816). It was compiled under ASan+UBSan against real AF_UNIX stream and datagram socketpairs, using a minimalSocket/Lookup/Failshim and the samemach_vm_*/process_vm_*copy primitives thatGeneral.cppuses. The test matrix was {FIONBIO, FIONREAD, FIONREAD after receive shutdown} × {RW page, read-only page, PROT_NONE page,0x10, an int that straddles RW→PROT_NONE}. Each case ran in a forked child.options.nonblockingnor the hostO_NONBLOCK. FIONBIO from a read-only page still succeeds, which is correct because it isIOC_IN. RW pages give 5 queued bytes, or 0 after shutdown.git merge-treeagainst main is clean. It does conflict with #11219 inGuestKernelFcntl.cpp, which is the row the bot flagged, so one of the two will need a rebase.Test gap. Two mutants survive the new tests. They do so because
0x10andnullptrare unreadable as well as unwritable:GuestCopyIn) and then writes directly.On a read-only page each mutant crashes (SIGBUS in the harness), but every new assertion passes. A row with a read-only destination would kill both. For example, in
GuestUdp.cppnext to the new rows, following theGuestDirectoryBuffer.cppCheckReadOnlyDestinationpattern:Add the same
0x4004667frow aftershutdown_nid_postfixinGuestTcp.cpp. I have not built this against the real test target, so please check that the target links the direct-memory exports.The code change looks correct to me.