Skip to content

Commit b3d8306

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to avoid NULL pointer dereference in f2fs_issue_flush()
With below two cases, it will cause NULL pointer dereference when accessing SM_I(sbi)->fcc_info in f2fs_issue_flush(). a) If kthread_run() fails in f2fs_create_flush_cmd_control(), it will release SM_I(sbi)->fcc_info, - mount -o noflush_merge /dev/vda /mnt/f2fs - mount -o remount,flush_merge /dev/vda /mnt/f2fs -- kthread_run() fails - dd if=/dev/zero of=/mnt/f2fs/file bs=4k count=1 conv=fsync b) we will never allocate memory for SM_I(sbi)->fcc_info w/ below testcase, - mount -o ro /dev/vda /mnt/f2fs - mount -o rw,remount /dev/vda /mnt/f2fs - dd if=/dev/zero of=/mnt/f2fs/file bs=4k count=1 conv=fsync In order to fix this issue, let change as below: - fix error path handling in f2fs_create_flush_cmd_control(). - allocate SM_I(sbi)->fcc_info even if readonly is on. Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 69b41ac commit b3d8306

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

fs/f2fs/segment.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi)
663663
if (IS_ERR(fcc->f2fs_issue_flush)) {
664664
int err = PTR_ERR(fcc->f2fs_issue_flush);
665665

666-
kfree(fcc);
667-
SM_I(sbi)->fcc_info = NULL;
666+
fcc->f2fs_issue_flush = NULL;
668667
return err;
669668
}
670669

@@ -5138,11 +5137,9 @@ int f2fs_build_segment_manager(struct f2fs_sb_info *sbi)
51385137

51395138
init_f2fs_rwsem(&sm_info->curseg_lock);
51405139

5141-
if (!f2fs_readonly(sbi->sb)) {
5142-
err = f2fs_create_flush_cmd_control(sbi);
5143-
if (err)
5144-
return err;
5145-
}
5140+
err = f2fs_create_flush_cmd_control(sbi);
5141+
if (err)
5142+
return err;
51465143

51475144
err = create_discard_cmd_control(sbi);
51485145
if (err)

0 commit comments

Comments
 (0)