X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FDisk%2FPartitionDxe%2FGpt.c;h=0778588298e5adbf45e9e36ea6c21df8646a35ba;hp=a3910041a3daaffdf0bfe245bf7d49de8904bec3;hb=b4e027f1c6063278c741757d82f3f787236673b6;hpb=e3df6949e7e2a4578660d4079988487a147c91b7 diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c index a3910041a3..0778588298 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c @@ -13,7 +13,7 @@ PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk partition content and validate the GPT table and GPT entry. -Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -307,7 +307,7 @@ PartitionInstallGptChildHandles ( DEBUG ((EFI_D_INFO, " Valid primary and !Valid backup partition table\n")); DEBUG ((EFI_D_INFO, " Restore backup partition table by the primary\n")); if (!PartitionRestoreGptTable (BlockIo, DiskIo, PrimaryHeader)) { - DEBUG ((EFI_D_INFO, " Restore backup partition table error\n")); + DEBUG ((EFI_D_INFO, " Restore backup partition table error\n")); } if (PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) { @@ -487,13 +487,22 @@ PartitionValidGptTable ( if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) || !PartitionCheckCrc (BlockSize, &PartHdr->Header) || - PartHdr->MyLBA != Lba + PartHdr->MyLBA != Lba || + (PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY)) ) { DEBUG ((EFI_D_INFO, "Invalid efi partition table header\n")); FreePool (PartHdr); return FALSE; } + // + // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow. + // + if (PartHdr->NumberOfPartitionEntries > DivU64x32 (MAX_UINTN, PartHdr->SizeOfPartitionEntry)) { + FreePool (PartHdr); + return FALSE; + } + CopyMem (PartHeader, PartHdr, sizeof (EFI_PARTITION_TABLE_HEADER)); if (!PartitionCheckGptEntryArrayCRC (BlockIo, DiskIo, PartHeader)) { FreePool (PartHdr);