Skip to content

Commit 172e344

Browse files
Ye Bintytso
authored andcommitted
ext4: init error handle resource before init group descriptors
Now, 's_err_report' timer is init after ext4_group_desc_init() when fill super. Theoretically, ext4_group_desc_init() may access to error handle as follows: __ext4_fill_super ext4_group_desc_init ext4_check_descriptors ext4_get_group_desc ext4_error ext4_handle_error ext4_commit_super ext4_update_super if (!es->s_error_count) mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ); --> Accessing Uninitialized Variables timer_setup(&sbi->s_err_report, print_daily_error_info, 0); Maybe above issue is just theoretical, as ext4_check_descriptors() didn't judge 'gpd' which get from ext4_get_group_desc(), if access to error handle ext4_get_group_desc() will return NULL, then will trigger null-ptr-deref in ext4_check_descriptors(). However, from the perspective of pure code, it is better to initialize resource that may need to be used first. Signed-off-by: Ye Bin <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0f7bfd6 commit 172e344

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

fs/ext4/super.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4738,7 +4738,6 @@ static int ext4_group_desc_init(struct super_block *sb,
47384738
struct ext4_sb_info *sbi = EXT4_SB(sb);
47394739
unsigned int db_count;
47404740
ext4_fsblk_t block;
4741-
int ret;
47424741
int i;
47434742

47444743
db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
@@ -4778,8 +4777,7 @@ static int ext4_group_desc_init(struct super_block *sb,
47784777
ext4_msg(sb, KERN_ERR,
47794778
"can't read group descriptor %d", i);
47804779
sbi->s_gdb_count = i;
4781-
ret = PTR_ERR(bh);
4782-
goto out;
4780+
return PTR_ERR(bh);
47834781
}
47844782
rcu_read_lock();
47854783
rcu_dereference(sbi->s_group_desc)[i] = bh;
@@ -4788,13 +4786,10 @@ static int ext4_group_desc_init(struct super_block *sb,
47884786
sbi->s_gdb_count = db_count;
47894787
if (!ext4_check_descriptors(sb, logical_sb_block, first_not_zeroed)) {
47904788
ext4_msg(sb, KERN_ERR, "group descriptors corrupted!");
4791-
ret = -EFSCORRUPTED;
4792-
goto out;
4789+
return -EFSCORRUPTED;
47934790
}
4791+
47944792
return 0;
4795-
out:
4796-
ext4_group_desc_free(sbi);
4797-
return ret;
47984793
}
47994794

48004795
static int ext4_load_and_init_journal(struct super_block *sb,
@@ -5220,14 +5215,14 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
52205215
if (ext4_geometry_check(sb, es))
52215216
goto failed_mount;
52225217

5223-
err = ext4_group_desc_init(sb, es, logical_sb_block, &first_not_zeroed);
5224-
if (err)
5225-
goto failed_mount;
5226-
52275218
timer_setup(&sbi->s_err_report, print_daily_error_info, 0);
52285219
spin_lock_init(&sbi->s_error_lock);
52295220
INIT_WORK(&sbi->s_error_work, flush_stashed_error_work);
52305221

5222+
err = ext4_group_desc_init(sb, es, logical_sb_block, &first_not_zeroed);
5223+
if (err)
5224+
goto failed_mount3;
5225+
52315226
/* Register extent status tree shrinker */
52325227
if (ext4_es_register_shrinker(sbi))
52335228
goto failed_mount3;

0 commit comments

Comments
 (0)