diff options
author | Chao Yu <chao@kernel.org> | 2024-04-07 10:26:03 +0300 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2024-04-12 23:58:35 +0300 |
commit | 7c5dffb3d90c5921b91981cc663e02757d90526e (patch) | |
tree | d0506dede13413076039176d29760fb03fda73bf /fs/f2fs | |
parent | 0f9b12142be1af8555cfe53c6fbecb8e60a40dac (diff) | |
download | linux-7c5dffb3d90c5921b91981cc663e02757d90526e.tar.xz |
f2fs: compress: fix to relocate check condition in f2fs_{release,reserve}_compress_blocks()
Compress flag should be checked after inode lock held to avoid
racing w/ f2fs_setflags_common(), fix it.
Fixes: 4c8ff7095bef ("f2fs: support data compression")
Reported-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Closes: https://lore.kernel.org/linux-f2fs-devel/CAHJ8P3LdZXLc2rqeYjvymgYHr2+YLuJ0sLG9DdsJZmwO7deuhw@mail.gmail.com
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r-- | fs/f2fs/file.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index bd55bbb4fa67..e4435461aeeb 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3543,9 +3543,6 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) if (!f2fs_sb_has_compression(sbi)) return -EOPNOTSUPP; - if (!f2fs_compressed_file(inode)) - return -EINVAL; - if (f2fs_readonly(sbi->sb)) return -EROFS; @@ -3564,7 +3561,8 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) goto out; } - if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + if (!f2fs_compressed_file(inode) || + is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { ret = -EINVAL; goto out; } @@ -3725,9 +3723,6 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) if (!f2fs_sb_has_compression(sbi)) return -EOPNOTSUPP; - if (!f2fs_compressed_file(inode)) - return -EINVAL; - if (f2fs_readonly(sbi->sb)) return -EROFS; @@ -3739,7 +3734,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) inode_lock(inode); - if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + if (!f2fs_compressed_file(inode) || + !is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { ret = -EINVAL; goto unlock_inode; } |