From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753348AbbFDSYp (ORCPT ); Thu, 4 Jun 2015 14:24:45 -0400 Received: from smtp.outflux.net ([198.145.64.163]:33844 "EHLO smtp.outflux.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752566AbbFDSYn (ORCPT ); Thu, 4 Jun 2015 14:24:43 -0400 X-Greylist: delayed 515 seconds by postgrey-1.27 at vger.kernel.org; Thu, 04 Jun 2015 14:24:43 EDT Date: Thu, 4 Jun 2015 11:15:53 -0700 From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Jens Axboe , Dan Carpenter , Rasmus Villemoes Subject: [PATCH] mac: validate mac_partition is within sector Message-ID: <20150604181553.GA6033@www.outflux.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-HELO: www.outflux.net Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If md->signature == MAC_DRIVER_MAGIC and md->block_size == 1023, a single 512 byte sector would be read (secsize / 512). However the partition structure would be located past the end of the buffer (secsize % 512). Signed-off-by: Kees Cook --- I don't have any way to test this at the moment. Does this look sensible to others? I just noticed it during manual review of the code. I'm unclear how prefetch works in this case, but I suspect this isn't actually exploitable since pagesize > 512. But for correctness, I think the patch is a good idea. --- block/partitions/mac.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/block/partitions/mac.c b/block/partitions/mac.c index c2c48ec64b27..621317ac4d59 100644 --- a/block/partitions/mac.c +++ b/block/partitions/mac.c @@ -32,7 +32,7 @@ int mac_partition(struct parsed_partitions *state) Sector sect; unsigned char *data; int slot, blocks_in_map; - unsigned secsize; + unsigned secsize, datasize, partoffset; #ifdef CONFIG_PPC_PMAC int found_root = 0; int found_root_goodness = 0; @@ -50,10 +50,14 @@ int mac_partition(struct parsed_partitions *state) } secsize = be16_to_cpu(md->block_size); put_dev_sector(sect); - data = read_part_sector(state, secsize/512, §); + datasize = round_down(secsize, 512); + data = read_part_sector(state, datasize / 512, §); if (!data) return -1; - part = (struct mac_partition *) (data + secsize%512); + partoffset = secsize % 512; + if (partoffset + sizeof(*part) > datasize) + return -1; + part = (struct mac_partition *) (data + partoffset); if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) { put_dev_sector(sect); return 0; /* not a MacOS disk */ -- 1.9.1 -- Kees Cook Chrome OS Security