Repository navigation
fix(libkernel): return EFAULT for unreadable iovec tables - #8743
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the current diff and error paths. The count bound is checked before the guest table is touched; zero-count calls avoid the pointer, address wraparound is rejected, and every nonzero path checks that the host copy completed before it inspects entries or performs I/O. The regression covers all ten exported entry points, including inaccessible/cross-page tables and state preservation. The author reports focused Linux and Windows builds/tests with a failing main-baseline control. I did not run a local build; hosted platform build jobs are skipped, and macOS runtime/build validation is not reported.
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the checked table-copy paths for Windows, Linux, and macOS, plus the new regression matrix covering inaccessible, cross-page, wrapping, and valid tables across the ten exported entry points. Copying the iovec array before dereferencing its guest-provided bases addresses the reported host crash while preserving later payload handling. The author reports focused suites passing on Linux and Windows and a negative control that faults before the fix. Eligibility, conventions, intake, labels, and report checks pass; hosted platform/runtime jobs are skipped, and macOS execution is not claimed.
|
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 Results (3 runs each):
Not run: other platforms, the other file tests, the full repository CTest, and any title or console run. AI-assisted (Claude Code). |
What
readv,writev,preadv,pwritev,_readv,_writevand theirsceKernelforms dereference the guest iovec table in host C++ before reaching the host I/O operation. A non-null unreadable table therefore terminates the process rather than returningEFAULT.Copy the bounded table into host-owned storage before inspecting its entries or dispatching file, random-device, archive, shared-memory or socket I/O. Prepare the table through the existing guest host-read hook, reject address wraparound, and require a complete checked copy:
ReadProcessMemoryon Windows,process_vm_readvon Linux andmach_vm_read_overwriteon macOS. Every later consumer uses the copy. A zero count does not touch the table; the existing count limit and POSIX/SCE error conventions remain intact.The expected table-copy behavior follows FreeBSD 11.4
copyinuioand itssys_readv/sys_writev/positioned variants. It has not been measured on a console. Payload-buffer validation is outside this change. Linux checked-copy errors other thanEFAULTthrow rather than being disguised as guest faults; this limitation is recorded in the library debt file.Overlap checking found no confirmed code conflicts after separating the initially adjacent include and debt additions from #8658 and #8359. Some already-conflicting PRs cannot be automatically compared; their shared-file patches were reviewed for this behavior. In particular #8663 changes scalar descriptor/error ordering, #7121 adds I/O notifications, #8520 adds archive directories, and the platform ports do not implement checked iovec-table copies. No prerequisite is required.
Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0; Linux Ubuntu 24.04 container, GCC 14.2. Production
libkernel/libcand the relevant test targets were rebuilt on both hosts. Final branch based one28d386d4.guest_file_vector_memory, covering all ten entry points: null and small invalid addresses, no-access pages, a table whose second entry crosses into no-access memory, an entry itself straddling that boundary, and wrapping addresses. Checks guestEFAULT, unchanged file contents/position and unchanged destinations. Also checks zero, negative and excessive counts; valid read-only tables; a readable table ending exactly at the page boundary; 1024 entries; read/write results; positioned offsets; and the table host-read hook.7e95bde79: retain the regression and restore only main'sStdio.cpp. Running each entry point separately gives 10/10 access violations (0xc0000005) on Windows and 10/10SIGSEGVs on Linux. The seven existing focused tests pass with the original implementation. Restoring the fix makes the new and existing tests pass.guest_filesystem, shared-memory open, socket read/write/pair/descriptors, recvmsg memory, archive/plain/mmap I/O, vector I/O, vector memory and fstat faults).git diff --checkand conventions checks passed. The required--base origin/maininvocation reports two existing debt-length warnings from upstream changes; checking againstupstream/mainis clean. Rantools/pr_overlap.py --branch fix/kernel-iovec-table-copy --base main --repo boykopovar/AnyPS5.No title improvement, full-suite result, GPU result or macOS runtime execution is claimed. Full Linux/Windows PR CI requires a maintainer to start the workflow. The container cannot use userfaultfd write watching, so that mode is not claimed.
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)