[f2fs-dev] [PATCH] f2fs: check cp_error before committing atomic writes

Wenjie Qi <[email protected]> Thu, 6 Aug 2026 14:18:07 +0800
Newsgroups net.sourceforge.lists.linux-f2fs-devel,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
F2FS checks cp_error before entering the ioctl path, but cp_error can be
set after that and before atomic commit starts replacing blocks.

In that case, F2FS_IOC_COMMIT_ATOMIC_WRITE returns -EIO, but the current
mount can still expose the new data before remount.

Check cp_error again in f2fs_commit_atomic_write() after
filemap_write_and_wait_range() and before block replacement starts.

Fixes: 3db1de0e582c ("f2fs: change the current atomic write way")
Cc: [email protected]
Signed-off-by: Wenjie Qi <[email protected]>
---
 fs/f2fs/segment.c | 3 +++
 1 file changed, 3 insertions(+)

QEMU validation:
- before fix, FAULT_CHECKPOINT made COMMIT_ATOMIC_WRITE fail with -EIO,
  while the current mount still exposed the new data; after remount, the
  file reverted to the old data.
- after fix, the same fault still failed with -EIO, and both the current
  mount and the remounted filesystem kept the old data.
- no-fault smoke still committed the new data successfully and preserved it
  across remount.

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 0b706568b034..e6384dd2e916 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -408,6 +408,9 @@ int f2fs_commit_atomic_write(struct inode *inode)
 	if (err)
 		return err;
 
+	if (unlikely(f2fs_cp_error(sbi)))
+		return -EIO;
+
 	f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
 	f2fs_lock_op(sbi, &lc);
 
-- 
2.43.0


_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel