Skip to content

fix(guest): give page faults their own exception stack#1571

Draft
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:stack_fix
Draft

fix(guest): give page faults their own exception stack#1571
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:stack_fix

Conversation

@ludfjig

@ludfjig ludfjig commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

I noticed test exception_handler_installation_and_validation started failing in one of my feature branches.

GuestAborted(15, "Exception: PageFault | Exception vector: 14
   Faulting Instruction: 0x1006
   Page Fault Address: 0x0
   Error code: 0x2
   Stack Pointer: 0xffffffffffffed00")

Turns out just adding a couple new guest functions shifted memory so a page the handler writes is now copy-on-write, and that first write from inside the handler is what trips the bug. See commit message for more details

A guest exception handler runs on the IST1 stack. If the handler writes
a copy-on-write page, the first write faults. The page fault also uses
IST1, so the CPU resets RSP to the top of IST1 and writes the fault
frame over the live handler frame. The handler then returns to a bad
address and the guest aborts.

The bug stays latent until an exception handler writes a copy-on-write
page. It surfaced when a memory layout change moved a counter that an
existing handler increments onto a page that stays copy-on-write after a
snapshot. The increment then faulted while the handler ran and crashed
the guest.

Send page faults to their own IST2 stack so a fault inside a handler
keeps the handler frame intact. The page-fault stack uses the second of
the two scratch pages already reserved at the top of the region.

Add a regression test, exception_handler_nested_page_fault. It installs
a handler that writes a copy-on-write page, then triggers int3. Without
the fix the guest aborts with a page fault. With the fix it returns 0.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig ludfjig added the kind/bugfix For PRs that fix bugs label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bugfix For PRs that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant