Repository navigation
fix(libkernel): fail ftruncate and getdirentries on a file read from app0.zar with EINVAL, as FreeBSD 11.4 does - #22298
Merged
oneandonlydean merged 1 commit intoNov 17, 2026
Conversation
…app0.zar with EINVAL, as FreeBSD 11.4 does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ycbuzi
added a commit
to ycbuzi/AnyPS5
that referenced
this pull request
Nov 17, 2026
PrivacyOnion
approved these changes
Nov 17, 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 caf24688e9:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_kernel_app_archive_testsbuilt cleanly. - CTest (
guest_kernel_app_archive_archive,guest_kernel_app_archive_plain,guest_kernel_app_archive_mmap):1/3 Test #5502: guest_kernel_app_archive_plain ..... Passed 0.05 sec 2/3 Test #5501: guest_kernel_app_archive_archive ... Passed 0.07 sec 3/3 Test #5503: guest_kernel_app_archive_mmap ...... Passed 0.04 sec 100% tests passed, 0 tests failed out of 3 - Negative control: with
core/libs/prx/libkernel/File/src/Stdio.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/3 Test #5502: guest_kernel_app_archive_plain ..... Passed 0.04 sec 2/3 Test #5503: guest_kernel_app_archive_mmap ...... Passed 0.03 sec 3/3 Test #5501: guest_kernel_app_archive_archive ...Subprocess aborted***Exception: 0.40 sec 67% tests passed, 1 tests failed out of 3 - Code reading:
- Checked Stdio.cpp:1220 ftruncate_nid_postfix correctly returns PosixFailure(GUEST_EINVAL) when File::IsArchivedFile(d) is true, matching FreeBSD 11.4 kern_ftruncate descriptor write-permission requirements.
- Checked Stdio.cpp:1464, 1511, 1593 sceKernelGetdirentries overloads on Windows, macOS, and Linux to ensure File::IsArchivedFile check precedes buf/nbytes validation and returns SceErrorFromErrno(GUEST_EINVAL), matching FreeBSD kern_getdirentries non-directory vnode check.
- Verified error code conversions between PosixFailure(GUEST_EINVAL) (-1 with errno=22) and sceKernel error codes (SCE_KERNEL_ERROR_EINVAL = 0x80020016) for both POSIX and sceKernel variants.
- Audited GuestKernelAppArchive.cpp:432-443 test cases to ensure ftruncate, sceKernelFtruncate, getdirentries, sceKernelGetdirentries (with valid buf, null buf, and zero size), and sceKernelGetdents are verified against archived file descriptors without modifying basep.
- Verified strict compliance with AGENTS.md conventions: no comments added, no hardcoded title IDs or special cases, and no extraneous files added.
Looks Good To Me
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
ftruncate,sceKernelFtruncate,getdirentries,sceKernelGetdirentriesandsceKernelGetdentsthrew on a descriptor of a file read from app0.zar. In FreeBSD 11.4 these fail withEINVALwhatever the filesystem:kern_ftruncate(sys/kern/sys_generic.c) refuses a descriptor opened withoutFWRITE, and an archived file can only be opened read-only, since other modes fail withEROFS.kern_getdirentries(sys/kern/vfs_syscalls.c) refuses a vnode that is notVDIR, and archived directories are not opened through this path.ftruncatenow returnsEINVALfor an archived file after its existing length and socket checks.getdirentriesreturnsEINVALfor an archived file before it looks at the buffer, askern_getdirentriesrejects the vnode before any copyout. A null buffer or a size of 0 therefore givesEINVALtoo. A host regular file still getsEFAULTfor a null buffer first; that ordering is unchanged here.GuestKernelAppArchive.cpp: inRefusals, theftruncateandgetdentsthrow checks becomeEINVALchecks forftruncate,sceKernelFtruncate,sceKernelGetdents,sceKernelGetdirentries(with a buffer, with a null buffer and with size 0, each leaving*basepalone) andgetdirentries.fsync,fdatasync,fchmod,futimes,flock,fstatfsandfdopenon an archived file still throw, as their answers depend on the console's/app0filesystem.Tested
Linux (Debian 13, GCC 14.2.0, Release), on
main47b33132f9.ctest -R '^(guest_kernel_app_archive.*|guest_kernel_fcntl.*|guest_filesystem.*|guest_file.*)$': 10 passed.main,guest_kernel_app_archive_archiveaborts withftruncate on a file read from app0.zar, fd=7 not implemented.ctest(6000 tests,-j 12) on this branch and my other five branches of this round, merged ontomain47b33132f9: 5985 passed. All 15 failures also fail onmainin the same 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_drivercases (agc_driver_image_table_packed_guardspasses when run on its own).python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branchfailed closed on feat(libkernel): support SEEK_DATA and SEEK_HOLE in lseek #6936, feat(libkernel): report open, read and close notes on watched files #7121, feat(libc): support archive-backed stdio reads #7447, feat(libkernel): implement the named ksem semaphores #9293, feat(libkernel_sys): implement POSIX message queues #9297, feat(libkernel_sys): implement kmq_notify registration #9302, feat(libkernel): cancel blocked POSIX reads with owned operations #12682, fix(libkernel): preserve blocking sockets over nonblocking native transport #12688, feat(libkernel): cancel blocked POSIX writes with partial progress #12700 and feat(libkernel): support deferred cancellation in POSIX accept #12965, which conflict withmain. None of their diffs changes these refusals. feat(libc): support archive-backed stdio reads #7447 (archive-backed stdio) adds a line next to theftruncaterefusal and keeps the throw for archived files, so the two conflict textually.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)