Skip to content

Commit

Permalink
disk: gpt: verify alternate LBA points to last usable LBA
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Heinrich Schuchardt <[email protected]>
  • Loading branch information
herbrechtsmeier authored and trini committed Apr 12, 2021
1 parent b935d19 commit d469338
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions disk/part_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d469338

Please sign in to comment.