fix(libkernel): fchown, fstat and ioctl on a kqueue descriptor behave as FreeBSD #10016
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10016"
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 xXPBSXx on 2026-10-23T04:08:38Z.
What
A kqueue descriptor is a placeholder host handle (NUL / /dev/null). Four calls treated it as a character device:
fchown(kq, 0, 0)returned 0. FreeBSD: kqueueops usesinvfo_chown,sys/kern/kern_descrip.c:4076returns EINVAL. Now EINVAL.fstat(kq)reported the host placeholder's type. FreeBSDkqueue_stat(sys/kern/kern_event.c:1928) zeroes the struct and setsst_mode = S_IFIFO. Now the same.ioctl(kq, <request>)reached the "unsupported request" throw. FreeBSDkqueue_ioctl(kern_event.c:1853, body under#if 0in 11.4) returns ENOTTY for every request. Now ENOTTY (FIOCLEX/FIONCLEX still handled before, as in sys_ioctl).fchmod(kq, mode)went to the host: on Linux the placeholder is an open of/dev/null, and run as root it changed the mode of/dev/null. FreeBSD: kqueueops setsfo_chmod = invfo_chmod(kern_event.c:131),sys/kern/kern_descrip.c:4068returns EINVAL. Now EINVAL (commitf51395bc09;guest_kqueuegets the case).Applies to
fstat_nid_disambig1_nid_postfixandsceKernelFstat; both build the result locally and copy it out withGuestCopyOut_nid_no_patch, failing with EFAULT when the buffer is not writable, like the otherfstatpaths after #9618.The commits
9226e7bd6c,3bc62ee2b7andc1716688cbonly mergemaininto the branch (conflicts resolved inStdio.cpp, then inlibkernel_sys/Export.cppandGuestKernelSys.cpp, then inGuestKqueue.cpp).Fixes: #10015
Tested
Head
22a5b6db47(two commits), rebased ontomainb91a6a60c5after #9618;git merge-treeagainst currentmain03b96b9241is clean. The diff is 7 files, +41/-1. The second commit (the exported helper forlibkernel_sys) is unchanged by the rebase. In the first commit the only change is inStdio.cpp: the kqueue branch of bothfstatfunctions now fills a local result and copies it out like the other branches, instead of writing into the caller's buffer.mainb91a6a60c5with this head (ninja exit code 0):guest_kqueueandguest_kernel_syseach pass 3 of 3 runs.Equeue.hpp,Kqueue.cpp,DescriptorControl.cpp,Stdio.cppandlibkernel_sys/Export.cpp(all five taken frommain, same build directory, tests kept; ninja exit code 0):guest_kqueueandguest_kernel_syseach fail 3 of 3 runs with exit code 0xc0000409.patched_libraries(this change toucheslibkernel_sys/Export.cpp) passes on Windows, 1 of 1.mainb91a6a60c5(ninja exit code 0):patched_libraries,guest_kqueueandguest_kernel_syseach pass 3 of 3 runs. I did not run these three without the changes on Linux.file|posix|shm|kqueue|equeue|pipe|truncate|lseek|flock|fsync|vector|socket_read|dup|fcntl|descriptor|stdio|aio|kernel_sys|ioctl|fstat|fchown|sendfilehas 161 tests onmainnow (the earlier description named 116): 159 pass and 2 are skipped (guest_named_shm_windows_short_tempandguest_named_shm_windows_long_short_temp, which skip because the volume of the test's temporary directory creates no 8.3 alias for it; measured withTEMPonK:); ctest reports100% tests passed, 0 tests failed out of 161, counting the skips as passed.check_conventions --base upstream/mainpasses.c1716688cb(merge ofmain5cb015caaa, which contains #10014; the diff against thatmainis the same 5 files, +37/-2), Windows 10 Pro 19045, MinGW-w64 GCC 15.2, Release (ninja exit code 0 in both arms):guest_kqueueandguest_kernel_syseach pass 3 of 3 runs andpatched_librariespasses; withDescriptorControl.cpp,Stdio.cppandlibkernel_sys/Export.cpptaken from thatmainand the tests kept,guest_kqueueandguest_kernel_syseach fail 3 of 3 runs, and ctest reportsExit code 0xc0000409for both.fstaton a kqueue descriptor with an unwritable buffer (the code path exists, no test covers it), macOS, a title, a console. Measured by wachi35676 on Windows 11 and WSL2 Ubuntu 24.04 (GCC 13.3, as root): at head22a5b6db47merged ontomain5b85225ef3,guest_kqueue,guest_kernel_sysandguest_kernel_fcntlpass 3 of 3 on both hosts and, with the PR's source files frommainand the tests kept,guest_kqueueandguest_kernel_sysfail on both; at head9226e7bd6cmerged ontomain9f386f3a29(the current head3bc62ee2b7is a later merge ofmain),guest_kqueueandguest_kernel_syspass 3 of 3 on both hosts and fail withmain's sources, and thefchmod(kq, 0644)check givesEINVALon Linux too, with/dev/nullstillcrw-rw-rw-after the runs. Behaviour on the console itself is not measured; the reference is FreeBSD 11.4 source.Overlap
This touches
Stdio.cppandGuestKqueue.cpplike #10014 (read/write/lseek/fsync/flock on a kqueue) andDescriptorControl.cppandGuestKernelSys.cpplike #9994 (fchdir on a kqueue). The three are independent changes in what they do, but two of them conflict in the test file. Measured withgit merge-tree --write-treeon the current heads (#9994c76ff24b4d, #100145ba5164c72, this head22a5b6db47; each on its own base, the merge base git found for the pair):GuestKqueue.cpp(both add a test function and a call next to each other inmain); all three together: the same one conflict.The earlier dependency on #10014 no longer applies: #10014 was merged on 2026-11-02 at 17:26 UTC. The conflict with it, in
GuestKqueue.cpp(the errno constants and the call list inmain), is resolved inc1716688cb.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:33:09Z.
Review: APPROVED
Reviewed the exact diff and submitted Windows test report. Kqueue metadata is handled before the placeholder host descriptor path:
fstat/sceKernelFstatzero the structure and reportS_IFIFO; ioctl returnsENOTTYafter the existing close-on-exec commands are handled;fchownreturnsEINVAL. The added tests cover the metadata, FIONREAD, and fchown paths. The PR reports focused and 116-test Windows results with a red control, and explicitly leaves console behavior unmeasured. Current-main conventions and diff checks pass; hosted convention/intake/labels pass, while product jobs skip under current path policy. No blocking issue found in the reviewed scope.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T05:59:08Z.
Review: COMMENTED
macOS test: Apple M2 Max, macOS 27.2
Apple M2 Max, macOS 27.2, Apple clang (Xcode 27), x86-64 Release build under Rosetta 2,
BUILD_TESTING=ON. Headb7caab1f11.maindoes not build on macOS, so the platform is #8658 (feat/macos-port) @fa063d8b07with this PR's diff applied (clean apply).On macOS the kqueue placeholder is also
/dev/null(a character device), sofstatandfchownanswered for the host device without the change.guest_kqueueguest_kernel_sysBoth new cases catch the bug on macOS, and the fix holds there.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T23:07:28Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The reported Windows and Linux tests cover head
d58a78540e3054325beb72bb1cde7c1bd4d61bdf, but it now conflicts with currentmaininGuestKqueue.cpp.What I ran
Reviewed head
d58a78540e3054325beb72bb1cde7c1bd4d61bdfagainst PR base84e91df41864e18869c289420d5e1696ed5d1291; currentmainisdc38224141e0b6096007b876b4c42fc9144d11b8. The merge preview is conflicted. Local checks ran in Linux; no compiler or build was invoked.Results
core/libs/tests/GuestKqueue.cppguest_kqueue,guest_kernel_sysand related tests pass on Windows/WSL2 on this head; not independently run hereUnedited local check output
Findings
Blocking
GuestKqueue.cpp, so the PR cannot be integrated as-is. Please preserve both the currentmaintest changes and this PR's kqueue coverage, then rerunguest_kqueueon the rebased head.Non-blocking
The implementation and Linux
fchmodregression evidence are described in the prior report; I did not independently rerun those tests.Sources
Not verified
No local build or tests, console behavior, or current-main merged test run was performed. Hosted product Linux and Windows jobs skipped.
To get this to a good state
Please resolve the
GuestKqueue.cppconflict against currentmainand rerunguest_kqueueon the new head. I will rerun the merge preview, diff check and conventions on that revision.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T23:46:54Z.
Review: APPROVED
Re-checked — new head, looks good
The helper rename and latest merge resolve the
GuestKqueue.cppconflict; the current-main preview is clean and the kqueue-specific error handling and regressions remain in the diff.What I ran
dd1a7c9efc734b4c127a8b4f36284ca74fde6b88; recorded PR base:58f6cff97a274f1f24755966d9d81fd8e8aa9bf5.upstream/main:1189ec3003672bb364dd9f3119ead7b3976e3c83; preview merged cleanly as treea5d9a85ccfb63338e74b20317499130066e66e2f.Results
git diff --checkUnedited local command output
Not verified
I did not run local tests or a build. The current hosted Linux product job was skipped. The earlier author-run Linux
guest_kqueueandguest_kernel_sysresults apply to the prior implementation head; the current code update changes the helper name and rebases the same behavior ontomain. The exact-head Windows run passed.Sources