From: Cheng Yongkang <teel4res@gmail.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
Cc: Cheng Yongkang <teel4res@gmail.com>,
linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 2/3] f2fs: reject MAIN_AREA boundary underflow
Date: Sun, 25 Oct 2026 11:02:06 -0700 [thread overview]
Message-ID: <20261025180207.348498-3-teel4res@gmail.com> (raw)
In-Reply-To: <20261025180207.348498-1-teel4res@gmail.com>
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
reproduced 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.
The underflow was reproduced 3/3 times; the patched kernel rejects
it with "Wrong MAIN_AREA boundary", leaves segment_count unchanged,
and does not trigger the KASAN report.
Fixes: fd694733d523 ("f2fs: cover large section in sanity check of super")
Assisted-by: LLM
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
---
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
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2026-10-25 18:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 18:02 [f2fs-dev] [PATCH 0/3] f2fs: fix dentry recovery and MAIN_AREA validation Cheng Yongkang
2026-10-25 18:02 ` [f2fs-dev] [PATCH 1/3] f2fs: reject non-directory parent inode during dentry recovery Cheng Yongkang
2026-10-25 18:02 ` Cheng Yongkang [this message]
2026-10-25 18:02 ` [f2fs-dev] [PATCH 3/3] f2fs: refresh superblock CRC after MAIN_AREA alignment fix Cheng Yongkang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261025180207.348498-3-teel4res@gmail.com \
--to=teel4res@gmail.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.