fix(libkernel_sys): validate descriptor first in fchown #8457
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8457"
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 vaibhavindalia on 2026-10-20T12:53:04Z.
What
Validate the file descriptor before checking ownership arguments in
fchown_nid_postfix. If the descriptor is not open or invalid, return guestEBADF(-1 with errno 9). UseRequireGuestOwnerto maintain the fail-fastNotImplemented_nid_no_patchthrow for unmodeled owner or group values on valid descriptors, matchingchown,lchownandfchownat. Add regression tests inGuestKernelSys.cppcovering supported mixed values and invalid descriptor error precedence.Tested
Windows 11 (NT 10.0.26300), WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r7), Release, Ninja:
cmake --build build --target guest_kernel_sys_tests: compiled and linked cleanly.ctest --test-dir build -R "^guest_kernel_sys$" -V: 1/1 tests passed (0.11s, 100% tests passed, 0 failures).python tools/check_conventions.py --base upstream/main: All conventions checks passed.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 repositoryImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T15:03:21Z.
Thanks for this. Checking the descriptor first is right: FreeBSD 11 resolves the descriptor before it looks at the owner, so
EBADFshould win over an unsupported owner. TheEPERMpart doesn't fit the rest of the tree, though:getuidandgeteuidreturn 0 (core/libs/prx/libkernel/System/src/Process.cpp:297-303), and other libkernel_sys entries (for examplechroot) follow FreeBSD "for a root caller".ufs_chownreturnsEPERMonly whenpriv_check_cred(cred, PRIV_VFS_CHOWN, 0)fails (sys/ufs/ufs/ufs_vnops.c:795-797). A root caller passes that check, and jailed root keepsPRIV_VFS_CHOWN, so the reference answer forfchown(fd, 1, 0)from this guest is success, notEPERM.NotImplementedthrow is still the honest answer for a real owner change.Could you keep the descriptor check first, keep the throw for an owner or group other than 0 and -1, and adjust the tests to match? Another option is a console measurement showing that a title process really gets
EPERM. If you have one, please add it to the description and the debt entry, andEPERMcan stay.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T03:52:27Z.
Independent Windows run of this PR (data only).
Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against
mainis clean. I built onlyguest_kernel_sys_tests;ctest -N -R guest_kernel_syslists exactly one test.Results (3 runs each):
guest_kernel_syspasses 3/3.core/libs/prx/libkernel_sys/Export.cppwith the version from the PR's merge base (5f7aa5570c), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T09:45:15Z.
Linux data point for
2814d6c7cb: WSL2 Ubuntu 24.04 (a virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release,BUILD_TESTING=ON, PR head alone (not merged ontomain).ctest -R '^guest_kernel_sys$'passes 3 of 3.core/libs/prx/libkernel_sys/Export.cpprestored to the merge-base (new test cases kept): fails (Subprocess aborted).Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:51:18Z.
Review: COMMENTED
Checked against main
522e32e3b6and FreeBSD 11.4 sys/kern/vfs_syscalls.c / sys/ufs/ufs/ufs_vnops.c:RequireGuestOwner(Export.cpp:193-197), andchown,lchownandfchownat(Export.cpp:724-744) now look up the file first and then call it. Following @oneandonlydean's suggestion,fchowncan callRequireGuestOwner("fchown", uid, gid)after thefstatcheck, the same way those three do; the descriptor-first order is still needed, since main'sfchown(-1, 1, 0)throws before reaching EBADF.git merge-treeagainst main conflicts indocs/dev/debt/libkernel_sys.md, where main added thechown, lchown and fchownatentry right after the fchown line. That entry says ownership is handled "as forfchown", so keeping the throw also keeps the two entries consistent.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.