]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/PartitionDxe: Correct the MBR last block value
authorZhichao Gao <zhichao.gao@intel.com>
Mon, 6 Jul 2020 06:21:10 +0000 (14:21 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 15 Jul 2020 01:18:13 +0000 (01:18 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2823

PartitionValidMbr function's second parameter should be the
last sector of the device. For MBR partition, the block size is
sector size, i.e. 512 bytes. The original value is media block
last LBA which is counted by the media block size. And media
block size is not always 512 bytes, it may be larger which would
cause the MBR boundary check incorrect. The boundary check is
based on the partition entry start LBA and size of LBA which
are both counted by the sector number (512 bytes).

Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c

index dac451a14415e1cfed5079d97dbd85194655d454..f0c92aa09a596c235050688705db4fc51433922e 100644 (file)
@@ -135,14 +135,17 @@ PartitionInstallMbrChildHandles (
   EFI_DEVICE_PATH_PROTOCOL     *LastDevicePathNode;\r
   UINT32                       BlockSize;\r
   UINT32                       MediaId;\r
-  EFI_LBA                      LastBlock;\r
+  EFI_LBA                      LastSector;\r
   EFI_PARTITION_INFO_PROTOCOL  PartitionInfo;\r
 \r
   Found           = EFI_NOT_FOUND;\r
 \r
-  BlockSize = BlockIo->Media->BlockSize;\r
-  MediaId   = BlockIo->Media->MediaId;\r
-  LastBlock = BlockIo->Media->LastBlock;\r
+  BlockSize   = BlockIo->Media->BlockSize;\r
+  MediaId     = BlockIo->Media->MediaId;\r
+  LastSector  = DivU64x32 (\r
+                  MultU64x32 (BlockIo->Media->LastBlock + 1, BlockSize),\r
+                  MBR_SIZE\r
+                  ) - 1;\r
 \r
   //\r
   // Ensure the block size can hold the MBR\r
@@ -167,7 +170,7 @@ PartitionInstallMbrChildHandles (
     Found = Status;\r
     goto Done;\r
   }\r
-  if (!PartitionValidMbr (Mbr, LastBlock)) {\r
+  if (!PartitionValidMbr (Mbr, LastSector)) {\r
     goto Done;\r
   }\r
   //\r