From: Jan Kara Subject: [PATCH 2/3] udf: Avoid run away loop when partition table length is corrupted Date: Wed, 4 Jul 2012 12:55:17 +0200 Message-ID: <1341399318-13744-3-git-send-email-jack@suse.cz> References: <1341399318-13744-1-git-send-email-jack@suse.cz> Cc: , Jan Kara To: stable@kernel.org Return-path: Received: from cantor2.suse.de ([195.135.220.15]:57036 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933907Ab2GDKzq (ORCPT ); Wed, 4 Jul 2012 06:55:46 -0400 In-Reply-To: <1341399318-13744-1-git-send-email-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Check provided length of partition table so that (possibly maliciously) corrupted partition table cannot cause accessing data beyond current buffer. Signed-off-by: Jan Kara --- fs/udf/super.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) Index: linux-3.0-SLE11-SP2/fs/udf/super.c =================================================================== --- linux-3.0-SLE11-SP2.orig/fs/udf/super.c +++ linux-3.0-SLE11-SP2/fs/udf/super.c @@ -1254,6 +1254,7 @@ static int udf_load_logicalvol(struct su struct genericPartitionMap *gpm; uint16_t ident; struct buffer_head *bh; + unsigned int table_len; int ret = 0; bh = udf_read_tagged(sb, block, block, &ident); @@ -1261,13 +1262,20 @@ static int udf_load_logicalvol(struct su return 1; BUG_ON(ident != TAG_IDENT_LVD); lvd = (struct logicalVolDesc *)bh->b_data; + table_len = le32_to_cpu(lvd->mapTableLength); + if (sizeof(*lvd) + table_len > sb->s_blocksize) { + udf_error(sb, __func__, "error loading logical volume descriptor: " + "Partition table too long (%u > %lu)\n", table_len, + sb->s_blocksize - sizeof(*lvd)); + goto out_bh; + } ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps)); if (ret) goto out_bh; for (i = 0, offset = 0; - i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength); + i < sbi->s_partitions && offset < table_len; i++, offset += gpm->partitionMapLength) { struct udf_part_map *map = &sbi->s_partmaps[i]; gpm = (struct genericPartitionMap *)