Skip to content

Commit ebbe26f

Browse files
committed
udf: Avoid excessive partition lengths
Avoid mounting filesystems where the partition would overflow the 32-bits used for block number. Also refuse to mount filesystems where the partition length is so large we cannot safely index bits in a block bitmap. Link: https://patch.msgid.link/[email protected] Signed-off-by: Jan Kara <[email protected]>
1 parent 8037da3 commit ebbe26f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fs/udf/super.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,12 +1111,19 @@ static int udf_fill_partdesc_info(struct super_block *sb,
11111111
struct udf_part_map *map;
11121112
struct udf_sb_info *sbi = UDF_SB(sb);
11131113
struct partitionHeaderDesc *phd;
1114+
u32 sum;
11141115
int err;
11151116

11161117
map = &sbi->s_partmaps[p_index];
11171118

11181119
map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
11191120
map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
1121+
if (check_add_overflow(map->s_partition_root, map->s_partition_len,
1122+
&sum)) {
1123+
udf_err(sb, "Partition %d has invalid location %u + %u\n",
1124+
p_index, map->s_partition_root, map->s_partition_len);
1125+
return -EFSCORRUPTED;
1126+
}
11201127

11211128
if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
11221129
map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
@@ -1172,6 +1179,14 @@ static int udf_fill_partdesc_info(struct super_block *sb,
11721179
bitmap->s_extPosition = le32_to_cpu(
11731180
phd->unallocSpaceBitmap.extPosition);
11741181
map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
1182+
/* Check whether math over bitmap won't overflow. */
1183+
if (check_add_overflow(map->s_partition_len,
1184+
sizeof(struct spaceBitmapDesc) << 3,
1185+
&sum)) {
1186+
udf_err(sb, "Partition %d is too long (%u)\n", p_index,
1187+
map->s_partition_len);
1188+
return -EFSCORRUPTED;
1189+
}
11751190
udf_debug("unallocSpaceBitmap (part %d) @ %u\n",
11761191
p_index, bitmap->s_extPosition);
11771192
}

0 commit comments

Comments
 (0)