Commit b1a75800 authored by Theodore Ts'o's avatar Theodore Ts'o Committed by Sasha Levin

ext4: add sanity checking to count_overhead()

[ Upstream commit c48ae41b ]

The commit "ext4: sanity check the block and cluster size at mount
time" should prevent any problems, but in case the superblock is
modified while the file system is mounted, add an extra safety check
to make sure we won't overrun the allocated buffer.
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarSasha Levin <alexander.levin@verizon.com>
parent 31eb998a
...@@ -3361,10 +3361,15 @@ static int count_overhead(struct super_block *sb, ext4_group_t grp, ...@@ -3361,10 +3361,15 @@ static int count_overhead(struct super_block *sb, ext4_group_t grp,
ext4_set_bit(s++, buf); ext4_set_bit(s++, buf);
count++; count++;
} }
for (j = ext4_bg_num_gdb(sb, grp); j > 0; j--) { j = ext4_bg_num_gdb(sb, grp);
if (s + j > EXT4_BLOCKS_PER_GROUP(sb)) {
ext4_error(sb, "Invalid number of block group "
"descriptor blocks: %d", j);
j = EXT4_BLOCKS_PER_GROUP(sb) - s;
}
count += j;
for (; j > 0; j--)
ext4_set_bit(EXT4_B2C(sbi, s++), buf); ext4_set_bit(EXT4_B2C(sbi, s++), buf);
count++;
}
} }
if (!count) if (!count)
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment