]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
Move sure FvImage buffer at its alignment when install FVB protocol on it.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / FwVolBlock / FwVolBlock.c
index bdac7817765b2abf8c06f559aa620da6c5596fb1..d50716759448beb0cc4cae170943c6002324fa21 100644 (file)
@@ -413,8 +413,10 @@ Returns:
   UINTN                         BlockIndex;\r
   UINTN                         BlockIndex2;\r
   UINTN                         LinearOffset;\r
+  UINT32                        FvAlignment;\r
   EFI_FV_BLOCK_MAP_ENTRY        *PtrBlockMapEntry;\r
-\r
+  \r
+  FvAlignment = 0;\r
   FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress;\r
   //\r
   // Validate FV Header, if not as expected, return\r
@@ -423,6 +425,19 @@ Returns:
     return EFI_VOLUME_CORRUPTED;\r
   }\r
   //\r
+  // Get FvHeader alignment\r
+  //\r
+  FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
+  if (FvAlignment < 8) {\r
+    FvAlignment = 8;\r
+  }\r
+  if ((UINTN)BaseAddress % FvAlignment != 0) {\r
+    //\r
+    // FvImage buffer is not at its required alignment.\r
+    //\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+  //\r
   // Allocate EFI_FW_VOL_BLOCK_DEVICE \r
   //\r
   FvbDev = CoreAllocateCopyPool (sizeof (EFI_FW_VOL_BLOCK_DEVICE), &mFwVolBlock);\r