]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
disk: gpt: verify alternate LBA points to last usable LBA
authorStefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Mon, 8 Mar 2021 16:07:11 +0000 (16:07 +0000)
committerTom Rini <trini@konsulko.com>
Mon, 12 Apr 2021 21:17:11 +0000 (17:17 -0400)
The gpt command require the GPT backup header at the standard location
at the end of the device. Check the alternate LBA value before reading
the GPT backup header from the last usable LBA of the device.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
disk/part_efi.c

index e5636ea7e699bd02c3fa23698a414f4d89a7b36a..0fb7ff0b6bb98c3ee9d7b2058aabe7a5532d18d4 100644 (file)
@@ -692,6 +692,15 @@ int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head,
        /* Free pte before allocating again */
        free(*gpt_pte);
 
+       /*
+        * Check that the alternate_lba entry points to the last LBA
+        */
+       if (le64_to_cpu(gpt_head->alternate_lba) != (dev_desc->lba - 1)) {
+               printf("%s: *** ERROR: Misplaced Backup GPT ***\n",
+                      __func__);
+               return -1;
+       }
+
        if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
                         gpt_head, gpt_pte) != 1) {
                printf("%s: *** ERROR: Invalid Backup GPT ***\n",