diff options
author | Chao Yu <chao@kernel.org> | 2024-02-19 10:28:44 +0800 |
---|---|---|
committer | Sasha Levin <sashal@kernel.org> | 2024-03-26 18:20:56 -0400 |
commit | 7486973accbc4a9046cdbcdf94028a9a7b67c890 (patch) | |
tree | 55e5b83a9ac7d21d6d43065a318e6549235eccb6 | |
parent | 18631d43d487233237dc41e765d067d2915fae8b (diff) |
f2fs: compress: fix to check compress flag w/ .i_sem lock
[ Upstream commit ea59b12ac69774c08aa95cd5b6100700ea0cce97 ]
It needs to check compress flag w/ .i_sem lock, otherwise, compressed
inode may be disabled after the check condition, it's not needed to
set compress option on non-compress inode.
Fixes: e1e8debec656 ("f2fs: add F2FS_IOC_SET_COMPRESS_OPTION ioctl")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | fs/f2fs/file.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 96b59c87f30c..be4cab941d29 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3967,16 +3967,20 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) sizeof(option))) return -EFAULT; - if (!f2fs_compressed_file(inode) || - option.log_cluster_size < MIN_COMPRESS_LOG_SIZE || - option.log_cluster_size > MAX_COMPRESS_LOG_SIZE || - option.algorithm >= COMPRESS_MAX) + if (option.log_cluster_size < MIN_COMPRESS_LOG_SIZE || + option.log_cluster_size > MAX_COMPRESS_LOG_SIZE || + option.algorithm >= COMPRESS_MAX) return -EINVAL; file_start_write(filp); inode_lock(inode); f2fs_down_write(&F2FS_I(inode)->i_sem); + if (!f2fs_compressed_file(inode)) { + ret = -EINVAL; + goto out; + } + if (f2fs_is_mmap_file(inode) || get_dirty_pages(inode)) { ret = -EBUSY; goto out; |