From: "Theodore Ts'o" <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Subject: [PATCH 02/23] ext4: return -EFSBADCRC when skipping a corrupt backup superblock
Date: Wed, 11 Nov 2026 23:46:51 -0500 [thread overview]
Message-ID: <20261112044712.1577296-3-tytso@mit.edu> (raw)
In-Reply-To: <20261112044712.1577296-1-tytso@mit.edu>
Commit 9a8c5b0d0615 ("ext4: update the backup superblock's at the end
of the online resize") stopped setting err = -EFSBADCRC when
ext4_update_backup_sb() finds a backup superblock with an invalid
checksum, so that ext4_std_error() would not mark the file system as
corrupted. However, it left err at 0, so the function now returns 1,
claiming that the backup superblock was successfully updated.
This makes the "Ignore bad checksum; try to update next sb" check in
ext4_update_superblocks_fn() dead code, and the skipped backup is
counted towards the two backup superblocks which are supposed to be
updated through the journal. If one of the first backups is corrupt,
fewer than two backup superblocks get journalled updates.
Release the buffer and return -EFSBADCRC directly, bypassing
ext4_std_error(), so the caller skips the corrupt backup without
counting it and without aborting the update.
Fixes: 9a8c5b0d0615 ("ext4: update the backup superblock's at the end of the online resize")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
fs/ext4/ioctl-test.c | 47 ++++++++++++++++++++++++++++++++++++++++++++
fs/ext4/ioctl.c | 10 ++++++++--
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ioctl-test.c b/fs/ext4/ioctl-test.c
index ebe4a87f17e1..c3eee774bcfa 100644
--- a/fs/ext4/ioctl-test.c
+++ b/fs/ext4/ioctl-test.c
@@ -817,6 +817,52 @@ static void test_update_superblocks_and_overhead(struct kunit *test)
KUNIT_EXPECT_EQ(test, ctx->sync_bh_calls, 5);
}
+/*
+ * Verify that a backup superblock with an invalid checksum is reported as
+ * -EFSBADCRC (and left untouched) rather than counted as updated, and that
+ * ext4_update_superblocks_fn still updates the remaining backups.
+ */
+static void test_update_backup_sb_bad_csum(struct kunit *test)
+{
+ struct ioctl_test_ctx *ctx = test->priv;
+ struct super_block *sb = ctx->sb;
+ static const ext4_group_t good_grps[] = { 1, 5, 7 };
+ char new_label[EXT4_LABEL_MAX] = "csum_label";
+ struct ext4_super_block *bad;
+ int i;
+
+ bad = (struct ext4_super_block *)ctx->backup_sb_bufs[3];
+ bad->s_checksum = cpu_to_le32(~le32_to_cpu(bad->s_checksum));
+
+ ctx->sync_bh_calls = 0;
+ KUNIT_EXPECT_EQ(test,
+ ext4_update_backup_sb_test(sb, NULL, 3,
+ ext4_sb_setlabel_test,
+ new_label),
+ -EFSBADCRC);
+ KUNIT_EXPECT_EQ(test, ctx->sync_bh_calls, 0);
+ KUNIT_EXPECT_MEMNEQ(test, bad->s_volume_name, new_label,
+ EXT4_LABEL_MAX);
+
+ /* Primary + backups 1, 5 and 7 are updated; backup 3 is skipped */
+ KUNIT_EXPECT_EQ(test,
+ ext4_update_superblocks_fn_test(sb,
+ ext4_sb_setlabel_test,
+ new_label),
+ 0);
+ KUNIT_EXPECT_EQ(test, ctx->sync_bh_calls, 4);
+ KUNIT_EXPECT_MEMNEQ(test, bad->s_volume_name, new_label,
+ EXT4_LABEL_MAX);
+ for (i = 0; i < ARRAY_SIZE(good_grps); i++) {
+ struct ext4_super_block *bes;
+
+ bes = (struct ext4_super_block *)
+ ctx->backup_sb_bufs[good_grps[i]];
+ KUNIT_EXPECT_MEMEQ(test, bes->s_volume_name, new_label,
+ EXT4_LABEL_MAX);
+ }
+}
+
/*
* Verify swap_inode_data swaps i_data, i_disksize, i_size, i_version,
* atime/mtime, and EXT4_FL_SHOULD_SWAP flags while preserving non-swapped
@@ -1191,6 +1237,7 @@ static struct kunit_case ioctl_test_cases[] = {
KUNIT_CASE(test_validate_tune_sb_params),
KUNIT_CASE(test_tune_sb_mount_opts_guard),
KUNIT_CASE(test_update_superblocks_and_overhead),
+ KUNIT_CASE(test_update_backup_sb_bad_csum),
KUNIT_CASE(test_swap_inode_data_and_seed),
KUNIT_CASE(test_immutable_dax_and_fileattr),
KUNIT_CASE(test_force_shutdown_and_ioctl_dispatch),
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 286f4a3e459a..37ad549ad693 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -110,7 +110,8 @@ int ext4_update_primary_sb(struct super_block *sb, handle_t *handle,
*
* Returns: 0 when no modification was done (no superblock in the group)
* 1 when the modification was successful
- * <0 on error
+ * <0 on error (-EFSBADCRC if the backup superblock has an invalid
+ * checksum and was skipped)
*/
static int ext4_update_backup_sb(struct super_block *sb,
handle_t *handle, ext4_group_t grp,
@@ -159,7 +160,12 @@ static int ext4_update_backup_sb(struct super_block *sb,
ext4_msg(sb, KERN_ERR, "Invalid checksum for backup "
"superblock %llu", sb_block);
unlock_buffer(bh);
- goto out_bh;
+ /*
+ * Let the caller skip this backup; don't report it via
+ * ext4_std_error() since it must not abort the update.
+ */
+ brelse(bh);
+ return -EFSBADCRC;
}
func(EXT4_SB(sb), es, arg);
if (ext4_has_feature_metadata_csum(sb))
--
2.56.0.542.g3ef89b7020-goog
next prev parent reply other threads:[~2026-11-12 4:47 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 4:46 [PATCH 00/23] ext4: lots of misc bug fixes Theodore Ts'o
2026-11-12 4:46 ` [PATCH 01/23] ext4: only update s_mount_opts when EXT4_TUNE_FL_MOUNT_OPTS is set Theodore Ts'o
2026-11-12 4:46 ` Theodore Ts'o [this message]
2026-11-12 4:46 ` [PATCH 03/23] ext4: don't allow enabling casefold via EXT4_IOC_SET_TUNE_SB_PARAM Theodore Ts'o
2026-11-12 4:46 ` [PATCH 04/23] ext4: persist the htree hash seed when enabling dir_index online Theodore Ts'o
2026-11-12 4:46 ` [PATCH 05/23] ext4: enforce feature prerequisites when tuning a mounted fs Theodore Ts'o
2026-11-12 4:46 ` [PATCH 06/23] ext4: handle s_lastcheck_hi in the get/set tune superblock ioctls Theodore Ts'o
2026-11-12 4:46 ` [PATCH 07/23] ext4: pass missing ioctls through ext4_compat_ioctl Theodore Ts'o
2026-11-12 4:46 ` [PATCH 08/23] ext4: fix inverted err_report_sec check in ext4_update_super() Theodore Ts'o
2026-11-12 4:46 ` [PATCH 09/23] ext4: fix err_report_sec_store() timer and value handling Theodore Ts'o
2026-11-12 4:46 ` [PATCH 10/23] ext4: fix inode table accounting in count_overhead() Theodore Ts'o
2026-11-12 4:47 ` [PATCH 11/23] ext4: handle flex groups straddling s_first_meta_bg in online resize Theodore Ts'o
2026-11-12 4:47 ` [PATCH 12/23] ext4: reject EXT4_IOC_GROUP_ADD inputs larger than a block group Theodore Ts'o
2026-11-12 4:47 ` [PATCH 13/23] ext4: propagate ext4_alloc_group_tables() errors from ext4_resize_fs() Theodore Ts'o
2026-11-12 4:47 ` [PATCH 14/23] ext4: reject online shrink before probing the device size Theodore Ts'o
2026-11-12 4:47 ` [PATCH 15/23] ext4: cap migrated extents at EXT_INIT_MAX_LEN Theodore Ts'o
2026-11-12 4:47 ` [PATCH 16/23] ext4: don't treat a handle restart as an error in finish_range() Theodore Ts'o
2026-11-12 4:47 ` [PATCH 17/23] ext4: don't clobber the migration result in ext4_ext_migrate() Theodore Ts'o
2026-11-12 4:47 ` [PATCH 18/23] ext4: fix EOF clamping of the range in mext_check_adjust_range() Theodore Ts'o
2026-11-12 4:47 ` [PATCH 19/23] ext4: bound the MMP update and check intervals Theodore Ts'o
2026-11-12 4:47 ` [PATCH 20/23] ext4: fix MMP claim of a cleanly unmounted filesystem Theodore Ts'o
2026-11-12 4:47 ` [PATCH 21/23] ext4: fix device comparison overflow in ext4_getfsmap_dev_compare() Theodore Ts'o
2026-11-12 4:47 ` [PATCH 22/23] ext4: don't allocate over indirect branches that failed to load Theodore Ts'o
2026-11-12 4:47 ` [PATCH 23/23] ext4: don't stop EXT4_IOC_GET_ES_CACHE at uncached ranges Theodore Ts'o
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=20261112044712.1577296-3-tytso@mit.edu \
--to=tytso@mit.edu \
--cc=linux-ext4@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