[PATCH] f2fs: reject a user area smaller than one segment
From: Kyuwon Cho
Date: Thu Dec 03 2026 - 11:49:46 EST
Checkpoint validation accepts any nonzero user_block_count. The debugfs
status code converts this count to whole segments and uses the result as a
divisor, so a crafted checkpoint with fewer than one segment causes a
divide by zero.
Require the user area to contain at least one complete segment before the
checkpoint is accepted.
Fixes: 9dc956b2c852 ("f2fs: fix to do sanity check with user_block_count")
Signed-off-by: Kyuwon Cho <kyuwon.cho@xxxxxxxx>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype.
The reproducer mounts a crafted F2FS image whose checkpoint declares a
nonzero user area smaller than one segment, then reads the filesystem's
debugfs status file. Mounting the image and accessing debugfs require root
in the initial namespace.
The decoded trace is:
Oops: divide error
stat_show (fs/f2fs/debug.c:243 fs/f2fs/debug.c:457)
seq_read_iter (fs/seq_file.c:231)
seq_read (fs/seq_file.c:163)
full_proxy_read (fs/debugfs/file.c:379)
vfs_read (fs/read_write.c:552)
With this patch, the reproducer completes without a divide error on
fe6ff8d5d675. The patch also builds on the current F2FS tree at
b61a029304bb.
fs/f2fs/super.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 2f9ef2abfba8..86916ac45b1b 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4353,7 +4353,8 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
segment_count_main = le32_to_cpu(raw_super->segment_count_main) +
(f2fs_sb_has_readonly(sbi) ? 1 : 0);
log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
- if (!user_block_count || user_block_count >=
+ if (user_block_count < BIT_ULL(log_blocks_per_seg) ||
+ user_block_count >=
segment_count_main << log_blocks_per_seg) {
f2fs_err(sbi, "Wrong user_block_count: %u",
user_block_count);