fix(libkernel): reject mprotect crossing guest thread stack bounds on Windows #4113

Closed
Feuris wants to merge 1 commit from upstream-pr/4113 into main
Feuris commented 2026-10-11 23:31:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Feuris on 2026-10-11T23:31:12Z.


What

Fixes #4088: sceKernelMprotect and mprotect accepted ranges that crossed a guest thread stack's bounds or touched the host stack margin on Windows since #3788, because the committed private memory fast path applied native protection to any unregistered host region.

  • Adds IsGuestThreadStackAllocation in Pthread to identify thread stack allocation bases on Windows.
  • Excludes thread stack allocations from the Windows committed private host memory fast path in DoMprotect.
  • Removes the GPU protection check from the in-stack handler so valid guest stack protections succeed directly.
  • Extends GuestKernelStackProtect to assert that ranges crossing stack boundaries and host margins are rejected with -1.

Closes #4088.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0: syntax and compilation verified (-fsyntax-only on modified PRX and test sources); tools/check_conventions.py --base origin/main and git diff --check pass cleanly.

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 (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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823213747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4113). Originally posted by [Feuris](https://github.com/Feuris) on 2026-10-11T23:31:12Z. --- ### What Fixes #4088: `sceKernelMprotect` and `mprotect` accepted ranges that crossed a guest thread stack's bounds or touched the host stack margin on Windows since #3788, because the committed private memory fast path applied native protection to any unregistered host region. - Adds `IsGuestThreadStackAllocation` in `Pthread` to identify thread stack allocation bases on Windows. - Excludes thread stack allocations from the Windows committed private host memory fast path in `DoMprotect`. - Removes the GPU protection check from the in-stack handler so valid guest stack protections succeed directly. - Extends `GuestKernelStackProtect` to assert that ranges crossing stack boundaries and host margins are rejected with -1. Closes #4088. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0: syntax and compilation verified (`-fsyntax-only` on modified PRX and test sources); `tools/check_conventions.py --base origin/main` and `git diff --check` pass cleanly. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
Feuris commented 2026-10-12 01:48:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Feuris on 2026-10-12T01:48:23Z.


Closing as superseded by #4169. Glad to see the Windows test suite green again!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116308432 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4113#issuecomment-6116308432). Originally posted by [Feuris](https://github.com/Feuris) on 2026-10-12T01:48:23Z. --- Closing as superseded by #4169. Glad to see the Windows test suite green again!

Pull request closed

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!4113
No description provided.