[PATCH 2/2 for 3.12-rc6] Revert "partitions/efi: account for pmbr size in lba"

From: Artem Bityutskiy
Date: Mon Oct 14 2013 - 07:42:01 EST


From: Artem Bityutskiy <artem.bityutskiy@xxxxxxxxxxxxxxx>

This reverts commit 27a7c642174eaec627f6a3a254035bf8abd02c5e.

This patch breaks existing systems, for example, Tizen IVI images do not boot
the way they have always been booted because of this patch.

Here is the (pretty standard) use-case:

1. We create a 4GiB image with GPT partition. At this point the protective MBR
partition contains correct 'size_in_lba'.
2. We dd this image to an 8GiB USB stick and try to boot off this USB stick.

Expected outcome:
The kernel complains that the alternate GPT header is not at the end of the
disk, but accepts/parses it anyway and the system boots.

With this patch:
The kernel just does not recognize the partition table and the system fails
to boot.

Ther root-cause is the size check introduced in the commit which is being
reverted. That commit does not explain which problem it solves, so I guess this
is more about "hardening" the GPT parser, which does not sound like a good
reason for breaking existing setups, so I think it is best to just revert this
change.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@xxxxxxxxxxxxxxx>
Tested-by: Artem Bityutskiy <artem.bityutskiy@xxxxxxxxxxxxxxx>
---
block/partitions/efi.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index 1a5ec9a..f5716b8 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -169,7 +169,6 @@ invalid:
/**
* is_pmbr_valid(): test Protective MBR for validity
* @mbr: pointer to a legacy mbr structure
- * @total_sectors: amount of sectors in the device
*
* Description: Checks for a valid protective or hybrid
* master boot record (MBR). The validity of a pMBR depends
@@ -184,9 +183,9 @@ invalid:
* Returns 0 upon invalid MBR, or GPT_MBR_PROTECTIVE or
* GPT_MBR_HYBRID depending on the device layout.
*/
-static int is_pmbr_valid(legacy_mbr *mbr, sector_t total_sectors)
+static int is_pmbr_valid(legacy_mbr *mbr)
{
- int i, part = 0, ret = 0; /* invalid by default */
+ int i, ret = 0; /* invalid by default */

if (!mbr || le16_to_cpu(mbr->signature) != MSDOS_MBR_SIGNATURE)
goto done;
@@ -194,7 +193,6 @@ static int is_pmbr_valid(legacy_mbr *mbr, sector_t total_sectors)
for (i = 0; i < 4; i++) {
ret = pmbr_part_valid(&mbr->partition_record[i]);
if (ret == GPT_MBR_PROTECTIVE) {
- part = i;
/*
* Ok, we at least know that there's a protective MBR,
* now check if there are other partition types for
@@ -212,18 +210,6 @@ check_hybrid:
EFI_PMBR_OSTYPE_EFI_GPT) &&
(mbr->partition_record[i].os_type != 0x00))
ret = GPT_MBR_HYBRID;
-
- /*
- * Protective MBRs take up the lesser of the whole disk
- * or 2 TiB (32bit LBA), ignoring the rest of the disk.
- *
- * Hybrid MBRs do not necessarily comply with this.
- */
- if (ret == GPT_MBR_PROTECTIVE) {
- if (le32_to_cpu(mbr->partition_record[part].size_in_lba) !=
- min((uint32_t) total_sectors - 1, 0xFFFFFFFF))
- ret = 0;
- }
done:
return ret;
}
@@ -582,7 +568,6 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
gpt_header *pgpt = NULL, *agpt = NULL;
gpt_entry *pptes = NULL, *aptes = NULL;
legacy_mbr *legacymbr;
- sector_t total_sectors = i_size_read(state->bdev->bd_inode) >> 9;
u64 lastlba;

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

read_lba(state, 0, (u8 *)legacymbr, sizeof(*legacymbr));
- good_pmbr = is_pmbr_valid(legacymbr, total_sectors);
+ good_pmbr = is_pmbr_valid(legacymbr);
kfree(legacymbr);

if (!good_pmbr)
--
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/