[Bug]: DXE core memory protection feature might cause inconsistency between GCD internal data structure with CPU page table #10771
Labels
package:mdemodulepkg
priority:high
Significant impact. Should be fixed as soon as possible.
state:needs-owner
state:needs-triage
type:bug
Something isn't working
Is there an existing issue for this?
Bug Type
Code first?
What packages are impacted?
MdeModulePkg
Which targets are impacted by this bug?
DEBUG, RELEASE
Current Behavior
When we enable DXE core memory protection feature, if we set some GCD irrelevent attributes like EFI_MEMORY_SP or EFI_MEMORY_CPU_CRYPTO via GCD SetMemorySpaceAttributes (), it will cause page fault except.
Expected Behavior
We can still invoke SetMemorySpaceAttributes () successfully to append EFI_MEMORY_SP or EFI_MEMORY_CPU_CRYPTO
Steps To Reproduce
Set the following two platform PCD to enable memory protection.
PcdSetNxForStack| TRUE
PcdDxeNxMemoryProtectionPolicy| 0x7FD5
Invoke GCD SetMemorySpaceAttributes () API in later DXE phase to append EFI_MEMORY_SP or EFI_MEMORY_CPU_CRYPTO (keep the original attributes)
System will have page fault exception
Build Environment
Version Information
Urgency
High
Are you going to fix this?
Someone else needs to fix it
Do you need maintainer feedback?
No maintainer feedback needed
Anything else?
The root cause of this issue is that Edk2\MdeModulePkg\Core\Dxe\Misc\MemoryProtection.c (line 1294) directly uses CPU arch protocol to clear XP in page table when loading DXE driver for execution, but it fails to update the GCD internal data structure according (the memory range still makes as XP attribute):
gCpu->SetMemoryAttributes (gCpu, Memory, Length, NewAttributes);
Later invoking of GCD SetMemorySpaceAttributes () will incorrectly re-apply the incorrect XP attribute and make it take effect in the final page table. When CPU executes the memory, it triggers the page fault exception.
The text was updated successfully, but these errors were encountered: