fix(guest): give page faults their own exception stack#1571
Draft
ludfjig wants to merge 1 commit into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed test
exception_handler_installation_and_validationstarted failing in one of my feature branches.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