]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BootScriptExecutorDxe: remove NX attr for FfsBuffer
authorJian J Wang <jian.j.wang@intel.com>
Mon, 15 Jan 2018 02:25:40 +0000 (10:25 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 18 Jan 2018 09:03:25 +0000 (17:03 +0800)
If PcdDxeNxMemoryProtectionPolicy is set to enable protection for memory
of EfiReservedMemoryType, the BIOS will hang at a page fault exception
triggered by BootScriptExecutorDxe.

The root cause is that this driver will allocate memory of
EfiReservedMemoryType and relocate itself into this new memory. Since
EfiReservedMemoryType of memory is marked non-executable, re-start this
driver after relocation will cause exception. The fix is removing the NX
attribute after memory allocation.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.h

index 29af7f55ec59aa6958f1cfaf6f3cd6cfdc6f662c..aac132122c47cf7be63ffc7e3e8882d87be10124 100644 (file)
@@ -68,6 +68,7 @@
   LockBoxLib\r
   CpuExceptionHandlerLib\r
   DevicePathLib\r
+  DxeServicesTableLib\r
 \r
 [Guids]\r
   gEfiBootScriptExecutorVariableGuid    ## PRODUCES ## UNDEFINED # SaveLockBox\r
index 4545d6e5810cd38889dfd6a3fb090e68d432093f..263a282188340c6c24ba68041a85ca8fa7fb6b53 100644 (file)
@@ -273,6 +273,7 @@ ReadyToLockEventNotify (
   UINTN                                         Pages;\r
   EFI_PHYSICAL_ADDRESS                          FfsBuffer;\r
   PE_COFF_LOADER_IMAGE_CONTEXT                  ImageContext;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR               MemDesc;\r
 \r
   Status = gBS->LocateProtocol (&gEfiDxeSmmReadyToLockProtocolGuid, NULL, &Interface);\r
   if (EFI_ERROR (Status)) {\r
@@ -322,6 +323,19 @@ ReadyToLockEventNotify (
                   &FfsBuffer\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Make sure that the buffer can be used to store code.\r
+  //\r
+  Status = gDS->GetMemorySpaceDescriptor (FfsBuffer, &MemDesc);\r
+  if (!EFI_ERROR (Status) && (MemDesc.Attributes & EFI_MEMORY_XP) != 0) {\r
+    gDS->SetMemorySpaceAttributes (\r
+           FfsBuffer,\r
+           EFI_PAGES_TO_SIZE (Pages),\r
+           MemDesc.Attributes & (~EFI_MEMORY_XP)\r
+           );\r
+  }\r
+\r
   ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)FfsBuffer;\r
   //\r
   // Align buffer on section boundary\r
index 75327569d75266e3d759ffaae6304c770d229499..94deae87e6a955389af8f01a61699f5fce9c5c97 100644 (file)
@@ -38,6 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/LockBoxLib.h>\r
 #include <Library/CpuExceptionHandlerLib.h>\r
 #include <Library/DevicePathLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
 \r
 #include <Guid/AcpiS3Context.h>\r
 #include <Guid/BootScriptExecutorVariable.h>\r