fix(libkernel): return EFAULT from ioctl FIONBIO for an unreadable argument #12579
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12579"
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 babyhuey on 2026-10-28T21:19:47Z.
What
ioctl(FIONBIO)read itsintargument directly after the existing null check, so a non-null pointer into unmapped memory crashed the host.FIONBIOis an_IOWrequest: FreeBSD'ssys_ioctlcopies the argument in and returnsEFAULTif that fails.GuestCopyIn_nid_no_patchbefore the status change; a failed copy returnsEFAULT(14).FIONBIObranch, after the descriptor lookup as before, so a bad descriptor still reportsEBADFfirst.Tested
core/libs/tests/GuestKernelFcntl.cppadds an unmapped argument (0x10) next to the existing null case; both fail withEFAULT.anyps5-buildCI image, Ubuntu 24.04, GCC 13, Release,BUILD_TESTING=ON), this headb4ae3afc61conmainf21ef7c99c5:guest_kernel_fcntlpasses; the fullctestpasses (2,740 of 2,740), andcheck_conventions.pypasses. Withmain'sDescriptorControl.cppthe same test segfaults.BUILD_TESTING=ON, this head: full build andlibssucceed;guest_kernel_fcntlpasses 3 of 3 alone; withmain'sDescriptorControl.cppit crashes (0xc0000005). CI's test selection for this change (2,384 tests): 1,644 pass, 739 skip, and one relinker test unrelated to this change,restricted_undefined_symbols_guest, timed out under--parallel 4against its own 20 s limit; alone on this head it passes 3 of 3 in at most 3.7 s.check_conventions.pypasses.#10016, #11219 and #12474 also edit
ioctl; each one's current head merges with this one without conflicts.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-28T21:29:05Z.
Review: APPROVED
Reviewed head
b4ae3afc61c6a15a7f8a84e0966cca912316dcf2against currentmain(319621ba2e578bd053b0baba2877fe70520e0737). The change reads the guestFIONBIOinteger throughGuestCopyIn_nid_no_patchbefore changing status, preserving descriptor lookup and its existingEBADFprecedence while mapping an unreadable guest pointer toEFAULT. The added0x10regression covers the non-null unreadable case alongside null.The current Windows workflow passes. The PR reports the focused and full Linux suites and a Windows full build/test run; I did not independently rerun those suites. The hosted Linux/product jobs are skipped. I also checked the current merge previews with #10016, #11219, and #12474; they combine cleanly, and their changed hunks do not require a declared ordering for this change. I found no blocking issue in the reviewed diff.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T21:44:15Z.
Review: COMMENTED
I reviewed head
b4ae3afc61.Linux (Ubuntu 24.04 amd64 container, GCC 13, Release,
BUILD_TESTING=ON, worktree at this head):guest_kernel_fcntlpasses 5 of 5 runs. RED check: withmain'sDescriptorControl.cpp(319621ba2e) under the head test, it segfaults (rc 139), as your body says.Mutants (each rebuilt and run against the head test)
return 0EINVALenableinvertedsizeof(int)Error precedence:
EFAULTshould come beforeEBADF. The body says the copy-in stays after the descriptor lookup "so a bad descriptor still reportsEBADFfirst". That is not FreeBSD's order. Insys_ioctltheIOC_INargument is copied in (copyin(uap->data, data, size), thengoto outon error) beforekern_ioctlruns, andkern_ioctlis wherefgetreturnsEBADF.mainalready follows that order for a null argument: the lineif ((command & RequestIn) && length != 0 && argument == nullptr) return Fail(GuestEfault);comes beforeClassify. So the head now gives two answers for the same bad-descriptor call:FreeBSD returns
EFAULTfor both. Moving the copy-in up next to the existing null check fixes that. Your tests still pass with it (5 of 5):Here is a test diff that pins the order and the full-width read. Your head source fails it (rc 134), the moved version passes 5 of 5, and it kills both copy-size survivors: with 1 or 2 bytes,
0x10000reads as 0 and the descriptor goes blocking.Out of scope, for a follow-up: a guest socket never reaches
File::Ioctl.ioctl_nid_postfixinSocket/src/Udp.cppstill dereferences the argument directly (value = *static_cast<int*>(argument) != 0;, and theFIONREADstore), soFIONBIOwith an unmapped non-null pointer on a socket would still crash the host. I didn't run that one.Gates:
check_conventions.py(title + body) passes;git merge-treeagainstmain319621ba2eis clean, and so is each of #10016, #11219 and #12474 against this head.pr_overlap.pyonly lists files it could not compare (#7121, #9557, #9566, #11872, #11969:DescriptorControl.cpp).