[PATCH v3 2/3] f2fs: reject MAIN_AREA boundary underflow

From: Cheng Yongkang

Date: Mon Oct 26 2026 - 06:51:58 EST


sanity_check_area_boundary() computes

main_end_blkaddr - segment0_blkaddr

as u64 when main_end_blkaddr < seg_end_blkaddr. A crafted superblock
can make main_end_blkaddr smaller than segment0_blkaddr, so the
subtraction underflows and cpu_to_le32() truncates the result; the
function persists a wrapped segment_count (0xfffffffd in the
crafted image) and the next mount rejects the filesystem. The
same path can also leave the error workqueue dereferencing freed
superblock state:

BUG: KASAN: slab-use-after-free in f2fs_commit_super

Reject the underflowing geometry before the subtraction.

Fixes: fd694733d523 ("f2fs: cover large section in sanity check of super")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: LLM
Signed-off-by: Cheng Yongkang <teel4res@xxxxxxxxx>
---
fs/f2fs/super.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index ea2d218..b90831e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4004,6 +4004,12 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
return true;
}

+ if (main_end_blkaddr < segment0_blkaddr) {
+ f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu)",
+ main_blkaddr, main_end_blkaddr);
+ return true;
+ }
+
if (main_end_blkaddr > seg_end_blkaddr) {
f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)",
main_blkaddr, seg_end_blkaddr,
--
2.34.1