fix(libkernel_sys): fail fchdir on a pipe or socket with EINVAL #9131
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9131"
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-21T12:48:01Z.
What
fchdirreturnedENOTDIRfor a pipe or a socket. FreeBSD 11.4'ssys_fchdirresolves the descriptor withgetvnode, which fails withEINVALfor a descriptor without a vnode; only a vnode that is not a directory getsENOTDIRfromchange_dir. A descriptor that is neither a vnode nor the random device now fails withEINVAL;EBADFfor a closed descriptor andENOTDIRfor a regular file are unchanged. Thefchdirdebt entry names the three errors.Tested
Windows 10 (19045), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, onmain865166414fplus this commit; Linux: WSL2 Ubuntu 24.04, GCC 13.3.0, Release, this head alone:ctest -R '^guest_kernel_sys$': Windows passes 3 of 3, Linux passes 3 of 3; withlibkernel_sys/Export.cpprestored tomain(the new pipe and socket cases kept) it fails (Windows exit code0xc00004093 of 3, LinuxSubprocess aborted).-R 'guest_kernel_sys|guest_filesystem$|guest_posix_filesystem|guest_kernel_rename|guest_dup|openat|directory|working_directory': 12 of 12 pass.python tools/check_conventions.py --base upstream/mainpasses;git merge-treeagainstmainis clean.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryAI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T18:14:03Z.
Review: CHANGES_REQUESTED
core/libs/prx/libkernel_sys/Export.cpp:363: the condition returnsEINVALfor every descriptor whereFile::IsVnodeis false.IsVnodeis true only for regular files and directories (DescriptorControl.cpp:586-595:S_ISREG/S_ISDIRon Linux,FILE_TYPE_DISKon Windows). A character device (tty,/dev/null,NUL, a console handle) is a vnode on FreeBSD, sogetvnodesucceeds andchange_dirreturnsENOTDIR. With this change those would now returnEINVAL, which is a new deviation from FreeBSD. Please scope it to what the title and #9130 describe: a pipe or a socket (e.g.S_ISFIFO/S_ISSOCKon Linux,FILE_TYPE_PIPEor the descriptor table's pipe/socket kind on Windows), and keepENOTDIRfor everything else.core/libs/tests/GuestKernelSys.cpp: once scoped, add a character device case that still expects 20 (ENOTDIR) so the narrower condition is pinned.docs/dev/debt/libkernel_sys.md:8: fine once the code matches; keep "pipe or socket".Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T19:43:50Z.
@adriadam10 thanks, you are right:
File::IsVnodeis false for a character device, so the first version returnedEINVALfor a tty,NULor/dev/nullwhere FreeBSD'sgetvnodesucceeds andchange_dirgivesENOTDIR.Pushed
77be50c54don top of the head you reviewed (no force push): theEINVALnow applies only when the descriptor is neither a vnode (File::IsVnode) nor a character device (newFile::IsCharacterDevice:FILE_TYPE_CHARon Windows with guest sockets excluded,S_ISCHRelsewhere) nor the guest random device; a pipe or socket getsEINVAL, everything else keepsENOTDIR. The debt line keeps "pipe or socket".guest_kernel_sysgets a/dev/randomcase that expectsENOTDIR; it pins the narrower condition but does not fail on the earlier head (the guest random device was already excluded there), so I did not find a case that distinguishes the two heads for a host tty.Windows 10 19045, WinLibs GCC 15.2.0 r7, Release, this head:
ctest -R '^guest_kernel_sys$'passes 3 of 3. (The pipe and socket cases failed without the change when I measured them on the first head: exit code0xc0000409, 3 of 3; I did not repeat the run without the change on this head.) The kernel_sys, filesystem, posix_filesystem, rename, dup, fcntl and file_lock tests pass (12 of 12).check_conventionspasses;git merge-treeagainstmainis clean. Linux (WSL2 Ubuntu 24.04, GCC 13.3.0, Release, this head alone):guest_kernel_syspasses 3 of 3; withlibkernel_sys/Export.cpprestored to the merge-base it fails (Subprocess aborted).Not tested: macOS, a console.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T22:47:14Z.
Code review location:
core/libs/tests/GuestKernelSys.cpp; line 374The implementation now preserves
ENOTDIRfor character devices viaIsCharacterDevice, but this test opens/dev/random, which is also explicitly excluded by!File::IsRandomDevice(fd)in thefchdircondition. It would still pass if the new character-device check always returned false. Could you add an ordinary character device case (/dev/nullon POSIX andNULon Windows, if available) so the branch that fixed the review finding is directly covered? The existing regular-file assertion already pins theENOTDIRpath for vnodes.