]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: fix to check return value of f2fs_do_truncate_blocks()
authorChao Yu <chao@kernel.org>
Wed, 5 Apr 2023 14:44:53 +0000 (22:44 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 May 2023 14:11:14 +0000 (23:11 +0900)
[ Upstream commit b851ee6ba3cc212641e622ebcf92b950c7bafa07 ]

Otherwise, if truncation on cow_inode failed, remained data may
pollute current transaction of atomic write.

Cc: Daeho Jeong <daehojeong@google.com>
Fixes: a46bebd502fe ("f2fs: synchronize atomic write aborts")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/file.c

index 23fb9861dba401cf3794e9da7d16f66798e82e2d..de92279a80020c3d948518e0e9a7a81e5e6c9841 100644 (file)
@@ -2117,7 +2117,11 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)
                clear_inode_flag(fi->cow_inode, FI_INLINE_DATA);
        } else {
                /* Reuse the already created COW inode */
-               f2fs_do_truncate_blocks(fi->cow_inode, 0, true);
+               ret = f2fs_do_truncate_blocks(fi->cow_inode, 0, true);
+               if (ret) {
+                       f2fs_up_write(&fi->i_gc_rwsem[WRITE]);
+                       goto out;
+               }
        }
 
        f2fs_write_inode(inode, NULL);