Repository navigation
fix(libkernel): fail EVFILT_READ and EVFILT_WRITE on the random device with ENODEV, as FreeBSD 11.4 does - #24482
Merged
oneandonlydean merged 1 commit intoNov 21, 2026
Conversation
…e with ENODEV, as FreeBSD 11.4 does kevent, sceKernelAddReadEvent and sceKernelAddWriteEvent threw for read and write events on /dev/random and /dev/urandom. FreeBSD 11.4 attaches these filters through the file's fo_kqfilter; devfs passes it to the device's d_kqfilter, which random_cdevsw leaves unset and prep_cdevsw fills with enodev. kqueue_register clears fflags before the attach, so the error event has fflags 0 and ENODEV in data. The check now comes before the standard input shortcut, so a random device duplicated onto descriptor 0 answers the same, and the two equeue calls check a bad queue first, as kern_kevent fetches the kqueue before the attach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 tasks done
PrivacyOnion
approved these changes
Nov 20, 2026
PrivacyOnion
left a comment
Contributor
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 0c7dd7b9cb:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_kqueue_testsbuilt cleanly. - CTest (
guest_kqueue,guest_kqueue_cleared_race):1/2 Test #5877: guest_kqueue ..................... Passed 5.57 sec 2/2 Test #5878: guest_kqueue_cleared_race ........ Passed 20.80 sec 100% tests passed, 0 tests failed out of 2 - Negative control: with
core/libs/prx/libkernel/Equeue/Equeue.cpp,core/libs/prx/libkernel/Equeue/src/Kqueue.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/2 Test #5877: guest_kqueue .....................Subprocess aborted***Exception: 2.68 sec 2/2 Test #5878: guest_kqueue_cleared_race ........ Passed 26.92 sec 50% tests passed, 1 tests failed out of 2 - Code reading:
- Verified sceKernelAddReadEvent and sceKernelAddWriteEvent validate EqueuePin_nid_postfix(eq) before returning SCE_KERNEL_ERROR_ENODEV or SCE_KERNEL_ERROR_EBADF, matching libkernel queue validation semantics.
- Verified AddDescriptorKnote in Kqueue.cpp checks File::IsRandomDevice(descriptor) and returns GUEST_ENODEV while clearing change.fflags and change.data to 0 according to FreeBSD 11.4 kqueue_register behavior.
- Verified error handling in kevent when EV_ERROR is returned in change/eventlist matches the expected struct fields without uninitialized data or improper state mutation.
- Verified guest_kqueue tests cover /dev/random, /dev/urandom, EVFILT_READ, EVFILT_WRITE, EV_DELETE (returning GuestEnoent), bad queue handle checks, and descriptor 0 redirection.
- Verified technical debt documentation fragment in docs/dev/debt/changes/fix-libkernel-kevent-random-device-enodev.md conforms to AGENTS.md requirements without forbidden comments in code.
Looks Good To Me
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
kevent,sceKernelAddReadEventandsceKernelAddWriteEventthrew for read and write events on/dev/randomand/dev/urandom. FreeBSD 11.4 attaches these filters through the file'sfo_kqfilter: devfs passes it to the device'sd_kqfilter, whichrandom_cdevswleaves unset andprep_cdevswfills withenodev.EVFILT_READandEVFILT_WRITEfail withENODEV.kqueue_registerclearsfflagsbefore the attach, so the error event hasfflags0 andENODEVindata.sceKernelAddReadEventandsceKernelAddWriteEventanswerENODEVin their export wrappers, afterEBADFfor a bad queue, askern_keventfetches the kqueue before the attach.AddDescriptorEvent, which feat(libkernel): add pipe write events and socket low watermarks to sceKernelAdd*Event #10645 rewrites, is not touched; this merges with feat(libkernel): add pipe write events and socket low watermarks to sceKernelAdd*Event #10645 without overlap.EVFILT_PROCDESCthere still throws, as fix(libkernel): handle kevent timer re-adds and the AIO, LIO, SENDFILE and PROCDESC filters as measured on a PS5 #7653 limited it to measured kinds, andEVFILT_VNODEandsceKernelAddFileEventstill watch the host device, where FreeBSD fails withENODEVas well.RandomDeviceReadWriteinGuestKqueue.cpp, for both devices, throughkeventwith and without an event list,EV_DELETEafterwards, the two equeue calls, and a random device on descriptor 0.Tested
Linux (Debian 13, GCC 14.2.0, Release). Head
0c7dd7b9cb, the single commit onmainc8f72e905c.main84e16538d4,guest_kqueueaborts withkevent: EVFILT_READ on a descriptor that is neither a socket nor the read end of a pipe not implemented.0c7dd7b9cb,ctestoverguest_kqueue,guest_equeue_events,guest_randomandguest_kernel_sys_ksem: all pass.ctest(6393 tests,-j 12) on this branch and my other eleven branches of this round, merged ontomain84e16538d4: 6378 passed. The 15 failures also fail onmainin this environment:.gitdirectory, network access or a passwd entry for the user:conventions_git_errors,test_script_registration,web_library_assets,title_run,title_run_identity,guest_kernel_sys_login,guest_net_ctl,guest_getloginandguest_getlogin_no_session;agc_driverGPU cases fail the same way onmain:prepared_shaderswith itsindirect,uncachedanddebugforms, andstorage_file_write;agc_driver_image_table_packed_guardsis unstable onmainas well (2 of 10 runs passed on its own onmain3f4693be43).python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch fix/libkernel-kevent-random-device-enodev: could not compare feat(libkernel): report open, read and close notes on watched files #7121 (Kqueue.cpp,GuestKqueue.cpp) and feat(libkernel): implement the named ksem semaphores #9293, feat(libkernel_sys): implement POSIX message queues #9297 and feat(libkernel_sys): implement kmq_notify registration #9302 (Equeue.cpp), which conflict withmain; none of their diffs touchesAddDescriptorKnoteor the two equeue wrappers.git merge-treewith feat(libkernel): add pipe write events and socket low watermarks to sceKernelAdd*Event #10645's head is clean.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)