From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Jones Subject: [PATCH] block/partitions/efi.c: ensure that the GPT header is at least the size of the structure. Date: Wed, 20 Feb 2013 09:37:01 -0500 Message-ID: <1361371021-583-2-git-send-email-pjones@redhat.com> References: <20130220173414.fa4886355efd8f85d0d349f4@canb.auug.org.au> <1361371021-583-1-git-send-email-pjones@redhat.com> Return-path: In-Reply-To: <1361371021-583-1-git-send-email-pjones@redhat.com> Sender: linux-kernel-owner@vger.kernel.org To: Stephen Rothwell Cc: Matt Fleming , Jens Axboe , Stephen Warren , Andrew Morton , linux-kernel@vger.kernel.org, linux-next@vger.kernel.org, Peter Jones List-Id: linux-next.vger.kernel.org UEFI 2.3.1D will include a change to the spec language mandating that a GPT header must be greater than *or equal to* the size of the defined structure. While verifying that this would work on Linux, I discovered that we're not actually checking the minimum bound at all. The result of this is that when we verify the checksum, it's possible that on a malformed header (with header_size of 0), we won't actually verify any data. Signed-off-by: Peter Jones Cc: Matt Fleming Cc: Jens Axboe Cc: Stephen Warren Cc: Andrew Morton --- block/partitions/efi.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index b62fb88..62e05cf 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -310,15 +310,23 @@ static int is_gpt_valid(struct parsed_partitions *state, u64 lba, goto fail; } - /* Check the GUID Partition Table header size */ + /* Check the GUID Partition Table header size is too big */ if (le32_to_cpu((*gpt)->header_size) > bdev_logical_block_size(state->bdev)) { - pr_debug("GUID Partition Table Header size is wrong: %u > %u\n", + pr_debug("GUID Partition Table Header size is too large: %u > %u\n", le32_to_cpu((*gpt)->header_size), bdev_logical_block_size(state->bdev)); goto fail; } + /* Check the GUID Partition Table header size is too small */ + if (le32_to_cpu((*gpt)->header_size) < sizeof(gpt_header)) { + pr_debug("GUID Partition Table Header size is too small: %u < %lu\n", + le32_to_cpu((*gpt)->header_size), + (unsigned long)sizeof(gpt_header)); + goto fail; + } + /* Check the GUID Partition Table CRC */ origcrc = le32_to_cpu((*gpt)->header_crc32); (*gpt)->header_crc32 = 0; -- 1.8.1.2