[PATCH v3 3/3] f2fs: refresh superblock CRC after MAIN_AREA alignment fix
From: Cheng Yongkang
Date: Mon Oct 26 2026 - 06:51:48 EST
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.
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 | 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