Skip to content

Commit 1a11201

Browse files
committed
udf: Verify partition map count
Verify that number of partition maps isn't insanely high which can lead to large allocation in udf_sb_alloc_partition_maps(). All partition maps have to fit in the LVD which is in a single block. Reported-by: [email protected] Signed-off-by: Jan Kara <[email protected]>
1 parent 185d349 commit 1a11201

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fs/udf/super.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
14401440
struct genericPartitionMap *gpm;
14411441
uint16_t ident;
14421442
struct buffer_head *bh;
1443-
unsigned int table_len;
1443+
unsigned int table_len, part_map_count;
14441444
int ret;
14451445

14461446
bh = udf_read_tagged(sb, block, block, &ident);
@@ -1461,7 +1461,16 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
14611461
"logical volume");
14621462
if (ret)
14631463
goto out_bh;
1464-
ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
1464+
1465+
part_map_count = le32_to_cpu(lvd->numPartitionMaps);
1466+
if (part_map_count > table_len / sizeof(struct genericPartitionMap1)) {
1467+
udf_err(sb, "error loading logical volume descriptor: "
1468+
"Too many partition maps (%u > %u)\n", part_map_count,
1469+
table_len / (unsigned)sizeof(struct genericPartitionMap1));
1470+
ret = -EIO;
1471+
goto out_bh;
1472+
}
1473+
ret = udf_sb_alloc_partition_maps(sb, part_map_count);
14651474
if (ret)
14661475
goto out_bh;
14671476

0 commit comments

Comments
 (0)