audk/ArmPkg
Ard Biesheuvel 1034d223f8 ArmPkg/CpuDxe: Perform preliminary NX remap of free memory
The DXE core implementation of PcdDxeNxMemoryProtectionPolicy already
contains an assertion that EfiConventionalMemory and EfiBootServicesData
are subjected to the same policy when it comes to the use of NX
permissions. The reason for this is that we may otherwise end up with
unbounded recursion in the page table code, given that allocating a page
table would then involve a permission attribute change, and this could
result in the need for a block entry to be split, which would trigger
the allocation of a page table recursively.

For the same reason, a shortcut exists in ApplyMemoryProtectionPolicy()
where, instead of setting the memory attributes unconditionally, we
compare the NX policies and avoid touching the page tables if they are
the same for the old and the new memory types. Without this shortcut, we
may end up in a situation where, as the CPU arch protocol DXE driver is
ramping up, the same unbounded recursion is triggered, due to the fact
that the NX policy for EfiConventionalMemory has not been applied yet.

To break this cycle, let's remap all EfiConventionalMemory regions
according to the NX policy for EfiBootServicesData before exposing the
CPU arch protocol to the DXE core and other drivers. This ensures that
creating EfiBootServicesData allocations does not result in memory
attribute changes, and therefore no recursion.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2023-05-29 16:51:01 +00:00
..
Application/ArmCpuInfo ArmPkg: add ArmCpuInfo EFI application 2023-04-21 18:50:05 +00:00
Drivers ArmPkg/CpuDxe: Perform preliminary NX remap of free memory 2023-05-29 16:51:01 +00:00
Filesystem/SemihostFs ArmPkg/SemihostFs: replace SetMem with ZeroMem 2023-03-09 09:45:39 +00:00
Include ArmPkg: older assemblers may lack ID_AA64ISAR2_EL1 2023-04-20 20:11:46 +00:00
Library ArmPkg: Configure PcdEmuVariableNvModeEnable as a dynamic PCD 2023-05-29 15:14:00 +00:00
Universal/Smbios ArmPkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
ArmPkg.ci.yaml ArmPkg, ArmVirtPkg: put SpellCheck in AuditOnly mode 2022-09-10 08:23:27 +00:00
ArmPkg.dec ArmPkg/CpuDxe: Perform preliminary NX remap of free memory 2023-05-29 16:51:01 +00:00
ArmPkg.dsc ArmPkg: add ArmCpuInfo EFI application 2023-04-21 18:50:05 +00:00