Skip to content

Commit 27a7c64

Browse files
Davidlohr Buesotorvalds
authored andcommitted
partitions/efi: account for pmbr size in lba
The partition that has the 0xEE (GPT protective), must have the size in lba field set to the lesser of the size of the disk minus one or 0xFFFFFFFF for larger disks. 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>
1 parent b05ebbb commit 27a7c64

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎block/partitions/efi.c‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ static inline int pmbr_part_valid(gpt_mbr_record *part)
166166
/**
167167
* is_pmbr_valid(): test Protective MBR for validity
168168
* @mbr: pointer to a legacy mbr structure
169+
* @total_sectors: amount of sectors in the device
169170
*
170171
* Description: Checks for a valid protective or hybrid
171172
* master boot record (MBR). The validity of a pMBR depends
@@ -180,16 +181,17 @@ static inline int pmbr_part_valid(gpt_mbr_record *part)
180181
* Returns 0 upon invalid MBR, or GPT_MBR_PROTECTIVE or
181182
* GPT_MBR_HYBRID depending on the device layout.
182183
*/
183-
static int is_pmbr_valid(legacy_mbr *mbr)
184+
static int is_pmbr_valid(legacy_mbr *mbr, sector_t total_sectors)
184185
{
185-
int i, ret = 0; /* invalid by default */
186+
int i, part = 0, ret = 0; /* invalid by default */
186187

187188
if (!mbr || le16_to_cpu(mbr->signature) != MSDOS_MBR_SIGNATURE)
188189
goto done;
189190

190191
for (i = 0; i < 4; i++) {
191192
ret = pmbr_part_valid(&mbr->partition_record[i]);
192193
if (ret == GPT_MBR_PROTECTIVE) {
194+
part = i;
193195
/*
194196
* Ok, we at least know that there's a protective MBR,
195197
* now check if there are other partition types for
@@ -207,6 +209,18 @@ static int is_pmbr_valid(legacy_mbr *mbr)
207209
EFI_PMBR_OSTYPE_EFI_GPT) &&
208210
(mbr->partition_record[i].os_type != 0x00))
209211
ret = GPT_MBR_HYBRID;
212+
213+
/*
214+
* Protective MBRs take up the lesser of the whole disk
215+
* or 2 TiB (32bit LBA), ignoring the rest of the disk.
216+
*
217+
* Hybrid MBRs do not necessarily comply with this.
218+
*/
219+
if (ret == GPT_MBR_PROTECTIVE) {
220+
if (le32_to_cpu(mbr->partition_record[part].size_in_lba) !=
221+
min((uint32_t) total_sectors - 1, 0xFFFFFFFF))
222+
ret = 0;
223+
}
210224
done:
211225
return ret;
212226
}
@@ -568,6 +582,7 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
568582
gpt_header *pgpt = NULL, *agpt = NULL;
569583
gpt_entry *pptes = NULL, *aptes = NULL;
570584
legacy_mbr *legacymbr;
585+
sector_t total_sectors = i_size_read(state->bdev->bd_inode) >> 9;
571586
u64 lastlba;
572587

573588
if (!ptes)
@@ -581,7 +596,7 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
581596
goto fail;
582597

583598
read_lba(state, 0, (u8 *)legacymbr, sizeof(*legacymbr));
584-
good_pmbr = is_pmbr_valid(legacymbr);
599+
good_pmbr = is_pmbr_valid(legacymbr, total_sectors);
585600
kfree(legacymbr);
586601

587602
if (!good_pmbr)

0 commit comments

Comments
 (0)