Skip to content

Commit 90be48b

Browse files
jw5454kimJaegeuk Kim
authored andcommitted
f2fs: do not allow to decompress files have FI_COMPRESS_RELEASED
If a file has FI_COMPRESS_RELEASED, all writes for it should not be allowed. However, as of now, in case of compress_mode=user, writes triggered by IOCTLs like F2FS_IOC_DE/COMPRESS_FILE are allowed unexpectly, which could crash that file. To fix it, let's do not allow F2FS_IOC_DE/COMPRESS_IOCTL if a file already has FI_COMPRESS_RELEASED flag. This is the reproduction process: 1. $ touch ./file 2. $ chattr +c ./file 3. $ dd if=/dev/random of=./file bs=4096 count=30 conv=notrunc 4. $ dd if=/dev/zero of=./file bs=4096 count=34 seek=30 conv=notrunc 5. $ sync 6. $ do_compress ./file ; call F2FS_IOC_COMPRESS_FILE 7. $ get_compr_blocks ./file ; call F2FS_IOC_GET_COMPRESS_BLOCKS 8. $ release ./file ; call F2FS_IOC_RELEASE_COMPRESS_BLOCKS 9. $ do_compress ./file ; call F2FS_IOC_COMPRESS_FILE again 10. $ get_compr_blocks ./file ; call F2FS_IOC_GET_COMPRESS_BLOCKS again This reproduction process is tested in 128kb cluster size. You can find compr_blocks has a negative value. Fixes: 5fdb322 ("f2fs: add F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMPRESS_FILE") Signed-off-by: Junbeom Yeom <[email protected]> Signed-off-by: Sungjong Seo <[email protected]> Signed-off-by: Youngjin Gil <[email protected]> Signed-off-by: Jaewook Kim <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 912f0d6 commit 90be48b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/f2fs/file.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,6 +3964,11 @@ static int f2fs_ioc_decompress_file(struct file *filp, unsigned long arg)
39643964
goto out;
39653965
}
39663966

3967+
if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
3968+
ret = -EINVAL;
3969+
goto out;
3970+
}
3971+
39673972
ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX);
39683973
if (ret)
39693974
goto out;
@@ -4031,6 +4036,11 @@ static int f2fs_ioc_compress_file(struct file *filp, unsigned long arg)
40314036
goto out;
40324037
}
40334038

4039+
if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
4040+
ret = -EINVAL;
4041+
goto out;
4042+
}
4043+
40344044
ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX);
40354045
if (ret)
40364046
goto out;

0 commit comments

Comments
 (0)