Repository navigation
fix(libkernel): check vector I/O lengths and descriptors before offsets - #9732
adriadam10 merged 1 commit into
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
I checked the reported overlap with #8726 manually. The code changes are independent, but the pairwise merge conflicts in |
There was a problem hiding this comment.
The vector-length and descriptor/offset precedence changes are supported by a detailed focused regression report. The branch is 4 commits behind current main. The pairwise merge with #8726 conflicts in docs/dev/debt/libkernel.md, although the code topics are independent; coordinate the order and preserve both debt entries. Product Linux/Windows jobs are skipped on the current PR.
I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
MarcZX10
left a comment
There was a problem hiding this comment.
The new SSIZE_MAX ordering and the closed-descriptor/pipe cases are supported by the reported focused run. I found an uncovered error-precedence gap in the negative-offset handling.
PositionedArgumentError(d, false, offset) does not check the descriptor's read/write access mode or general seekability. With a negative offset, an open descriptor that is neither a guest socket nor a pipe falls through to EINVAL. That means preadv on an O_WRONLY descriptor and pwritev on an O_RDONLY descriptor return EINVAL, where FreeBSD 11.4 checks fget_read/fget_write first and returns EBADF. Likewise, a negative offset on a non-seekable descriptor other than a pipe/socket can return EINVAL instead of ESPIPE. FreeBSD's ordering is visible in kern_preadv and kern_pwritev; fget_read/fget_write request the corresponding access flags in kern_descrip.c.
Please add focused cases for a read-only and write-only descriptor with negative offsets, and for a representative non-seekable descriptor other than a pipe/socket, then order the checks to match FreeBSD. The existing tests cover a closed descriptor and a pipe, but neither verifies descriptor access mode.
I also checked the refreshed repository state. The PR is still based on 4777caca (54 commits behind current main b7d1d47a), and Stdio.cpp has since changed on main. Please rebase and rerun the focused test on that base. The earlier request to coordinate the adjacent debt-line edit with open #8726 remains unresolved.
Checks run locally on this exact head: g++ -std=c++20 -fsyntax-only passed for Stdio.cpp and GuestFileVector.cpp; diff-check and conventions passed. A host POSIX probe returned EBADF for preadv(O_WRONLY, offset=-1) and pwritev(O_RDONLY, offset=-1); this is not a PS5 or FreeBSD runtime test. No configured build is available here, so I could not run guest_file_vector. The PR's 14-case run on its older base remains author-reported.
|
I’ve noticed that asking you to hold this PR was unnecessary. It’s fine to keep submitting PRs; maintainers will handle them in due course. |
eb900c3 to
acac3b1
Compare
|
@MarcZX10 thanks, you were right on both points. Rebased on
The 16 new checks fail on the previous head and pass here; the Tested section has the runs. One gap I left in the debt entry: FreeBSD lets a negative offset through on a AI-assisted: yes |
|
Hey folks, I picked up the Windows validation for simonbronk's current fix. The error-ordering failures reproduce here, and the patch clears them on the pinned main revision below. Windows 11 Pro x64, build 26300; WinLibs GCC 15.2.0 r7; Release,
The 21 failing checks are eight access-mode cases, four closed-descriptor cases, four negative-offset pipe cases and five negative-offset kqueue cases. The six oversized-vector checks and three nonnegative-offset kqueue checks already pass on Windows, so the Linux failure count should not be reused for this platform. The diagnostic overlay only lets those 30 checks continue after a failure. All existing assertions and the four new setup/correct-direction controls stay fatal. It is separate from the proposed patch, and I removed it before the final full build and 19-test run. The final checkout is clean. Receipts include source hashes, executable hashes and both patched and actual unpatched The 19 tests cover vector I/O and buffer protection, filesystem, AIO (including bad descriptors), fcntl, append streams/writes, UDP/TCP, socket read/write and descriptor handling, kqueue, random devices and all three app-archive modes. Full CTest, Linux, physical PS5 measurements and title execution were not run in this check. The FreeBSD reference and character-device gap remain as documented. The adjacent #8726 debt-entry ordering still needs the authors' agreement; this run does not settle it or validate a combined stack. Main advanced to This is simonbronk's fix; I'm contributing the Windows comparison and logs. AI-assisted, with a separate review of the raw results before posting. AnyPS5-9732-Windows-validation-20261023-v2.zip ZIP SHA-256: |
acac3b1 to
7a3f27c
Compare
Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7a3f27c to
88e86a7
Compare
|
Checked the argument order against FreeBSD 11.4 ( |
What
Argument checks in libkernel's vector and positioned I/O now run in the order FreeBSD 11.4 uses:
readv,writev,preadv,pwritevand theirsceKernelforms fail withEINVALwhen the iovec lengths add up to more thanSSIZE_MAX, before the descriptor is looked up, ascopyinuiodoes. Only the Windows path had this check. On Linux a closed descriptor gaveEBADF, and guest sockets, the random device and archived files received the oversized table.kern_preadvandkern_pwritevget the file withfget_read/fget_write, then returnESPIPEfor a file withoutDFLAG_SEEKABLE, and only thenEINVALfor a negative offset.preadvandpwritevchecked the offset first. They now usePositionedArgumentError, the checkpreadandpwritealready use, on Linux and Windows, and that check now follows the same order for all eight functions:EBADFfor a closed descriptor, and for a file, directory or character device that is not open in that direction (a negative offset or a null buffer on anO_RDONLYdescriptor throughpwrite/pwritev, orO_WRONLYthroughpread/preadv, gaveEINVALorEFAULT);ESPIPEfor anything that is not a vnode, character device or the random device: pipes, guest sockets and kqueues. A kqueue gaveEINVALfor a negative offset and read 0 bytes from its host/dev/nullplaceholder otherwise, so it now getsESPIPEfor every offset. FreeBSD marks pipes, sockets and kqueues readable and writable, so none of them reaches the access check;EINVALfor a negative offset, orEFAULTfor a null buffer.File::GrantsAccessreads the host descriptor's access mode through the helperfcntl(F_GETFL)already uses. FreeBSD passes a negative offset on a character device to the driver instead of rejecting it; that still returnsEINVALhere and is in the debt entry. Nothing is measured on a PS5; thereadvdebt entry says these rules follow FreeBSD.Tested
Linux, Ubuntu 24.04 x86-64 container under Rosetta on Apple silicon (Colima), GCC 13, RelWithDebInfo with ASan.
guest_file_vectornow has 30 checks for this change: the 14 from before (a closed descriptor and a pipe with offset -1, a table totallingSSIZE_MAX + 1bytes) and 16 new ones:O_RDONLYfile throughsceKernelPwriteandsceKernelPwritev/pwritevwith offset -1, andpwritewith a null buffer; anO_WRONLYfile the same way through the read forms; each expectsEBADF, and the opposite direction with offset -1 still getsEINVAL;sceKernelPreadv,sceKernelPwritev,preadvandpwritevwith offset -1 and 0,sceKernelPreadat 0 andpwriteat -1, each expectingESPIPE.Run with the test's abort turned off to list the failing checks, all on
maina6fc8a4:mainwith only the new test file: the 30 checks fail.cmake --build --target libkernel guest_file_vector_testsexits 0 andguest_file_vectorpasses.The branch was then rebased onto
maind6e7ab4; its 6 newer commits touch none of the changed files, and the only change since the runs is the shortened debt sentence.From the full build of this branch,
guest_file_vector_memory,guest_aio,guest_udp,guest_tcp,guest_socket_read_write,guest_socket_descriptors,guest_socket_descriptor_flags,guest_kqueue,guest_kernel_fcntl,guest_random,guest_posix_random,guest_filesystem,guest_append_streams,guest_append_writes, the threeguest_kernel_app_archivemodes and fiveguest_named_shmtests pass.guest_named_shm_concurrency(the container runs as root, sounlinkof a read-only object gets noEACCES) andguest_closed_standard_descriptors(child exits with 74) fail the same way onmaina6fc8a4. The only build error on both is the existingatrac9_gradient_testslink failure.Windows not built or run; the Windows
sceKernelPread/sceKernelPwriteandTransferIovecspaths change, andGrantsAccessuses the Windows access helperfcntl(F_GETFL)uses. A guest socket with a negative offset and a character device have no test here.check_conventions.py --base origin/mainpasses.pr_overlap.pyreports no PR with the same change, only #8726 next to the edited debt line. No title tested.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)🤖 Generated with Claude Code