Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753822AbcCAXxH (ORCPT ); Tue, 1 Mar 2016 18:53:07 -0500 Received: from mail333.us4.mandrillapp.com ([205.201.137.77]:48984 "EHLO mail333.us4.mandrillapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754802AbcCAXwE (ORCPT ); Tue, 1 Mar 2016 18:52:04 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; q=dns; s=mandrill; d=linuxfoundation.org; b=j88yOTzeDCTliOMvZiHQ7djeNGEyHXaJ+e+YNg+HpiT3u4fkEb+dGeZ02JdrMjlH8Y+IQ+B1ME/N SqLTm+D+0tYAZGWDJRAyZPBLnsfEFFrBUPhfiQ3XdVQtftbTA/ukaWmIDnuoTlusgo6QOcNaJBNG 3HxOcbt9sf2J8fFWgEg=; From: Greg Kroah-Hartman Subject: [PATCH 3.14 063/130] mac: validate mac_partition is within sector X-Mailer: git-send-email 2.7.2 To: Cc: Greg Kroah-Hartman , , Kees Cook , Jens Axboe Message-Id: <20160301234502.042116677@linuxfoundation.org> In-Reply-To: <20160301234459.768886030@linuxfoundation.org> References: <20160301234459.768886030@linuxfoundation.org> X-Report-Abuse: Please forward a copy of this message, including all headers, to abuse@mandrill.com X-Report-Abuse: You can also report abuse here: http://mandrillapp.com/contact/abuse?id=30481620.dea411b8d48c40428be954bf58357aed X-Mandrill-User: md_30481620 Date: Tue, 01 Mar 2016 23:51:18 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1614 Lines: 48 3.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook commit 02e2a5bfebe99edcf9d694575a75032d53fe1b73 upstream. 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 Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/partitions/mac.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/block/partitions/mac.c +++ b/block/partitions/mac.c @@ -32,7 +32,7 @@ int mac_partition(struct parsed_partitio 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_partitio } 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 */