fix(libkernel): place Linux guest thread stacks inside application area #4283

Merged
MarcZX10 merged 3 commits from upstream-pr/4283 into main 2026-10-13 14:28:19 +00:00
MarcZX10 commented 2026-10-12 04:09:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T04:09:13Z.


What

Carries Tamalero's Linux guest thread stack implementation from issue #3283, preserving the original implementation commit author (Cesar Rodriguez). A separate follow-up commit tracks each live guest stack's full host mapping and rejects mprotect ranges that overlap its host-only prefix or suffix, including the guard page. This prevents generic guest allocation paths from making those pages writable while preserving valid protection changes inside the guest-visible stack.

The stack-protection regression checks a guard-only range and a range crossing from outside into the guest stack. The Linux post-join assertion accepts the reserved PROT_NONE state used by the guest arena, and the subsequent stack-reuse test still exercises the address.

Tested

  • Before the current-main rebase, Linux built guest_kernel_stack_protect_tests and guest_kernel_is_stack_tests; CTest passed 2/2, conventions passed, and the baseline guest_kernel_stack_protect test passed on that base.
  • The current-main rebase has not been rebuilt or retested locally. CI should rerun the checks against this head.

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
  • No notes, investigation files or images added to the repository
  • Generic behavior, not title-specific
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824811844 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4283). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T04:09:13Z. --- ### What Carries Tamalero's Linux guest thread stack implementation from issue #3283, preserving the original implementation commit author (Cesar Rodriguez). A separate follow-up commit tracks each live guest stack's full host mapping and rejects `mprotect` ranges that overlap its host-only prefix or suffix, including the guard page. This prevents generic guest allocation paths from making those pages writable while preserving valid protection changes inside the guest-visible stack. The stack-protection regression checks a guard-only range and a range crossing from outside into the guest stack. The Linux post-join assertion accepts the reserved `PROT_NONE` state used by the guest arena, and the subsequent stack-reuse test still exercises the address. ### Tested - Before the current-main rebase, Linux built `guest_kernel_stack_protect_tests` and `guest_kernel_is_stack_tests`; CTest passed 2/2, conventions passed, and the baseline `guest_kernel_stack_protect` test passed on that base. - The current-main rebase has not been rebuilt or retested locally. CI should rerun the checks against this head. ### 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] No notes, investigation files or images added to the repository - [x] Generic behavior, not title-specific - [x] Depends on: none - [x] AI-assisted: yes
MarcZX10 commented 2026-10-12 04:10:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T04:10:08Z.


The conventions run reported the PR sections as empty because the parser expects level-2/3 headings named What, Tested, and Checklist. I updated the body to use the repository template headings and verified the parser now reads all three sections as nonempty. The original run is not rerunnable according to GitHub, so this comment records the correction; a new commit or body-triggered workflow run may be needed to refresh that check.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117587483 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4283#issuecomment-6117587483). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T04:10:08Z. --- The conventions run reported the PR sections as empty because the parser expects level-2/3 headings named What, Tested, and Checklist. I updated the body to use the repository template headings and verified the parser now reads all three sections as nonempty. The original run is not rerunnable according to GitHub, so this comment records the correction; a new commit or body-triggered workflow run may be needed to refresh that check.
MarcZX10 commented 2026-10-12 04:14:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T04:14:41Z.


All build checks have now completed successfully (including Windows relinker). The only remaining failed status is the original conventions run, which reported empty sections from the initial ### headings. The PR body now uses the repository ## headings; I verified the parser reads What, Tested, and Checklist as nonempty. GitHub disallows rerunning the original run with my permissions.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117629708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4283#issuecomment-6117629708). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T04:14:41Z. --- All build checks have now completed successfully (including Windows relinker). The only remaining failed status is the original conventions run, which reported empty sections from the initial `###` headings. The PR body now uses the repository `##` headings; I verified the parser reads What, Tested, and Checklist as nonempty. GitHub disallows rerunning the original run with my permissions.
oneandonlydean commented 2026-10-12 08:25:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:25:43Z.


Please rebase onto main instead of merging it in (c05000db6 is a merge commit) and force-push. That also re-runs the conventions check, which is still red from the first description.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120543364 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4283#issuecomment-6120543364). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T08:25:43Z. --- Please rebase onto main instead of merging it in (c05000db6 is a merge commit) and force-push. That also re-runs the conventions check, which is still red from the first description.
MarcZX10 commented 2026-10-13 07:17:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:17:51Z.


You are right: the current branch includes merge commit c05000db6, so it does not meet the rebase requirement. I will rebase the PR commits onto current main, force-push the branch, and then check that the conventions run reflects the corrected PR description.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140403663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4283#issuecomment-6140403663). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T07:17:51Z. --- You are right: the current branch includes merge commit c05000db6, so it does not meet the rebase requirement. I will rebase the PR commits onto current main, force-push the branch, and then check that the conventions run reflects the corrected PR description.
MarcZX10 commented 2026-10-13 07:32:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:32:43Z.


Rebased both commits onto current main without a merge commit and force-pushed the updated branch. The previous Linux results were from before this rebase; I updated the PR description so it does not present them as validation of the new head. CI should rerun against the rebased commits.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140630102 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4283#issuecomment-6140630102). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T07:32:43Z. --- Rebased both commits onto current `main` without a merge commit and force-pushed the updated branch. The previous Linux results were from before this rebase; I updated the PR description so it does not present them as validation of the new head. CI should rerun against the rebased commits.
adriadam10 commented 2026-10-13 13:45:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:45:53Z.


Checked on Linux: build and the libs ctest scope pass (146/146), guest_kernel_is_stack and guest_kernel_stack_protect pass and both fail without the non-test changes. The Linux-only code sits under __linux__; Windows only gets the GuestThreadStackHostRangeOverlaps stub. Rebased without a merge commit as requested. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146989058 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4283#issuecomment-6146989058). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T13:45:53Z. --- Checked on Linux: build and the libs ctest scope pass (146/146), `guest_kernel_is_stack` and `guest_kernel_stack_protect` pass and both fail without the non-test changes. The Linux-only code sits under `__linux__`; Windows only gets the `GuestThreadStackHostRangeOverlaps` stub. Rebased without a merge commit as requested. Merging once the full Build is green.
adriadam10 commented 2026-10-13 14:06:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:06:40Z.


The full Build failed on Windows in guest_kernel_stack_protect (failed at line 90, Require(hostGuard != 0)): the new host-guard check looks for a non-writable host page below the guest stack, which only exists with the Linux stack mapping; Windows keeps its normal thread stacks.

Added one commit on top, test(libkernel): check the host-only stack guard on Linux only, that puts that block under #ifdef __linux__, and rebased onto current main. Build and the libs ctest scope pass (146/146). Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147409029 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4283#issuecomment-6147409029). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:06:40Z. --- The full Build failed on Windows in `guest_kernel_stack_protect` (`failed at line 90`, `Require(hostGuard != 0)`): the new host-guard check looks for a non-writable host page below the guest stack, which only exists with the Linux stack mapping; Windows keeps its normal thread stacks. Added one commit on top, `test(libkernel): check the host-only stack guard on Linux only`, that puts that block under `#ifdef __linux__`, and rebased onto current main. Build and the libs ctest scope pass (146/146). Merging once the full Build is 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!4283
No description provided.