fix(libkernel): answer fstat and fchmod on a ksem id as FreeBSD 11.4's ksem_stat and ksem_chmod do #24491
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24491"
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 brajankw on 2026-11-20T17:29:10Z.
What
A ksem id is a host null device descriptor here, so
fstatreported the host's/dev/null, andfchmodcalled the host'sfchmodon it, which as root changes the mode of the host's/dev/null. FreeBSD 11.4 answers both from the semaphore:ksem_creategivesksem_init's semaphoreS_IRWXU | S_IRWXGunder the umask, owned by the caller (ksem_alloc); the owner isgetuid/getgid, both 0 here.ksem_statreports a zeroed stat withS_IFREG, that mode, the owner and the four times.ksem_chmodkeeps the mode'sACCESSPERMSbits and changes no time.vfs_timestampdoes by default: all four at creation, the change time onksem_post(L733), and the access time on every wait, before the count is checked, so a failingksem_trywaittoo (L820), and onksem_getvalue, also when its copy-out then fails (L888).fstatwhether a descriptor is a regular file, which a ksem id would now pass. They ask a new exportedIsKsemDescriptor_nid_no_patchinstead, as AIO is in libkernel_sys:sceKernelAddReadEventandsceKernelAddWriteEventkeep their throw on a ksem id,aio_readkeepsEOPNOTSUPP(aio_queue_file), andaio_fsyncnow getsEINVAL(aio_aqueue) where it gotEOPNOTSUPP.IsKsemDescriptor_nid_no_patchhas its own body and does not callIsKsemDescriptor, which open #22191 replaces, so this merges with #22191 and with my other ksem PRs without overlap, in any order.ksem_openwith(void)mode; on top of this, it would need to keep its mode asksem_initnow does.MetadatainGuestKernelSysKsem.cpp, through_fstatandsceKernelFstat,fchmodandsceKernelFchmod, the times after post, waits andksem_getvalue, and the two equeue calls; the ksem cases inGuestKernelSysAio.cpp. Thefstatchecks come first, so onmainthe test fails before it callsfchmod.Tested
Linux (Debian 13, GCC 14.2.0, Release). Head
f9c7ef4e59, the single commit onmainc8f72e905c.main84e16538d4,guest_kernel_sys_ksemfails at the newst_modecheck, before anyfchmod.f9c7ef4e59,ctestoverguest_kernel_sys_ksem,guest_kqueue,guest_kernel_sys,guest_filesystem,guest_file_vector,guest_kernel_sys_aio,guest_equeue_events,guest_kernel_fcntl,guest_kernel_ioctl_fionreadandguest_kernel_ioctl_device_type: all 10 pass.ctest(6393 tests,-j 12) on this branch before review, which then added the equeue and AIO exclusions and theksem_getvalueaccess time, 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-ksem-fstat-fchmod: could not compare #6936, #7121, #7447, #9293, #9297, #9302, #12682, #12688, #12700, #12965 and #15037, which conflict withmain. #9293, #9297 and #9302 carry older copies of the ksem files; #9293'sksem_openis noted above.git merge-treewith #22191, #10645 and my other ksem branches 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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T17:51:34Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f9c7ef4e59:tools/check_conventions.pypassed.guest_kernel_sys_aio_tests,guest_kernel_sys_ksem_testsbuilt cleanly.guest_kernel_sys_ksem,guest_kernel_sys_aio):core/libs/prx/libkernel/Equeue/Equeue.cpp,core/libs/prx/libkernel/File/src/Stdio.cpp,core/libs/prx/libkernel/Semaphore/include/Ksem.hpp,core/libs/prx/libkernel/Semaphore/src/Ksem.cpp,core/libs/prx/libkernel_sys/Aio.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:54:33Z.
Review: APPROVED
Reviewed — looks good
The change was reviewed at head
f9c7ef4e59feebdc7c1ab3f2241939188bb3e0c7; the inspected implementation and tests support the stated ksem metadata behavior, and no blocking defect was verified.What I ran
No commands or tests were run. I inspected the prepared diff and targeted repository source through
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported Linux test runs, convention check, and negative control were not independently run. Windows, macOS, and physical console behavior were not verified.
review/files.jsonwas not available in the prepared review listing; the manifest lists seven changed files, all included and read. The source review covered the changed implementation, its directly relevant callers, and tests; it did not inspect unrelated repository code.To get this to a good state
Nothing is required.