forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0021-gpt-refuse-to-write-to-sector-0.patch
34 lines (28 loc) · 1.13 KB
/
0021-gpt-refuse-to-write-to-sector-0.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
From d81aa092c0eb91ec618a6f0879426e8fcbdae0d4 Mon Sep 17 00:00:00 2001
From: Michael Marineau <michael.marineau@coreos.com>
Date: Thu, 11 Aug 2016 15:02:21 -0700
Subject: [PATCH] gpt: refuse to write to sector 0
---
grub-core/lib/gpt.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/grub-core/lib/gpt.c b/grub-core/lib/gpt.c
index f83fe29..b744991 100644
--- a/grub-core/lib/gpt.c
+++ b/grub-core/lib/gpt.c
@@ -626,10 +626,17 @@ grub_gpt_write_table (grub_disk_t disk, grub_gpt_t gpt,
sizeof (*header));
addr = grub_gpt_sector_to_addr (gpt, grub_le_to_cpu64 (header->header_lba));
+ if (addr == 0)
+ return grub_error (GRUB_ERR_BUG,
+ "Refusing to write GPT header to address 0x0");
if (grub_disk_write (disk, addr, 0, sizeof (*header), header))
return grub_errno;
addr = grub_gpt_sector_to_addr (gpt, grub_le_to_cpu64 (header->partitions));
+ if (addr < 2)
+ return grub_error (GRUB_ERR_BUG,
+ "Refusing to write GPT entries to address 0x%llx",
+ (unsigned long long) addr);
if (grub_disk_write (disk, addr, 0, gpt->entries_size, gpt->entries))
return grub_errno;
--
2.21.3