Reviewed-by: Ray Ni <ray...@intel.com> > -----Original Message----- > From: Gao, Zhichao <zhichao....@intel.com> > Sent: Tuesday, July 14, 2020 9:23 AM > To: devel@edk2.groups.io > Cc: Wu, Hao A <hao.a...@intel.com>; Ni, Ray <ray...@intel.com> > Subject: [PATCH V3 1/3] MdeModulePkg/PartitionDxe: Correct the MBR last > block value > > 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...@intel.com> > Cc: Ray Ni <ray...@intel.com> > Signed-off-by: Zhichao Gao <zhichao....@intel.com> > --- > MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c > b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c > index dac451a144..f0c92aa09a 100644 > --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c > +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c > @@ -135,14 +135,17 @@ PartitionInstallMbrChildHandles ( > EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode; > UINT32 BlockSize; > UINT32 MediaId; > - EFI_LBA LastBlock; > + EFI_LBA LastSector; > EFI_PARTITION_INFO_PROTOCOL PartitionInfo; > > Found = EFI_NOT_FOUND; > > - BlockSize = BlockIo->Media->BlockSize; > - MediaId = BlockIo->Media->MediaId; > - LastBlock = BlockIo->Media->LastBlock; > + BlockSize = BlockIo->Media->BlockSize; > + MediaId = BlockIo->Media->MediaId; > + LastSector = DivU64x32 ( > + MultU64x32 (BlockIo->Media->LastBlock + 1, BlockSize), > + MBR_SIZE > + ) - 1; > > // > // Ensure the block size can hold the MBR > @@ -167,7 +170,7 @@ PartitionInstallMbrChildHandles ( > Found = Status; > goto Done; > } > - if (!PartitionValidMbr (Mbr, LastBlock)) { > + if (!PartitionValidMbr (Mbr, LastSector)) { > goto Done; > } > // > -- > 2.21.0.windows.1
-=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62466): https://edk2.groups.io/g/devel/message/62466 Mute This Topic: https://groups.io/mt/75490640/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-