• Chao Yu's avatar
    f2fs: fix to avoid NULL pointer dereference in f2fs_issue_flush() · b3d83066
    Chao Yu authored
    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: default avatarChao Yu <chao@kernel.org>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
    b3d83066
segment.c 135 KB