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 7eab7a696827 ("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: 4c8ff7095bef ("f2fs: support data compression")
Fixes: 7eab7a696827 ("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
..
2022-01-22 08:33:37 +02:00
2021-08-19 09:02:55 +09:00
2022-01-22 08:33:38 +02:00
2022-01-22 10:59:32 +02:00
2022-01-19 23:14:34 -06:00
2021-11-09 10:02:51 -08:00
2021-10-25 19:11:50 -07:00
2022-01-12 11:11:34 -08:00
2021-12-03 18:44:06 +01:00
2022-01-12 15:46:11 -08:00
2022-01-22 08:33:38 +02:00
2022-01-12 11:11:34 -08:00
2022-01-12 15:46:11 -08:00
2022-01-22 08:33:37 +02:00
2021-11-03 09:23:25 -07:00
2022-01-20 13:39:13 +02:00
2022-01-22 08:33:38 +02:00
2022-01-23 06:20:44 +02:00
2022-01-22 08:33:37 +02:00
2022-01-10 11:48:37 -08:00
\n
2021-11-06 16:40:48 -07:00
2022-01-16 10:15:32 +02:00
2021-08-19 09:02:55 +09:00
2022-01-22 11:04:27 +02:00
2021-12-17 16:56:35 +09:00
2022-01-22 08:33:34 +02:00
2021-11-17 09:26:09 +01:00
2022-01-12 13:45:12 -08:00
2022-01-22 08:33:35 +02:00
2022-01-21 16:07:21 +02:00
2022-01-07 13:40:39 +00:00
2022-01-22 08:33:38 +02:00
2022-01-22 08:33:36 +02:00
2022-01-22 08:33:36 +02:00
2022-01-22 08:33:38 +02:00
2021-08-10 17:57:22 +02:00