Forwarded: [PATCH] f2fs: fix infinite loop in block_operations() on CP error

syzbot
2025-12-06T10:34:18Z

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] f2fs: fix infinite loop in block_operations() on CP error
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

When IO errors occur and CP_ERROR_FLAG is set, the retry loops in
block_operations() can spin forever. The sync functions (f2fs_sync_dirty_inodes,
f2fs_sync_inode_meta, f2fs_sync_node_pages) may return success even though
dirty pages remain due to IO errors, causing infinite retry loops.

The hung task traces show:
f2fs: block_ops check DIRTY_IMETA=1
f2fs: block_ops retry_flush_quotas cnt=0
f2fs: block_ops retry_flush_dents dirty_dents=0
f2fs: block_ops check DIRTY_IMETA=1
... (repeats forever)

Add f2fs_cp_error() checks after each sync operation in block_operations()
to break out of retry loops when the filesystem is in error state.

Reported-by: syzbot+4235e4d7b6fd75704528@syzkaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
fs/f2fs/checkpoint.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index bbe07e3a6c75..a6f831ed3d9b 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1236,6 +1236,8 @@ static int block_operations(struct f2fs_sb_info *sbi)
f2fs_do_quota_sync(sbi->sb, -1);
up_read(&sbi->sb->s_umount);
}
+ if (unlikely(f2fs_cp_error(sbi)))
+ return -EIO;
cond_resched();
goto retry_flush_quotas;
}
@@ -1247,6 +1249,8 @@ static int block_operations(struct f2fs_sb_info *sbi)
err = f2fs_sync_dirty_inodes(sbi, DIR_INODE, true);
if (err)
return err;
+ if (unlikely(f2fs_cp_error(sbi)))
+ return -EIO;
cond_resched();
goto retry_flush_quotas;
}
@@ -1263,6 +1267,8 @@ static int block_operations(struct f2fs_sb_info *sbi)
err = f2fs_sync_inode_meta(sbi);
if (err)
return err;
+ if (unlikely(f2fs_cp_error(sbi)))
+ return -EIO;
cond_resched();
goto retry_flush_quotas;
}
@@ -1280,6 +1286,11 @@ static int block_operations(struct f2fs_sb_info *sbi)
f2fs_unlock_all(sbi);
return err;
}
+ if (unlikely(f2fs_cp_error(sbi))) {
+ f2fs_up_write(&sbi->node_change);
+ f2fs_unlock_all(sbi);
+ return -EIO;
+ }
cond_resched();
goto retry_flush_nodes;
}
--
2.43.0