fix(libkernel): return EFAULT from module info and list queries for invalid memory pointers #13587

Merged
pushkarreddyy merged 3 commits from upstream-pr/13587 into main 2026-11-08 04:19:03 +00:00
pushkarreddyy commented 2026-10-30 18:52:06 +00:00 (Migrated from github.com)

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


What

Fixes #13569.
FillModuleList and FillModuleInfo (underlying sceKernelGetModuleList, sceKernelGetModuleList2, sceKernelGetModuleInfo, and sceKernelGetModuleInfo2), as well as sceKernelGetModuleInfoFromAddr, directly dereferenced and wrote through handles, actual, and info guest pointers. If a non-null invalid or unwritable guest address was passed, the host crashed with a segmentation fault (SIGSEGV).

This change:

  • Uses GuestCopyIn_nid_no_patch to safely validate st_size in FillModuleInfo.
  • Uses GuestCopyOut_nid_no_patch to safely write to handles, actual, and info destination buffers in FillModuleList, FillModuleInfo, and sceKernelGetModuleInfoFromAddr.
  • Returns SCE_KERNEL_ERROR_EFAULT (0x8002000e) if guest memory is unreadable or unwritable.
  • Adds regression unit tests in core/libs/tests/GuestModuleInfo.cpp covering unwritable handles, actual, and info pointers.
  • Updates documentation in docs/dev/debt/libkernel.md.

Tested

  • Ran python tools/check_conventions.py --base origin/main.
  • Added unit tests in core/libs/tests/GuestModuleInfo.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:5089502832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13587). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-30T18:52:06Z. --- ### What Fixes #13569. `FillModuleList` and `FillModuleInfo` (underlying `sceKernelGetModuleList`, `sceKernelGetModuleList2`, `sceKernelGetModuleInfo`, and `sceKernelGetModuleInfo2`), as well as `sceKernelGetModuleInfoFromAddr`, directly dereferenced and wrote through `handles`, `actual`, and `info` guest pointers. If a non-null invalid or unwritable guest address was passed, the host crashed with a segmentation fault (`SIGSEGV`). This change: - Uses `GuestCopyIn_nid_no_patch` to safely validate `st_size` in `FillModuleInfo`. - Uses `GuestCopyOut_nid_no_patch` to safely write to `handles`, `actual`, and `info` destination buffers in `FillModuleList`, `FillModuleInfo`, and `sceKernelGetModuleInfoFromAddr`. - Returns `SCE_KERNEL_ERROR_EFAULT` (`0x8002000e`) if guest memory is unreadable or unwritable. - Adds regression unit tests in `core/libs/tests/GuestModuleInfo.cpp` covering unwritable `handles`, `actual`, and `info` pointers. - Updates documentation in `docs/dev/debt/libkernel.md`. ### Tested - Ran `python tools/check_conventions.py --base origin/main`. - Added unit tests in `core/libs/tests/GuestModuleInfo.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
blawesom commented 2026-10-30 20:36:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-30T20:36:06Z.

Review: APPROVED


Verified a2ae599dd on Linux x86-64 (GCC 16.2.1, CachyOS kernel 6.2.10, Release, BUILD_TESTING=ON), isolated worktree at refs/pull/13587/head.

  • Diff review: FillModuleInfo validates st_size via GuestCopyIn_nid_no_patch and writes results via GuestCopyOut_nid_no_patch; FillModuleList writes handles and actual via GuestCopyOut_nid_no_patch (staged through a local vector, so a bad handles no longer partially writes before the ENOMEM path); sceKernelGetModuleInfoFromAddr zero-writes through the guarded copy. All return SCE_KERNEL_ERROR_EFAULT on failure. No special-casing, no comments, matches the EFAULT-series pattern.
  • Coverage: tests hit invalid handles, actual, and info pointers (0x10) for GetModuleList, GetModuleList2, GetModuleInfo, and GetModuleInfo2. Note sceKernelGetModuleInfoFromAddr with a bad info pointer is not directly tested (minor, its guards are the same helpers).
  • guest_module_info: builds clean, passes 5/5 with ctest --repeat until-fail:5.
  • Negative control: with this PR's tests kept and ModuleInfo.cpp restored to main, guest_module_info SEGFAULTs (reproduces issue #13569); rebuilt with the PR source it passes again.
  • Broader family (built in this worktree): guest_sysmodule, guest_sysmodule_maps_scan, guest_unwind_module_info, guest_unwind_module_info_failure all pass. Other *module* ctest entries were Not Run/Failed because their executables were not built in the focused worktree — not related to this change.
  • python tools/check_conventions.py --base origin/main: all checks passed.
  • Debt doc entry correctly states console fault handling is unmeasured (host-safety fallback framing).

Not run: full ctest suite, title run, console measurement. Checklist is complete and truthful. Clean approve.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5718353455 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13587#pullrequestreview-5718353455). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-30T20:36:06Z. **Review:** APPROVED --- Verified a2ae599dd on Linux x86-64 (GCC 16.2.1, CachyOS kernel 6.2.10, Release, BUILD_TESTING=ON), isolated worktree at refs/pull/13587/head. - Diff review: `FillModuleInfo` validates `st_size` via `GuestCopyIn_nid_no_patch` and writes results via `GuestCopyOut_nid_no_patch`; `FillModuleList` writes `handles` and `actual` via `GuestCopyOut_nid_no_patch` (staged through a local vector, so a bad `handles` no longer partially writes before the ENOMEM path); `sceKernelGetModuleInfoFromAddr` zero-writes through the guarded copy. All return `SCE_KERNEL_ERROR_EFAULT` on failure. No special-casing, no comments, matches the EFAULT-series pattern. - Coverage: tests hit invalid `handles`, `actual`, and `info` pointers (`0x10`) for GetModuleList, GetModuleList2, GetModuleInfo, and GetModuleInfo2. Note `sceKernelGetModuleInfoFromAddr` with a bad `info` pointer is not directly tested (minor, its guards are the same helpers). - `guest_module_info`: builds clean, passes 5/5 with `ctest --repeat until-fail:5`. - Negative control: with this PR's tests kept and `ModuleInfo.cpp` restored to `main`, `guest_module_info` SEGFAULTs (reproduces issue #13569); rebuilt with the PR source it passes again. - Broader family (built in this worktree): `guest_sysmodule`, `guest_sysmodule_maps_scan`, `guest_unwind_module_info`, `guest_unwind_module_info_failure` all pass. Other `*module*` ctest entries were Not Run/Failed because their executables were not built in the focused worktree — not related to this change. - `python tools/check_conventions.py --base origin/main`: all checks passed. - Debt doc entry correctly states console fault handling is unmeasured (host-safety fallback framing). Not run: full ctest suite, title run, console measurement. Checklist is complete and truthful. Clean approve.
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!13587
No description provided.