Skip to content

Commit c704a32

Browse files
jankaraopsiff
authored andcommitted
udf: Verify partition map count
[ Upstream commit 1a11201 ] 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: syzbot+478f2c1a6f0f447a46bb@syzkaller.appspotmail.com Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 5a1e1ab8379639315535d5d77d70bc9af114c2f8)
1 parent b367318 commit c704a32

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

fs/udf/super.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
14091409
struct genericPartitionMap *gpm;
14101410
uint16_t ident;
14111411
struct buffer_head *bh;
1412-
unsigned int table_len;
1412+
unsigned int table_len, part_map_count;
14131413
int ret;
14141414

14151415
bh = udf_read_tagged(sb, block, block, &ident);
@@ -1430,7 +1430,16 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
14301430
"logical volume");
14311431
if (ret)
14321432
goto out_bh;
1433-
ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
1433+
1434+
part_map_count = le32_to_cpu(lvd->numPartitionMaps);
1435+
if (part_map_count > table_len / sizeof(struct genericPartitionMap1)) {
1436+
udf_err(sb, "error loading logical volume descriptor: "
1437+
"Too many partition maps (%u > %u)\n", part_map_count,
1438+
table_len / (unsigned)sizeof(struct genericPartitionMap1));
1439+
ret = -EIO;
1440+
goto out_bh;
1441+
}
1442+
ret = udf_sb_alloc_partition_maps(sb, part_map_count);
14341443
if (ret)
14351444
goto out_bh;
14361445

0 commit comments

Comments
 (0)