fix(libkernel): return EFAULT from memory protection and stack queries for invalid memory #13904

Merged
DeveshB-1 merged 2 commits from upstream-pr/13904 into main 2026-11-01 09:56:50 +00:00
DeveshB-1 commented 2026-10-31 12:22:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DeveshB-1 on 2026-10-31T12:22:14Z.


What

Safely copy out memory protection and stack boundary query results using GuestCopyOut_nid_no_patch in sceKernelQueryMemoryProtection and sceKernelIsStack, returning SCE_KERNEL_ERROR_EFAULT when the caller provides invalid output memory pointers.

Tested

Linux (Ubuntu 24.04, x86_64). Added negative control assertions passing invalid pointers (0x10) to GuestKernelIsStack.cpp. Verified that the unpatched base crashed with SIGSEGV and that the change cleanly returns SCE_KERNEL_ERROR_EFAULT. Verified guest_kernel_is_stack and guest_protection_report pass cleanly across repeated test runs. Ran python3 tools/check_conventions.py --base origin/main and python3 tools/pr_overlap.py --branch fix/memory-protection-query-efault (no overlap).

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5097460983 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13904). Originally posted by [DeveshB-1](https://github.com/DeveshB-1) on 2026-10-31T12:22:14Z. --- ### What Safely copy out memory protection and stack boundary query results using `GuestCopyOut_nid_no_patch` in `sceKernelQueryMemoryProtection` and `sceKernelIsStack`, returning `SCE_KERNEL_ERROR_EFAULT` when the caller provides invalid output memory pointers. ### Tested Linux (Ubuntu 24.04, x86_64). Added negative control assertions passing invalid pointers (`0x10`) to `GuestKernelIsStack.cpp`. Verified that the unpatched base crashed with `SIGSEGV` and that the change cleanly returns `SCE_KERNEL_ERROR_EFAULT`. Verified `guest_kernel_is_stack` and `guest_protection_report` pass cleanly across repeated test runs. Ran `python3 tools/check_conventions.py --base origin/main` and `python3 tools/pr_overlap.py --branch fix/memory-protection-query-efault` (no overlap). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-31 12:29:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T12:29:00Z.

Review: APPROVED


Reviewed — looks good

The exact head c331346597bd007c80c9f7abba445f856b1a6535 safely copies each optional query result to guest memory and returns EFAULT when a destination is invalid.

The no-build precheck passed the diff, conventions, and mergeability checks. The author reports repeated Linux tests including invalid-pointer cases; hosted Windows passed, while Linux and specialized build jobs were skipped. I did not run a local C++ build or test binary.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5722709425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13904#pullrequestreview-5722709425). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T12:29:00Z. **Review:** APPROVED --- # Reviewed — looks good The exact head `c331346597bd007c80c9f7abba445f856b1a6535` safely copies each optional query result to guest memory and returns `EFAULT` when a destination is invalid. The no-build precheck passed the diff, conventions, and mergeability checks. The author reports repeated Linux tests including invalid-pointer cases; hosted Windows passed, while Linux and specialized build jobs were skipped. I did not run a local C++ build or test binary.
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!13904
No description provided.