linux-stable/fs/f2fs
Fengnan Chang 9b56adcf52 f2fs: fix compressed file start atomic write may cause data corruption
When compressed file has blocks, f2fs_ioc_start_atomic_write will succeed,
but compressed flag will be remained in inode. If write partial compreseed
cluster and commit atomic write will cause data corruption.

This is the reproduction process:
Step 1:
create a compressed file ,write 64K data , call fsync(), then the blocks
are write as compressed cluster.
Step2:
iotcl(F2FS_IOC_START_ATOMIC_WRITE)  --- this should be fail, but not.
write page 0 and page 3.
iotcl(F2FS_IOC_COMMIT_ATOMIC_WRITE)  -- page 0 and 3 write as normal file,
Step3:
drop cache.
read page 0-4   -- Since page 0 has a valid block address, read as
non-compressed cluster, page 1 and 2 will be filled with compressed data
or zero.

The root cause is, after commit 7eab7a6968 ("f2fs: compress: remove
unneeded read when rewrite whole cluster"), in step 2, f2fs_write_begin()
only set target page dirty, and in f2fs_commit_inmem_pages(), we will write
partial raw pages into compressed cluster, result in corrupting compressed
cluster layout.

Fixes: 4c8ff7095b ("f2fs: support data compression")
Fixes: 7eab7a6968 ("f2fs: compress: remove unneeded read when rewrite whole cluster")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2022-03-18 09:12:48 -07:00
..
acl.c f2fs: support idmapped mounts 2022-02-12 06:20:46 -08:00
acl.h vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
checkpoint.c f2fs: avoid an infinite loop in f2fs_sync_dirty_inodes 2022-03-04 09:15:46 -08:00
compress.c f2fs: compress: fix to print raw data size in error path of lz4 decompression 2022-03-17 09:16:22 -07:00
data.c f2fs: fix compressed file start atomic write may cause data corruption 2022-03-18 09:12:48 -07:00
debug.c f2fs: introduce gc_urgent_mid mode 2022-03-17 09:16:22 -07:00
dir.c f2fs: move f2fs to use reader-unfair rwsems 2022-01-24 17:40:04 -08:00
extent_cache.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
f2fs.h f2fs: introduce gc_urgent_mid mode 2022-03-17 09:16:22 -07:00
file.c f2fs: fix compressed file start atomic write may cause data corruption 2022-03-18 09:12:48 -07:00
gc.c f2fs: introduce gc_urgent_mid mode 2022-03-17 09:16:22 -07:00
gc.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
hash.c f2fs: Handle casefolding with Encryption 2020-12-02 22:00:21 -08:00
inline.c f2fs: move f2fs to use reader-unfair rwsems 2022-01-24 17:40:04 -08:00
inode.c f2fs: don't get FREEZE lock in f2fs_evict_inode in frozen fs 2022-03-11 07:36:17 -08:00
iostat.c f2fs: use iomap for direct I/O 2021-12-10 15:48:30 -08: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: remove redundant parameter judgment 2022-03-17 09:16:22 -07:00
node.c f2fs: fix to avoid potential deadlock 2022-03-03 13:30:48 -08:00
node.h f2fs: add a way to limit roll forward recovery time 2022-02-12 05:58:18 -08:00
recovery.c f2fs: add a way to limit roll forward recovery time 2022-02-12 05:58:18 -08:00
segment.c f2fs: fix to do sanity check on curseg->alloc_type 2022-03-03 18:19:41 -08:00
segment.h f2fs: introduce F2FS_IPU_HONOR_OPU_WRITE ipu policy 2022-02-07 11:28:35 -08:00
shrinker.c f2fs: avoid race condition for shrinker count 2020-12-03 00:59:26 -08:00
super.c f2fs: initialize sbi->gc_mode explicitly 2022-03-17 23:48:03 -07:00
sysfs.c f2fs: introduce gc_urgent_mid mode 2022-03-17 09:16:22 -07:00
verity.c f2fs: move f2fs to use reader-unfair rwsems 2022-01-24 17:40:04 -08:00
xattr.c f2fs: move f2fs to use reader-unfair rwsems 2022-01-24 17:40:04 -08:00
xattr.h f2fs: code cleanup by removing ifdef macro surrounding 2020-05-26 18:56:10 -07:00