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, Cheng Yongkang <teel4res@gmail.com>
Subject: [PATCH 3/3] f2fs: refresh superblock CRC after MAIN_AREA alignment fix
Date: Sun, 25 Oct 2026 11:02:07 -0700 [thread overview]
Message-ID: <20261025180207.348498-4-teel4res@gmail.com> (raw)
In-Reply-To: <20261025180207.348498-1-teel4res@gmail.com>
sanity_check_area_boundary() fixes the on-disk segment_count through
__f2fs_commit_super(..., false), which does not refresh the superblock
checksum. segment_count is covered by the checksum, so the next mount
fails with -EFSCORRUPTED after the alignment fix.
Recompute the CRC over the modified superblock before writing it. Use the
raw superblock's feature bit: sanity_check_area_boundary() runs from
read_raw_super_block(), before sbi->raw_super is assigned.
The stale-CRC trigger was reproduced 3/3 times; with this fix both
superblock copies end with segment_count=9 and a matching CRC, and the
next mount no longer reports an invalid checksum.
Assisted-by: LLM
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
---
fs/f2fs/super.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index b90831e..7dcf15e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4023,6 +4023,13 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
raw_super->segment_count = cpu_to_le32((main_end_blkaddr -
segment0_blkaddr) >> log_blocks_per_seg);
+ if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) {
+ u32 crc;
+
+ crc = f2fs_crc32(raw_super, offsetof(struct f2fs_super_block, crc));
+ raw_super->crc = cpu_to_le32(crc);
+ }
+
if (f2fs_readonly(sb) || f2fs_hw_is_readonly(sbi)) {
set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
res = "internally";
--
2.34.1
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 [PATCH 0/3] f2fs: fix dentry recovery and MAIN_AREA validation Cheng Yongkang
2026-10-25 18:02 ` [PATCH 1/3] f2fs: reject non-directory parent inode during dentry recovery Cheng Yongkang
2026-10-25 18:02 ` [PATCH 2/3] f2fs: reject MAIN_AREA boundary underflow Cheng Yongkang
2026-10-25 18:02 ` Cheng Yongkang [this message]
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-4-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 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®