add patch fix-warning-message-in-ext4_enable_quotas
[ext4-patch-queue.git] / fix-ext4_check_descriptors
blob27b04251ea744b8e5fa268c0417ef17a923eea3d
1 ext4: fix false negatives *and* false positives in ext4_check_descriptors()
3 Ext4_check_descriptors() was getting called before s_gdb_count was
4 initialized.  So for file systems w/o the meta_bg feature, allocation
5 bitmaps could overlap the block group descriptors and ext4 wouldn't
6 notice.
8 For file systems with the meta_bg feature enabled, there was a
9 fencepost error which would cause the ext4_check_descriptors() to
10 incorrectly believe that the block allocation bitmap overlaps with the
11 block group descriptor blocks, and it would reject the mount.
13 Fix both of these problems.
15 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 Cc: stable@vger.kernel.org
17 ---
18 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
19 index f36c9f774e83..90d0e113a174 100644
20 --- a/fs/ext4/super.c
21 +++ b/fs/ext4/super.c
22 @@ -2348,7 +2348,7 @@ static int ext4_check_descriptors(struct super_block *sb,
23         struct ext4_sb_info *sbi = EXT4_SB(sb);
24         ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
25         ext4_fsblk_t last_block;
26 -       ext4_fsblk_t last_bg_block = sb_block + ext4_bg_num_gdb(sb, 0) + 1;
27 +       ext4_fsblk_t last_bg_block = sb_block + ext4_bg_num_gdb(sb, 0);
28         ext4_fsblk_t block_bitmap;
29         ext4_fsblk_t inode_bitmap;
30         ext4_fsblk_t inode_table;
31 @@ -4092,14 +4092,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
32                         goto failed_mount2;
33                 }
34         }
35 +       sbi->s_gdb_count = db_count;
36         if (!ext4_check_descriptors(sb, logical_sb_block, &first_not_zeroed)) {
37                 ext4_msg(sb, KERN_ERR, "group descriptors corrupted!");
38                 ret = -EFSCORRUPTED;
39                 goto failed_mount2;
40         }
42 -       sbi->s_gdb_count = db_count;
44         timer_setup(&sbi->s_err_report, print_daily_error_info, 0);
46         /* Register extent status tree shrinker */