Skip to content

fix(libkernel): return EFAULT for unreadable iovec tables - #8743

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
valenciana-nc:fix/kernel-iovec-table-copy
Oct 21, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
valenciana-nc:fix/kernel-iovec-table-copy

Conversation

@valenciana-nc

Copy link
Copy Markdown
Contributor

What

readv, writev, preadv, pwritev, _readv, _writev and their sceKernel forms 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 returning EFAULT.

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: ReadProcessMemory on Windows, process_vm_readv on Linux and mach_vm_read_overwrite on 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 copyinuio and its sys_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 than EFAULT throw 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/libc and the relevant test targets were rebuilt on both hosts. Final branch based on e28d386d4.

  • Added 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 guest EFAULT, 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.
  • Negative control on main 7e95bde79: retain the regression and restore only main's Stdio.cpp. Running each entry point separately gives 10/10 access violations (0xc0000005) on Windows and 10/10 SIGSEGVs on Linux. The seven existing focused tests pass with the original implementation. Restoring the fix makes the new and existing tests pass.
  • Final Windows focused suite: 12/12 passed (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).
  • Final Linux focused suite: 17/17 passed, including the same tests plus named shared-memory open, lifecycle, descriptor reuse, permissions and I/O descriptor reuse.
  • Both vector tests also passed three consecutive runs on each host.
  • git diff --check and conventions checks passed. The required --base origin/main invocation reports two existing debt-length warnings from upstream changes; checking against upstream/main is clean. Ran tools/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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6149 docs/dev/debt/libkernel.md
PR 6226 core/libs/prx/libkernel/CMakeLists.txt
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6586 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6879 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 6977 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7509 docs/dev/debt/libkernel.md
PR 7530 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 7532 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8520 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 8523 docs/dev/debt/libkernel.md
PR 8626 core/libs/prx/libkernel/CMakeLists.txt
PR 8658 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@xXPBSXx

xXPBSXx commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

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 main 339217e is clean. I built only guest_file_vector_memory_tests; ctest -N -R guest_file_vector_memory lists exactly one test.

Results (3 runs each):

  • PR head: guest_file_vector_memory passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libkernel/File/src/Stdio.cpp with the version from the PR's merge base (e28d386d45), then rebuilt. The test crashes 3/3 (ctest reports SEGFAULT). I restored the PR's Stdio.cpp afterwards.

Not run: other platforms, the other file tests, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

@oneandonlydean
oneandonlydean merged commit 8a803d3 into boykopovar:main Oct 21, 2026
11 checks passed
@valenciana-nc
valenciana-nc deleted the fix/kernel-iovec-table-copy branch October 21, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants