Skip to content

Merged PR 15471605: EfiHv: clear page memory attributes before free#71

Merged
maheeraeron merged 1 commit into
microsoft:mainfrom
maheeraeron:user/maheeraeron/uefi-update-05042026
May 5, 2026
Merged

Merged PR 15471605: EfiHv: clear page memory attributes before free#71
maheeraeron merged 1 commit into
microsoft:mainfrom
maheeraeron:user/maheeraeron/uefi-update-05042026

Conversation

@maheeraeron
Copy link
Copy Markdown
Collaborator

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

Related work items: #62101222

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
@maheeraeron maheeraeron merged commit 8476a49 into microsoft:main May 5, 2026
8 checks passed
@maheeraeron maheeraeron deleted the user/maheeraeron/uefi-update-05042026 branch May 5, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants