fix(libkernel): reject malformed ranges in sceKernelReleaseDirectMemory #2421

Merged
Pouare514 merged 1 commit from upstream-pr/2421 into main 2026-10-10 06:37:29 +00:00
Pouare514 commented 2026-10-09 19:02:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-09T19:02:57Z.


What

sceKernelReleaseDirectMemory only rejected a negative start and a zero length, so malformed ranges reached the physical pool: a sub-page length silently freed a whole page while fragmenting the block map at byte granularity, and an out-of-range length walked the page table past the backing store. Validate page alignment of start and length plus the range bound up front and return EINVAL instead, mirroring DoMunmap.

Tested

  • New CheckReleaseDirectMemoryRejectsInvalidRanges in core/libs/tests/GuestMemory.cpp: negative start, zero/misaligned/huge/out-of-range lengths.
  • guest_memory passes with the fix; with the fix stashed it aborts (0xc0000409), so the test pins the behavior.
  • CI green: conventions, eligibility, intake, report, relinker macos/ubuntu/windows (linux/windows jobs skip by design).

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4804691556 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2421). Originally posted by [Pouare514](https://github.com/Pouare514) on 2026-10-09T19:02:57Z. --- ### What sceKernelReleaseDirectMemory only rejected a negative start and a zero length, so malformed ranges reached the physical pool: a sub-page length silently freed a whole page while fragmenting the block map at byte granularity, and an out-of-range length walked the page table past the backing store. Validate page alignment of start and length plus the range bound up front and return EINVAL instead, mirroring DoMunmap. ### Tested - New CheckReleaseDirectMemoryRejectsInvalidRanges in core/libs/tests/GuestMemory.cpp: negative start, zero/misaligned/huge/out-of-range lengths. - guest_memory passes with the fix; with the fix stashed it aborts (0xc0000409), so the test pins the behavior. - CI green: conventions, eligibility, intake, report, relinker macos/ubuntu/windows (linux/windows jobs skip by design). ### Checklist - [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 - [x] Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt - [x] No notes, investigation .md files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
popcoder565 commented 2026-10-09 19:41:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T19:41:49Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head aa77b2b8, merged onto main 8b393b6e in one build with 31 other PRs that had no Windows run.

  • This PR's tests pass: guest_memory.
  • Full ctest in that build: 520 of 521. The one failure is guest_offline_imports, broken by #2359 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088009000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2421#issuecomment-6088009000). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T19:41:49Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `aa77b2b8`, merged onto `main` 8b393b6e in one build with 31 other PRs that had no Windows run. - This PR's tests pass: `guest_memory`. - Full ctest in that build: 520 of 521. The one failure is `guest_offline_imports`, broken by #2359 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
Kikoarl commented 2026-10-09 20:00:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T20:00:49Z.


Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at aa77b2b8:

  • Build: Built cleanly in RAM (/tmp/anyps5_build) with zero warnings/errors.
  • Conventions: python3 tools/check_conventions.py --base origin/main --head HEAD -> PASS (0 errors).
  • Verification: Verified GuestMemory.cpp (CheckReleaseDirectMemoryRejectsInvalidRanges). Page-alignment checks and bounds validation against DIRECT_MEMORY_SIZE cleanly reject unaligned and out-of-bounds ranges with SCE_KERNEL_ERROR_EINVAL.

LGTM!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088303862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2421#issuecomment-6088303862). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T20:00:49Z. --- Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at `aa77b2b8`: - **Build**: Built cleanly in RAM (`/tmp/anyps5_build`) with zero warnings/errors. - **Conventions**: `python3 tools/check_conventions.py --base origin/main --head HEAD` -> **PASS (0 errors)**. - **Verification**: Verified `GuestMemory.cpp` (`CheckReleaseDirectMemoryRejectsInvalidRanges`). Page-alignment checks and bounds validation against `DIRECT_MEMORY_SIZE` cleanly reject unaligned and out-of-bounds ranges with `SCE_KERNEL_ERROR_EINVAL`. LGTM!
oneandonlydean commented 2026-10-10 05:19:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:19:05Z.


Conflicts with main in core/libs/prx/libkernel/DirectMemory/Export.cpp after #2236; please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094146588 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2421#issuecomment-6094146588). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:19:05Z. --- Conflicts with main in `core/libs/prx/libkernel/DirectMemory/Export.cpp` after #2236; please rebase.
adriadam10 commented 2026-10-10 06:26:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:26:04Z.


Rebased onto current main (conflict with #2236 in sceKernelReleaseDirectMemory: the range validation now runs before DirectMemoryViews). Build and ctest green on the rebase, including guest_memory. Page alignment matches KytyPS5 and shadPS4 (EINVAL); merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094637203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2421#issuecomment-6094637203). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:26:04Z. --- Rebased onto current main (conflict with #2236 in `sceKernelReleaseDirectMemory`: the range validation now runs before `DirectMemoryViews`). Build and ctest green on the rebase, including `guest_memory`. Page alignment matches KytyPS5 and shadPS4 (EINVAL); merging.
github-actions[bot] commented 2026-10-10 06:28:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T06:28:49Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1905 core/libs/tests/GuestMemory.cpp L7
#1961 core/libs/tests/GuestMemory.cpp L7-8
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094657121 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2421#issuecomment-6094657121). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T06:28:49Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1905 | `core/libs/tests/GuestMemory.cpp` [L7](https://github.com/boykopovar/AnyPS5/blob/d43d50beb1ee86b1df14569e0780257ab87d6903/core/libs/tests/GuestMemory.cpp#L7) | | | | #1961 | `core/libs/tests/GuestMemory.cpp` [L7-8](https://github.com/boykopovar/AnyPS5/blob/d43d50beb1ee86b1df14569e0780257ab87d6903/core/libs/tests/GuestMemory.cpp#L7-L8) | | |
adriadam10 commented 2026-10-10 06:37:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:37:26Z.


The only red check was write-watch (macos-15-intel): write_watch_threads timed out at 30 s on a slow runner (the same job on macos-15 passes, and those tests don't touch libkernel). Re-running it; merging once green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094720016 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2421#issuecomment-6094720016). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:37:26Z. --- The only red check was `write-watch (macos-15-intel)`: `write_watch_threads` timed out at 30 s on a slow runner (the same job on macos-15 passes, and those tests don't touch libkernel). Re-running it; merging once green.
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!2421
No description provided.