Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] libfdisk: (gpt) fix check for beginning of protective partition
@ 2015-05-02  4:44 Michael Marineau
  2015-05-05 11:03 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Marineau @ 2015-05-02  4:44 UTC (permalink / raw)
  To: util-linux; +Cc: Michael Marineau

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 <michael.marineau@coreos.com>
---
 libfdisk/src/gpt.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index a7766da..989fd75 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))
-- 
2.0.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libfdisk: (gpt) fix check for beginning of protective partition
  2015-05-02  4:44 [PATCH] libfdisk: (gpt) fix check for beginning of protective partition Michael Marineau
@ 2015-05-05 11:03 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2015-05-05 11:03 UTC (permalink / raw)
  To: Michael Marineau; +Cc: util-linux

On Fri, May 01, 2015 at 09:44:33PM -0700, Michael Marineau wrote:
> 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.

 IMHO is better to say "sorry, this is unsupported use-case", than
 really on bad thing like hybrid GPT.

 Anyway applied, with your patch the code seems more robust, thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-05 11:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-02  4:44 [PATCH] libfdisk: (gpt) fix check for beginning of protective partition Michael Marineau
2015-05-05 11:03 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox