feat(libkernel): keep the SIGIO owner of a pipe for F_GETOWN and F_SETOWN #9557
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9557"
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 DavidSamir on 2026-10-22T02:12:30Z.
What
fcntlthrew forF_GETOWNandF_SETOWNon every descriptor, andioctlthrew forFIOGETOWNandFIOSETOWN. They now follow FreeBSD 11:kern_fcntlturnsF_GETOWNandF_SETOWNintofo_ioctl(FIOGETOWN/FIOSETOWN)(sys/kern/kern_descrip.c:579-598).pipe_ioctlkeeps the end's SIGIO owner throughfsetownandfgetown(sys/kern/sys_pipe.c:1392-1399,kern_descrip.c:1043and:1148). Here:ESRCH, aspfind/pgfindfind no such process or group;dup,dup2andF_DUPFDshare it.app0.zar: all four fail withENOTTY, asvn_ioctlhands them toVOP_IOCTL(sys/kern/vfs_vnops.c:1488).No
SIGIOis ever sent.O_ASYNCstill throws, so a stored owner never implies a signal. The owner is kept in aweak_ptrmap keyed on the descriptor's shared status object, which leaves the descriptor table'sEntryandShareDescriptorunchanged.tcgetpgrp/tcsetpgrpon a pipe (TIOCGPGRP/TIOCSPGRP) will follow in a separate PR.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is CPU-side, so no GPU is involved.
New test
guest_kernel_fcntl_owner(core/libs/tests/GuestKernelFcntlOwner.cpp), which covers:ESRCHforpid + 1and-(pid + 1)with the owner kept; sharing throughdup; the other end staying independent; theFIOSETOWN/FIOGETOWNforms, includingEFAULTfor a NULLFIOGETOWNargument.ENOTTYfrom all four requests.EBADF.Results:
guest_kernel_fcntl,guest_dup,guest_kqueueandguest_terminalpass in 3 runs of the set. In one earlier run of the set, right after a partial rebuild,guest_kqueueaborted. It didn't reproduce in 5 solo runs and 3 more runs of the set.dupsharing);ESRCHcheck, it fails at line 60.tools/check_conventions.py: 0 errors. Its one warning is the length of thefcntldebt entry, which was already 4476 characters onmain.tools/pr_overlap.py --branchplusgit merge-tree. #9131 and #7121 merge cleanly. #9256, #8544 and #9109 rewrite the same longfcntldebt line indocs/dev/debt/libkernel.md, so this PR conflicts with them on that line only. The code itself doesn't conflict, and whichever merges second keeps both changes.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-22T04:14:36Z.
Review: CHANGES_REQUESTED
The owner state and focused pipe tests are coherent on inspection, but there is a concrete invalid-pointer gap in the ioctl path:
FIOSETOWNdirectly dereferencesargument(*static_cast<const int*>(argument)) before validating it.FIOGETOWNexplicitly returnsEFAULTfor a null output pointer, whileFIOSETOWNwith null can fault the host instead of returning guestEFAULT. Please add checked copy-in for the four-byte input (including an unreadable non-null pointer) and a regression test, matching the checked output handling. Also, the overlap report flags live shared debt edits in #9256, #8544 and #9109; those authors must agree the ordering and preserve each debt change, with aDepends onentry if sequencing is required. Finally this branch is based on8c26eac3, 23 commits behind currentmaindce41a89478876a8e3ea9c346b1dac00bb31c8cd; please update and rerun relevant tests before approval. Hosted policy checks pass, product build jobs are skipped; Windows test evidence in the body is author-reported and I did not run it locally.Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T06:01:29Z.
Review: COMMENTED
Checked against main
4a17c7175and FreeBSD releng/11.4 (sys/kern/sys_pipe.c:1392-1410,sys/kern/kern_descrip.c:1043-1148,sys/fs/fifofs/fifo_vnops.c):fsetown/fgetown: 0 clears,ESRCHkeeps the old owner, and the owner is per open file and shared bydup. The weak_ptr map is reset correctly bypipe()andclose().FIOSETOWNNULL point:Ioctlalready returnsEFAULTfor a NULLIOC_INargument atDescriptorControl.cpp:559, before the dereference at:581. Only a non-NULL unreadable pointer gets through, andFIONBIOon main does the same. A checked copy-in would be nice for both, plus a test that NULLFIOSETOWNgivesEFAULT, which isn't covered yet.Kind::Socket, soF_GETOWN/F_SETOWNon it throw. The debt sentence only names the character device and random device. Could you add that case?pipe_sigio(fifo_vnops.cpassesfip->fi_pipeto every open). Here twoopen()s of the same host FIFO keep separate owners. Worth a short debt note.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T07:58:56Z.
Thanks @MarcZX10 and @harisibrar1. New commits, no force-push:
4aa8b79b25:FIOSETOWNandFIONBIOnow copy their int argument in with a checked read:ReadProcessMemoryon Windows,process_vm_readvon Linux,mach_vm_read_overwriteon macOS, the same asStdio.cpp'sCopyIovecs. An unreadable non-null pointer fails withEFAULTinstead of faulting the host. As @harisibrar1 noted, a null argument already gotEFAULTat theIOC_INcheck, but no test covered it.guest_kernel_fcntl_ownernow checksFIOSETOWNwithnullptrand with an unreadable pointer (0x10), each givingEFAULTwith the owner unchanged, andFIONBIOwith the unreadable pointer.0xc0000005.F_GETOWN/F_SETOWNon a host socket that is not a guest socket still throw (Linux and macOS), and that two opens of one FIFO keep separate owners, where FreeBSD sharespipe_sigio.f8698a0b66: merges currentmain(d6eafa54d0).Re-run on the merge (Windows 11, WinLibs GCC 15.2):
guest_kernel_fcntl,guest_kernel_fcntl_owner,guest_terminalandguest_append_writespass, andcheck_conventions.pyreports 0 errors. Its one warning is thefcntldebt entry, already over the limit onmain.For the debt-row overlaps (#9256, #8544, #9109), I'm asking those authors for an order and will record it in the checklist.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:22:51Z.
The checked copy-in for FIOSETOWN/FIONBIO and the added debt notes address the concrete feedback from the earlier review; the author-reported Windows focused tests pass. I checked this head against current upstream/main: the merge is clean and no intervening main commit changes DescriptorControl.cpp, the new owner test, or the debt file, but it remains 3 ahead/11 behind (merge base
d6eafa54d). Please update to current main and rerun the focused fcntl/owner tests and conventions. The debt-line length is still reported as a warning by conventions (0 errors). The shared debt edit also needs recorded agreement with #9256, #8544, #9109 and the adjacent #9561 update; please add Depends on where an order is required. I found the order proposal to #9256, but no confirmation from the affected author yet. Product and relinker jobs are skipped; I did not run tests locally because the filesystem is full.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:22:52Z.
Review: CHANGES_REQUESTED
The invalid-pointer safety issue is addressed, and the author reports the focused Windows tests passing. The remaining blockers are repository integration requirements: this branch is 3 ahead/11 behind current upstream/main
4777caca34(merge based6eafa54d), so update and rerun relevant tests; and record merge-order agreement for the shared libkernel debt edit with #9256, #8544, #9109 and #9561, declaring Depends on if required. Conventions reports 0 errors with the inherited long debt-row warning. Hosted product/relinker tests are skipped. I did not run tests locally because the filesystem is full.Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T12:54:55Z.
Review: APPROVED
Rechecked at
f8698a0b6:FIOSETOWNandFIONBIOnow copy their argument in throughReadGuestInt(DescriptorControl.cpp:554-574). It follows main'sCopyIovecschecks (null and wrap, thenReadProcessMemory/process_vm_readv/mach_vm_read_overwritewith a full-length check), so an unreadable pointer givesEFAULTand the owner is left unchanged. The newnullptrand0x10cases inGuestKernelFcntlOwnercover both.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Pull request closed