From: Chao Yu chao@kernel.org
stable inclusion from stable-v6.6.33 commit 116d824f953a83bb8d3559b71cbc9fcfd14f2aee category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAD6H2
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=...
--------------------------------
[ Upstream commit bd9ae4ae9e585061acfd4a169f2321706f900246 ]
Compress flag should be checked after inode lock held to avoid racing w/ f2fs_setflags_common() , fix it.
Fixes: 5fdb322ff2c2 ("f2fs: add F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMPRESS_FILE") Reported-by: Zhiguo Niu zhiguo.niu@unisoc.com Closes: https://lore.kernel.org/linux-f2fs-devel/CAHJ8P3LdZXLc2rqeYjvymgYHr2+YLuJ0sL... Signed-off-by: Chao Yu chao@kernel.org Signed-off-by: Jaegeuk Kim jaegeuk@kernel.org Signed-off-by: Sasha Levin sashal@kernel.org Signed-off-by: Wang Hai wanghai38@huawei.com --- fs/f2fs/file.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 45ac1d53310b..17a3c891b848 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4091,9 +4091,6 @@ static int f2fs_ioc_decompress_file(struct file *filp) if (!(filp->f_mode & FMODE_WRITE)) return -EBADF;
- if (!f2fs_compressed_file(inode)) - return -EINVAL; - f2fs_balance_fs(sbi, true);
file_start_write(filp); @@ -4104,7 +4101,8 @@ static int f2fs_ioc_decompress_file(struct file *filp) 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; } @@ -4170,9 +4168,6 @@ static int f2fs_ioc_compress_file(struct file *filp) if (!(filp->f_mode & FMODE_WRITE)) return -EBADF;
- if (!f2fs_compressed_file(inode)) - return -EINVAL; - f2fs_balance_fs(sbi, true);
file_start_write(filp); @@ -4183,7 +4178,8 @@ static int f2fs_ioc_compress_file(struct file *filp) 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; }