Skip to content

Commit adee11b

Browse files
committed
udf: Avoid run away loop when partition table length is corrupted
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 <jack@suse.cz>
1 parent cb14d34 commit adee11b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎fs/udf/super.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,20 +1225,28 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
12251225
struct genericPartitionMap *gpm;
12261226
uint16_t ident;
12271227
struct buffer_head *bh;
1228+
unsigned int table_len;
12281229
int ret = 0;
12291230

12301231
bh = udf_read_tagged(sb, block, block, &ident);
12311232
if (!bh)
12321233
return 1;
12331234
BUG_ON(ident != TAG_IDENT_LVD);
12341235
lvd = (struct logicalVolDesc *)bh->b_data;
1236+
table_len = le32_to_cpu(lvd->mapTableLength);
1237+
if (sizeof(*lvd) + table_len > sb->s_blocksize) {
1238+
udf_err(sb, "error loading logical volume descriptor: "
1239+
"Partition table too long (%u > %lu)\n", table_len,
1240+
sb->s_blocksize - sizeof(*lvd));
1241+
goto out_bh;
1242+
}
12351243

12361244
ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
12371245
if (ret)
12381246
goto out_bh;
12391247

12401248
for (i = 0, offset = 0;
1241-
i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
1249+
i < sbi->s_partitions && offset < table_len;
12421250
i++, offset += gpm->partitionMapLength) {
12431251
struct udf_part_map *map = &sbi->s_partmaps[i];
12441252
gpm = (struct genericPartitionMap *)

0 commit comments

Comments
 (0)