1 ext4: add sanity checking to count_overhead()
3 The commit "ext4: sanity check the block and cluster size at mount
4 time" should prevent any problems, but in case the superblock is
5 modified while the file system is mounted, add an extra safety check
6 to make sure we won't overrun the allocated buffer.
8 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 Cc: stable@vger.kernel.org
11 fs/ext4/super.c | 11 ++++++++---
12 1 file changed, 8 insertions(+), 3 deletions(-)
14 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
15 index 689c02df1af4..2d8a49d74f56 100644
18 @@ -3195,10 +3195,15 @@ static int count_overhead(struct super_block *sb, ext4_group_t grp,
19 ext4_set_bit(s++, buf);
22 - for (j = ext4_bg_num_gdb(sb, grp); j > 0; j--) {
23 - ext4_set_bit(EXT4_B2C(sbi, s++), buf);
25 + j = ext4_bg_num_gdb(sb, grp);
26 + if (s + j > EXT4_BLOCKS_PER_GROUP(sb)) {
27 + ext4_error(sb, "Invalid number of block group "
28 + "descriptor blocks: %d", j);
29 + j = EXT4_BLOCKS_PER_GROUP(sb) - s;
33 + ext4_set_bit(EXT4_B2C(sbi, s++), buf);