Commit b5ab327
f2fs: fix to avoid mmap vs set_compress_option case
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: e1e8deb ("f2fs: add F2FS_IOC_SET_COMPRESS_OPTION ioctl")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>1 parent c709d09 commit b5ab327
2 files changed
Lines changed: 20 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4483 | 4483 | | |
4484 | 4484 | | |
4485 | 4485 | | |
4486 | | - | |
| 4486 | + | |
| 4487 | + | |
4487 | 4488 | | |
4488 | 4489 | | |
4489 | 4490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
| 529 | + | |
| 530 | + | |
529 | 531 | | |
| 532 | + | |
| 533 | + | |
530 | 534 | | |
531 | 535 | | |
532 | 536 | | |
| |||
1919 | 1923 | | |
1920 | 1924 | | |
1921 | 1925 | | |
1922 | | - | |
1923 | | - | |
1924 | | - | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
1925 | 1932 | | |
1926 | | - | |
1927 | | - | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
1928 | 1939 | | |
1929 | 1940 | | |
1930 | 1941 | | |
| |||
3976 | 3987 | | |
3977 | 3988 | | |
3978 | 3989 | | |
| 3990 | + | |
3979 | 3991 | | |
3980 | 3992 | | |
3981 | 3993 | | |
| |||
3995 | 4007 | | |
3996 | 4008 | | |
3997 | 4009 | | |
| 4010 | + | |
3998 | 4011 | | |
3999 | 4012 | | |
4000 | 4013 | | |
| |||
0 commit comments