From: Cheng Yongkang <teel4res@gmail.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v3 2/3] f2fs: reject MAIN_AREA boundary underflow
Date: Mon, 26 Oct 2026 03:50:40 -0700 [thread overview]
Message-ID: <20261026105042.1148554-3-teel4res@gmail.com> (raw)
In-Reply-To: <20261026105042.1148554-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
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@vger.kernel.org
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
next prev parent reply other threads:[~2026-10-26 10:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 10:50 [PATCH v3 0/3] f2fs: fix dentry recovery and MAIN_AREA validation Cheng Yongkang
2026-10-26 10:50 ` [PATCH v3 1/3] f2fs: reject non-directory parent inode during dentry recovery Cheng Yongkang
2026-10-26 10:50 ` Cheng Yongkang [this message]
2026-10-26 10:50 ` [PATCH v3 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=20261026105042.1148554-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 \
--cc=stable@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®