Merged PR 15471605: EfiHv: clear page memory attributes before free#71
Merged
maheeraeron merged 1 commit intoMay 5, 2026
Conversation
When EfiHv needs to make a hypercall page, it marks it as RO. Unfortunately, we have been freeing this page back to DXE Core's allocator without clearing the RO bits. This results in rare occasions where we hit a race condition: DXE core may try to allocate one of these pages, and a subsequent write will trigger a page fault in the guest. Because we have no memory protections by default for non-isolated or non-TVMs, we have no guards against this. This PR fixes that by ensuring we clear the RO bits before we free the page in EfiHv. ---- #### AI description (iteration 1) #### PR Classification Bug fix to prevent guest triple-faults by clearing memory attributes before freeing the hypercall page. #### PR Summary Fixes a critical issue where read-only memory attributes persisted on freed pages, causing page faults when those pages were later reallocated for pool allocations with write operations. - `EfiHvDxe/EfiHv.c`: Added explicit clearing of hardware memory attributes (EFI_MEMORY_RO) on the hypercall page before freeing it using `SetMemoryAttributes` with Attributes=0 to restore RW=1/NX=0, preventing the page allocator from handing out still-RO pages that would triple-fault on first write <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #62101222
chris-oo
approved these changes
May 4, 2026
mebersol
approved these changes
May 5, 2026
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.
When EfiHv needs to make a hypercall page, it marks it as RO.
Unfortunately, we have been freeing this page back to DXE Core's allocator without clearing the RO bits. This results in rare occasions where we hit a race condition: DXE core may try to allocate one of these pages, and a subsequent write will trigger a page fault in the guest.
Because we have no memory protections by default for non-isolated or non-TVMs, we have no guards against this.
This PR fixes that by ensuring we clear the RO bits before we free the page in EfiHv.
AI description (iteration 1)
PR Classification
Bug fix to prevent guest triple-faults by clearing memory attributes before freeing the hypercall page.
PR Summary
Fixes a critical issue where read-only memory attributes persisted on freed pages, causing page faults when those pages were later reallocated for pool allocations with write operations.
EfiHvDxe/EfiHv.c: Added explicit clearing of hardware memory attributes (EFI_MEMORY_RO) on the hypercall page before freeing it usingSetMemoryAttributeswith Attributes=0 to restore RW=1/NX=0, preventing the page allocator from handing out still-RO pages that would triple-fault on first writeRelated work items: #62101222