kpartx: verify GUID partition entry size
authorBenjamin Marzinski <bmarzins@redhat.com>
Fri, 10 Feb 2012 18:14:39 +0000 (12:14 -0600)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Sat, 11 Feb 2012 08:20:07 +0000 (09:20 +0100)
This patch pulls in some kernel code to catch a corrupt GUID partition
table with the wrong size.

Signed-off-by: Boris Ranto <branto@redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
kpartx/gpt.c

index d0dec70231ce0c8684b577725d6d07deaf99d3d6..3082cae37b6ee34b6221279c94ea84bd7e914b66 100644 (file)
@@ -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;