Commit 6b02fa59a7cf34c548eedee657b07ea6c54d3894

Authored by Davidlohr Bueso
Committed by Linus Torvalds
1 parent 3711d86a2d

partitions/efi: loosen check fot pmbr size in lba

Matt found that commit 27a7c642174e ("partitions/efi: account for pmbr
size in lba") caused his GPT formatted eMMC device not to boot.  The
reason is that this commit enforced Linux to always check the lesser of
the whole disk or 2Tib for the pMBR size in LBA.  While most disk
partitioning tools out there create a pMBR with these characteristics,
Microsoft does not, as it always sets the entry to the maximum 32-bit
limitation - even though a drive may be smaller than that[1].

Loosen this check and only verify that the size is either the whole disk
or 0xFFFFFFFF.  No tool in its right mind would set it to any value
other than these.

[1] http://thestarman.pcministry.com/asm/mbr/GPT.htm#GPTPT

Reported-and-tested-by: Matt Porter <matt.porter@linaro.org>
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 6 additions and 2 deletions Side-by-side Diff

block/partitions/efi.c
... ... @@ -186,6 +186,7 @@
186 186 */
187 187 static int is_pmbr_valid(legacy_mbr *mbr, sector_t total_sectors)
188 188 {
  189 + uint32_t sz = 0;
189 190 int i, part = 0, ret = 0; /* invalid by default */
190 191  
191 192 if (!mbr || le16_to_cpu(mbr->signature) != MSDOS_MBR_SIGNATURE)
192 193  
... ... @@ -216,12 +217,15 @@
216 217 /*
217 218 * Protective MBRs take up the lesser of the whole disk
218 219 * or 2 TiB (32bit LBA), ignoring the rest of the disk.
  220 + * Some partitioning programs, nonetheless, choose to set
  221 + * the size to the maximum 32-bit limitation, disregarding
  222 + * the disk size.
219 223 *
220 224 * Hybrid MBRs do not necessarily comply with this.
221 225 */
222 226 if (ret == GPT_MBR_PROTECTIVE) {
223   - if (le32_to_cpu(mbr->partition_record[part].size_in_lba) !=
224   - min((uint32_t) total_sectors - 1, 0xFFFFFFFF))
  227 + sz = le32_to_cpu(mbr->partition_record[part].size_in_lba);
  228 + if (sz != (uint32_t) total_sectors - 1 && sz != 0xFFFFFFFF)
225 229 ret = 0;
226 230 }
227 231 done: