• Chao Yu's avatar
    f2fs: fix to avoid mmap vs set_compress_option case · b5ab3276
    Chao Yu authored
    Compression option in inode should not be changed after they have
    been used, however, it may happen in below race case:
    
    Thread A				Thread B
    - f2fs_ioc_set_compress_option
     - check f2fs_is_mmap_file()
     - check get_dirty_pages()
     - check F2FS_HAS_BLOCKS()
    					- f2fs_file_mmap
    					 - set_inode_flag(FI_MMAP_FILE)
    					- fault
    					 - do_page_mkwrite
    					  - f2fs_vm_page_mkwrite
    					  - f2fs_get_block_locked
    					 - fault_dirty_shared_page
    					  - set_page_dirty
     - update i_compress_algorithm
     - update i_log_cluster_size
     - update i_cluster_size
    
    Avoid such race condition by covering f2fs_file_mmap() w/ i_sem lock,
    meanwhile add mmap file check condition in f2fs_may_compress() as well.
    
    Fixes: e1e8debe ("f2fs: add F2FS_IOC_SET_COMPRESS_OPTION ioctl")
    Signed-off-by: default avatarChao Yu <chao@kernel.org>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
    b5ab3276
f2fs.h 149 KB