linux-stable/fs/f2fs
Jaewook Kim 6974cec610 f2fs: do not allow to decompress files have FI_COMPRESS_RELEASED
[ Upstream commit 90be48bd9d ]

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: 5fdb322ff2 ("f2fs: add F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMPRESS_FILE")

Signed-off-by: Junbeom Yeom <junbeom.yeom@samsung.com>
Signed-off-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Youngjin Gil <youngjin.gil@samsung.com>
Signed-off-by: Jaewook Kim <jw5454.kim@samsung.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-08-17 14:42:16 +02:00
..
acl.c f2fs: support idmapped mounts 2022-02-12 06:20:46 -08:00
acl.h
checkpoint.c f2fs: kill volatile write support 2022-08-17 14:42:13 +02:00
compress.c Filesystem folio changes for 5.18 2022-03-22 18:26:56 -07:00
data.c f2fs: kill volatile write support 2022-08-17 14:42:13 +02:00
debug.c f2fs: kill volatile write support 2022-08-17 14:42:13 +02:00
dir.c f2fs: don't use casefolded comparison for "." and ".." 2022-06-09 10:30:40 +02:00
extent_cache.c
f2fs.h f2fs: fix to check inline_data during compressed inode conversion 2022-08-17 14:42:13 +02:00
file.c f2fs: do not allow to decompress files have FI_COMPRESS_RELEASED 2022-08-17 14:42:16 +02:00
gc.c f2fs: change the current atomic write way 2022-08-17 14:42:13 +02:00
gc.h
hash.c f2fs: don't use casefolded comparison for "." and ".." 2022-06-09 10:30:40 +02:00
inline.c f2fs: fix to do sanity check for inline inode 2022-06-09 10:30:40 +02:00
inode.c f2fs: change the current atomic write way 2022-08-17 14:42:13 +02:00
iostat.c f2fs: fix iostat related lock protection 2022-06-29 09:04:38 +02:00
iostat.h f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
Kconfig f2fs: introduce F2FS_UNFAIR_RWSEM to support unfair rwsem 2022-03-04 09:15:53 -08:00
Makefile f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
namei.c f2fs: change the current atomic write way 2022-08-17 14:42:13 +02:00
node.c f2fs: change the current atomic write way 2022-08-17 14:42:13 +02:00
node.h f2fs: change the current atomic write way 2022-08-17 14:42:13 +02:00
recovery.c f2fs-for-5.18 2022-03-22 10:00:31 -07:00
segment.c f2fs: kill volatile write support 2022-08-17 14:42:13 +02:00
segment.h f2fs: change the current atomic write way 2022-08-17 14:42:13 +02:00
shrinker.c
super.c f2fs: change the current atomic write way 2022-08-17 14:42:13 +02:00
sysfs.c f2fs-for-5.18 2022-03-22 10:00:31 -07:00
verity.c f2fs: kill volatile write support 2022-08-17 14:42:13 +02:00
xattr.c f2fs: move f2fs to use reader-unfair rwsems 2022-01-24 17:40:04 -08:00
xattr.h