Skip to contentSkip to conversation

kpartx: verify GUID partition entry size

PATCH New Benjamin Marzinski 1 participant 1 message Feb 10, 2012 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 kpartx: verify GUID partition entry size

This patch pulls in some kernel code to catch a corrupt GUID partition table with the wrong size.

---
 kpartx/gpt.c |    9 +++++++++
 1 file changed, 9 insertions(+)
kpartx/gpt.c +9 -0
Index: multipath-tools-120123/kpartx/gpt.c
===================================================================
@@ -367,6 +367,15 @@ is_gpt_valid(int fd, uint64_t lba,
 	}
 
 
+	/* Check that sizeof_partition_entry has the correct value */
+	if (__le32_to_cpu((*gpt)->sizeof_partition_entry) != sizeof(gpt_entry)) {
+		// printf("GUID partition entry size check failed.\n");
+		free(*gpt);
+		*gpt = NULL;
+		return 0;
+	}
+
+
 	if (!(*ptes = alloc_read_gpt_entries(fd, *gpt))) {
 		free(*gpt);
 		*gpt = NULL;