From: Michael Marineau Date: Sat, 2 May 2015 04:44:33 +0000 (-0700) Subject: libfdisk: (gpt) fix check for beginning of protective partition X-Git-Tag: v2.27-rc1~217 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c6bf5c094d90a8a67317ac0fe5b685e7c2b54199;p=thirdparty%2Futil-linux.git libfdisk: (gpt) fix check for beginning of protective partition Search for the protective partition before attempting to validate that it covers the GPT header. Some hybrid MBRs list partitions out of order. For example, CoreOS images ship with a hybrid MBR that lists the boot partition first and the protective partition second in order to maintain compatibility with old versions of Xen's PV-GRUB. Signed-off-by: Michael Marineau --- diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index a7766da604..989fd752c5 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -678,11 +678,6 @@ static int valid_pmbr(struct fdisk_context *cxt) if (le16_to_cpu(pmbr->signature) != MSDOS_MBR_SIGNATURE) goto done; - /* LBA of the GPT partition header */ - if (pmbr->partition_record[0].starting_lba != - cpu_to_le32(GPT_PRIMARY_PARTITION_TABLE_LBA)) - goto done; - /* seems like a valid MBR was found, check DOS primary partitions */ for (i = 0; i < 4; i++) { if (pmbr->partition_record[i].os_type == EFI_PMBR_OSTYPE) { @@ -693,13 +688,18 @@ static int valid_pmbr(struct fdisk_context *cxt) */ part = i; ret = GPT_MBR_PROTECTIVE; - goto check_hybrid; + break; } } if (ret != GPT_MBR_PROTECTIVE) goto done; -check_hybrid: + + /* LBA of the GPT partition header */ + if (pmbr->partition_record[part].starting_lba != + cpu_to_le32(GPT_PRIMARY_PARTITION_TABLE_LBA)) + goto done; + for (i = 0 ; i < 4; i++) { if ((pmbr->partition_record[i].os_type != EFI_PMBR_OSTYPE) && (pmbr->partition_record[i].os_type != 0x00))