From 13c6353fc7dcd3c2a8c4afba48f9e3d90edefd7c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 22 May 2012 09:09:00 +0200 Subject: [PATCH] * grub-core/partmap/gpt.c (grub_gpt_partition_map_iterate): Accept protective entry in any slot. * grub-core/partmap/msdos.c (grub_partition_msdos_iterate): Reject if protective entry is found in any slot. Protective entry in non-first slot make no sense but is a widespread brain damage. --- ChangeLog | 10 ++++++++++ grub-core/partmap/gpt.c | 5 ++++- grub-core/partmap/msdos.c | 10 ++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b064e6c31..9c734d9c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2012-05-22 Vladimir Serbinenko + + * grub-core/partmap/gpt.c (grub_gpt_partition_map_iterate): Accept + protective entry in any slot. + * grub-core/partmap/msdos.c (grub_partition_msdos_iterate): Reject + if protective entry is found in any slot. + + Protective entry in non-first slot make no sense but is a widespread + brain damage. + 2012-05-22 Vladimir Serbinenko * grub-core/fs/squash4.c (grub_squash_read_data): Add missing byte-swap. diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c index c51753d5f..17f242d1d 100644 --- a/grub-core/partmap/gpt.c +++ b/grub-core/partmap/gpt.c @@ -69,7 +69,10 @@ grub_gpt_partition_map_iterate (grub_disk_t disk, return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); /* Make sure the MBR is a protective MBR and not a normal MBR. */ - if (mbr.entries[0].type != GRUB_PC_PARTITION_TYPE_GPT_DISK) + for (i = 0; i < 4; i++) + if (mbr.entries[i].type == GRUB_PC_PARTITION_TYPE_GPT_DISK) + break; + if (i == 4) return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found"); /* Read the GPT header. */ diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index 60caa9ec8..6e54a7427 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -136,6 +136,12 @@ grub_partition_msdos_iterate (grub_disk_t disk, if (grub_disk_read (disk, p.offset, 0, sizeof (mbr), &mbr)) goto finish; + /* If this is a GPT partition, this MBR is just a dummy. */ + if (p.offset == 0) + for (i = 0; i < 4; i++) + if (mbr.entries[i].type == GRUB_PC_PARTITION_TYPE_GPT_DISK) + return grub_error (GRUB_ERR_BAD_PART_TABLE, "dummy mbr"); + /* This is our loop-detection algorithm. It works the following way: It saves last position which was a power of two. Then it compares the saved value with a current one. This way it's guaranteed that the loop @@ -174,10 +180,6 @@ grub_partition_msdos_iterate (grub_disk_t disk, (unsigned long long) p.start, (unsigned long long) p.len); - /* If this is a GPT partition, this MBR is just a dummy. */ - if (e->type == GRUB_PC_PARTITION_TYPE_GPT_DISK && p.index == 0) - return grub_error (GRUB_ERR_BAD_PART_TABLE, "dummy mbr"); - /* If this partition is a normal one, call the hook. */ if (! grub_msdos_partition_is_empty (e->type) && ! grub_msdos_partition_is_extended (e->type))