public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] disk: gpt: verify alternate LBA points to last usable LBA
@ 2021-03-08 16:07 Stefan Herbrechtsmeier
  2021-03-08 17:38 ` Heinrich Schuchardt
  2021-04-13 14:28 ` Tom Rini
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Herbrechtsmeier @ 2021-03-08 16:07 UTC (permalink / raw)
  To: u-boot

From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

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>

---

 disk/part_efi.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index e5636ea7e6..0fb7ff0b6b 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -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",
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-13 14:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-08 16:07 [PATCH] disk: gpt: verify alternate LBA points to last usable LBA Stefan Herbrechtsmeier
2021-03-08 17:38 ` Heinrich Schuchardt
2021-03-09  9:36   ` Stefan Herbrechtsmeier
2021-03-09 16:24   ` Stefan Herbrechtsmeier
2021-03-09 17:15     ` Heinrich Schuchardt
2021-04-13 14:28 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox