if (!gpt)
                return NULL;
 
-       count = le32_to_cpu(gpt->num_partition_entries) *
+       count = (size_t)le32_to_cpu(gpt->num_partition_entries) *
                 le32_to_cpu(gpt->sizeof_partition_entry);
        if (!count)
                return NULL;
                        gpt_header **gpt, gpt_entry **ptes)
 {
        u32 crc, origcrc;
-       u64 lastlba;
+       u64 lastlba, pt_size;
 
        if (!ptes)
                return 0;
                goto fail;
        }
 
+       /* Sanity check partition table size */
+       pt_size = (u64)le32_to_cpu((*gpt)->num_partition_entries) *
+               le32_to_cpu((*gpt)->sizeof_partition_entry);
+       if (pt_size > KMALLOC_MAX_SIZE) {
+               pr_debug("GUID Partition Table is too large: %llu > %lu bytes\n",
+                        (unsigned long long)pt_size, KMALLOC_MAX_SIZE);
+               goto fail;
+       }
+
        if (!(*ptes = alloc_read_gpt_entries(state, *gpt)))
                goto fail;
 
        /* Check the GUID Partition Entry Array CRC */
-       crc = efi_crc32((const unsigned char *) (*ptes),
-                       le32_to_cpu((*gpt)->num_partition_entries) *
-                       le32_to_cpu((*gpt)->sizeof_partition_entry));
+       crc = efi_crc32((const unsigned char *) (*ptes), pt_size);
 
        if (crc != le32_to_cpu((*gpt)->partition_entry_array_crc32)) {
                pr_debug("GUID Partition Entry Array CRC check failed.\n");