partitions/efi: check pmbr record's starting lba
authorDavidlohr Bueso <davidlohr@hp.com>
Wed, 11 Sep 2013 21:24:56 +0000 (14:24 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Sep 2013 22:59:15 +0000 (15:59 -0700)
Per the UEFI Specs 2.4, June 2013, the starting lba of the partition that
has the EFI GPT (0xEE) must be set to 0x00000001 - this is obviously the
LBA of the GPT Partition Header.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Reviewed-by: Karel Zak <kzak@redhat.com>
Acked-by: Matt Fleming <matt.fleming@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
block/partitions/efi.c

index bd8fb22b2109df17d2511577d72977c0c59485ec..7a2b74f0d06fcc9e00241ba0ca7f784bd117b5d3 100644 (file)
@@ -151,10 +151,19 @@ static u64 last_lba(struct block_device *bdev)
 
 static inline int pmbr_part_valid(gpt_mbr_record *part)
 {
-       if (part->os_type == EFI_PMBR_OSTYPE_EFI_GPT &&
-           le32_to_cpu(part->start_sector) == 1UL)
-               return 1;
-        return 0;
+       if (part->os_type != EFI_PMBR_OSTYPE_EFI_GPT)
+               goto invalid;
+
+       /* set to 0x00000001 (i.e., the LBA of the GPT Partition Header) */
+       if (le32_to_cpu(part->starting_lba) != GPT_PRIMARY_PARTITION_TABLE_LBA)
+               goto invalid;
+
+       if (le32_to_cpu(part->start_sector) != 1UL)
+               goto invalid;
+
+       return 1;
+invalid:
+       return 0;
 }
 
 /**