Patch "partitions/efi: Fix integer overflow in GPT size calculation" has been added to the 4.4-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
partitions/efi: Fix integer overflow in GPT size calculation
to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
partitions-efi-fix-integer-overflow-in-gpt-size-calculation.patch
and it can be found in the queue-4.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Thu Oct 5 10:49:14 CEST 2017
From: Alden Tondettar <[email protected]>
Date: Sun, 15 Jan 2017 15:31:56 -0700
Subject: partitions/efi: Fix integer overflow in GPT size calculation
From: Alden Tondettar <[email protected]>
[ Upstream commit c5082b70adfe8e1ea1cf4a8eff92c9f260e364d2 ]
If a GUID Partition Table claims to have more than 2**25 entries, the calculation of the partition table size in alloc_read_gpt_entries() will overflow a 32-bit integer and not enough space will be allocated for the table.
Nothing seems to get written out of bounds, but later efi_partition() will read up to 32768 bytes from a 128 byte buffer, possibly OOPSing or exposing information to /proc/partitions and uevents.
The problem exists on both 64-bit and 32-bit platforms.
Fix the overflow and also print a meaningful debug message if the table size is too large.
--- block/partitions/efi.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
block/partitions/efi.c +12 -5
@@ -293,7 +293,7 @@ static gpt_entry *alloc_read_gpt_entriesif (!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 ;
@@ -352,7 +352,7 @@ static int is_gpt_valid(struct parsed_pa gpt_header **gpt, gpt_entry **ptes) {u32 crc, origcrc; -u64 lastlba; +u64 lastlba, pt_size;if (!ptes)return 0 ;
@@ -434,13 +434,20 @@ static int is_gpt_valid(struct parsed_pa 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 Partitition Entry Array CRC check failed.\n" );
Patches currently in stable-queue which might be from [email protected] are
queue-4.4/partitions-efi-fix-integer-overflow-in-gpt-size-calculation.patch