fix(libkernel): fail getdents on a descriptor that is not open with EBADF #4999
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4999"
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-13T07:41:27Z.
What
On Windows,
getdents,getdirentriesandsceKernelGetdents/sceKernelGetdirentriesansweredENOTDIR(20) for a descriptor that is not open. FreeBSD 11.4'skern_getdirentriestakes the descriptor withgetvnodefirst, andgetvnodefails an invalid descriptor (-1, closed, never opened) withEBADF(9).ReadDirectoryDescriptornow returnsEBADFwhen the descriptor is not open and keepsENOTDIRfor an open descriptor that is not a directory.An existing assertion changes with it:
GuestDirectoryBuffer.cppexpectedENOTDIRforsceKernelGetdents(-1, …). That check came in with the undersized-buffer work, where the descriptor argument was not the subject, and it records what the code answered rather than a source for the number. It now expectsEBADF, and the test also covers a closed descriptor,getdirentriesand the POSIX forms.Not changed, and listed in the TechnicalDebt entry for libkernel: for an open descriptor that is not a directory (and for a pipe or socket) the code still answers
ENOTDIR, where FreeBSD'skern_getdirentriesanswersEINVAL(vp->v_type != VDIR;getvnodeon a non-vnode). The console's answer is not known, so these were left as they were; the test therefore no longer pinsENOTDIRfor an open plain file.No title evidence: found by calling
getdentswith invalid descriptors and comparing with the FreeBSD source. This is FreeBSD conformance.Overlap (checked with
git merge-treeagainst the heads of #4796, #4920, #4922, #4929, #4968, #4989 and #4993): no conflict. The new TechnicalDebt entry sits next to the Windows directory descriptors entry, not at the end of the file, so it does not collide with the entries other PRs append there. No new test file, so no CMake change. Since then #5253 (getdirentriesbasep) conflicts with this PR indocs/dev/debt/libkernel.md(git merge-treeagainstmain8cf6a0bc3, both clean againstmain) and changes the sameextern "C"block ofGuestDirectoryBuffer.cpp; whichever lands second rebases the debt entry.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, in a combined build on
main0214069e3:guest_directory_bufferpasses with the new checks (the test declaresgetdents_nid_postfixand__error_nid_postfixitself:mainremoved them from the file'sextern "C"block in the meantime, and without the declarations the test does not compile); theguest_directory*,guest_fdopendir,guest_file*andguest_filesystemtests pass.DirectoryDescriptor.cppit fails at thegetdents(-1)check (Directory buffer check failed at line 71).python tools/check_conventions.py --base upstream/mainpasses.main0214069e3:guest_directory_buffertakes 0.07 s (ctest, serial, Windows). The fullguest_*/ libc / libkernel group passes with this branch in the combined build (394 of 394, 0 failed; the build also contains the other branches of this series).DirectoryDescriptor.cppis the Windows implementation; the Linux path answers with the host's error), a console, a title run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (docs/dev/debt/libkernel.md).mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T16:19:51Z.
Tested on Linux x86-64 (Ubuntu 24.04 in a Colima VM with Rosetta on Apple M4, GCC 13.3), this PR (
ae37373a9) merged intomain39890031e, Release build withBUILD_TESTING=ON.ctest: 1062/1069 pass, including the tests incore/libs/tests/GuestDirectoryBuffer.cpp. The only failures are the 7 that also fail onmainin this environment (Rosetta and VM limits:guest_math,amd64_only_converter,agc_driver_depth_compare_copy,tls_function_coverage_register_address_loads,linux_executable_exports,linux_entry_argv,linux_input_program_headers). No new failures.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T21:18:27Z.
Thank you for the Linux test, @simonbronk.
One correction for the record: the head you tested (
ae37373a9) has been replaced by39d610155. Aftermain'sd31e28308removed the unusedgetdents_nid_postfixand__error_nid_postfixdeclarations fromGuestDirectoryBuffer.cpp, the earlier head would not compile once merged withmain(the merged test calls two functionsmainno longer declares); the new head declares both in the test. The code change (ReadDirectoryDescriptoransweringEBADFfor a descriptor that is not open) is the same. The description now states this, and that for an open descriptor that is not a directory the code still answersENOTDIRwhere FreeBSD answersEINVAL(listed in the TechnicalDebt entry).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:13:15Z.
Closing: no title is known to reach this. With the queue at 750 open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed