summaryrefslogtreecommitdiff
path: root/fs/ext4/super.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2016-11-18 21:37:47 +0300
committerSasha Levin <alexander.levin@verizon.com>2017-01-15 17:49:49 +0300
commitcefafbaa4a6ae8141182a7eb1d24e611483dfcb4 (patch)
tree8491853eb75c340cc0d2e830c4a534ba0e6f6237 /fs/ext4/super.c
parentf358bbb9f1922f34e9056bb6a3ba60abc825a10e (diff)
downloadlinux-cefafbaa4a6ae8141182a7eb1d24e611483dfcb4.tar.xz
ext4: add sanity checking to count_overhead()
[ Upstream commit c48ae41bafe31e9a66d8be2ced4e42a6b57fa814 ] 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: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Diffstat (limited to 'fs/ext4/super.c')
-rw-r--r--fs/ext4/super.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index ea08ab7173b5..a5200023e604 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3325,10 +3325,15 @@ static int count_overhead(struct super_block *sb, ext4_group_t grp,
ext4_set_bit(s++, buf);
count++;
}
- for (j = ext4_bg_num_gdb(sb, grp); j > 0; j--) {
- ext4_set_bit(EXT4_B2C(sbi, s++), buf);
- count++;
+ 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);
}
if (!count)
return 0;