diff options
| author | Theodore Ts'o <tytso@mit.edu> | 2016-11-18 21:37:47 +0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-01-06 13:16:22 +0300 |
| commit | 1bfcffbb88017c09c1a469507616c88a27037757 (patch) | |
| tree | 1ea4592d58076efc740efaf2945e520113dbcdb5 | |
| parent | 9689eb99ce0f2ea904f7959022e6c1fdee158db1 (diff) | |
| download | linux-1bfcffbb88017c09c1a469507616c88a27037757.tar.xz | |
ext4: add sanity checking to count_overhead()
commit c48ae41bafe31e9a66d8be2ced4e42a6b57fa814 upstream.
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | fs/ext4/super.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 1d6e82e5d1db..104d49f7c328 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3161,10 +3161,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; |
