fix(libkernel): return EFAULT from direct memory queries for invalid memory pointers #13576

Merged
pushkarreddyy merged 3 commits from upstream-pr/13576 into main 2026-10-31 04:15:50 +00:00
pushkarreddyy commented 2026-10-30 18:36:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-30T18:36:35Z.


What

Fixes #13566.
sceKernelAvailableDirectMemorySize, sceKernelGetDirectMemoryType, and sceKernelDirectMemoryQuery directly dereferenced guest output pointers (phys_addr_out, size_out, memory_type, start, end, and info). When a guest passed a non-null pointer into unmapped or read-only memory, the host process crashed with SIGSEGV.

This change:

  • Uses GuestCopyOut_nid_no_patch to safely write output values to guest destination buffers in sceKernelAvailableDirectMemorySize, sceKernelGetDirectMemoryType, and sceKernelDirectMemoryQuery.
  • Returns SCE_KERNEL_ERROR_EFAULT (0x8002000e) when destination memory is inaccessible.
  • Adds regression unit tests covering invalid destination pointers in core/libs/tests/GuestMemory.cpp.
  • Documents the host-safety fallback in docs/dev/debt/libkernel.md.

Tested

  • Ran python tools/check_conventions.py --base origin/main.
  • Added unit tests in core/libs/tests/GuestMemory.cpp verifying that passing invalid memory pointers (0x10) returns SCE_KERNEL_ERROR_EFAULT.

Checklist

  • What
  • Tested
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5089313303 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13576). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-30T18:36:35Z. --- ### What Fixes #13566. `sceKernelAvailableDirectMemorySize`, `sceKernelGetDirectMemoryType`, and `sceKernelDirectMemoryQuery` directly dereferenced guest output pointers (`phys_addr_out`, `size_out`, `memory_type`, `start`, `end`, and `info`). When a guest passed a non-null pointer into unmapped or read-only memory, the host process crashed with `SIGSEGV`. This change: - Uses `GuestCopyOut_nid_no_patch` to safely write output values to guest destination buffers in `sceKernelAvailableDirectMemorySize`, `sceKernelGetDirectMemoryType`, and `sceKernelDirectMemoryQuery`. - Returns `SCE_KERNEL_ERROR_EFAULT` (0x8002000e) when destination memory is inaccessible. - Adds regression unit tests covering invalid destination pointers in `core/libs/tests/GuestMemory.cpp`. - Documents the host-safety fallback in `docs/dev/debt/libkernel.md`. ### Tested - Ran `python tools/check_conventions.py --base origin/main`. - Added unit tests in `core/libs/tests/GuestMemory.cpp` verifying that passing invalid memory pointers (`0x10`) returns `SCE_KERNEL_ERROR_EFAULT`. ### Checklist - [x] What - [x] Tested - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-30 21:31:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T21:31:45Z.

Review: COMMENTED


First Linux run of head a347c4ef7e, merged onto main 6472c708ae (clean merge). Ubuntu 26.04, i7-8700, GCC 15.2, Release, BUILD_TESTING=ON, Ninja.

  • guest_memory: passes 3/3.
  • public_headers: passes.
  • Red check: with only core/libs/prx/libkernel/DirectMemory/Export.cpp reverted to main (new test kept), guest_memory segfaults 3/3. So on Linux the new checks fail without the fix.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5718883381 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13576#pullrequestreview-5718883381). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-30T21:31:45Z. **Review:** COMMENTED --- First Linux run of head `a347c4ef7e`, merged onto `main` `6472c708ae` (clean merge). Ubuntu 26.04, i7-8700, GCC 15.2, Release, `BUILD_TESTING=ON`, Ninja. - `guest_memory`: passes 3/3. - `public_headers`: passes. - Red check: with only `core/libs/prx/libkernel/DirectMemory/Export.cpp` reverted to `main` (new test kept), `guest_memory` segfaults 3/3. So on Linux the new checks fail without the fix. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13576
No description provided.