Re: ext4 online resize -> EXT4-fs error (device loop0) in ext4_update_backup_sb:174: Filesystem failed CRC

From: Quentin Schulz
Date: Thu Nov 03 2022 - 07:54:35 EST


Hi Theodore,

On 10/28/22 05:59, Theodore Ts'o wrote:
On Wed, Oct 26, 2022 at 07:49:56PM +0000, Unterwurzacher, Jakob wrote:

it looks like I am hitting a similar issue as reported by Borislav Petkov
in April 2022 ( https://urldefense.com/v3/__https://lore.kernel.org/lkml/YmqOqGKajOOx90ZY@xxxxxxx/__;!!OOPJP91ZZw!kg_tsVkw00-Mf-bC3nyz9aOxZvEowuWZ19B4d-Vzx22Kd8RwNeAb7lEReLYF4ulwcE_OE0im6sdv3zVWHiLXp8Tafu1i$ ).

I'm on kernel 6.0.5 and see this on arm64 as well as x86_64.
I have a 100% reproducer using a loop mount, here it is:

truncate -s 16g ext4.img
mkfs.ext4 ext4.img 500m
mkdir ext4.mnt
mount ext4.img ext4.mnt
resize2fs ext4.img

Thanks for the reproducer! The following patch should fix things.

- Ted

From 9a8c5b0d061554fedd7dbe894e63aa34d0bac7c4 Mon Sep 17 00:00:00 2001
From: Theodore Ts'o <tytso@xxxxxxx>
Date: Thu, 27 Oct 2022 16:04:36 -0400
Subject: [PATCH] ext4: update the backup superblock's at the end of the online
resize

When expanding a file system using online resize, various fields in
the superblock (e.g., s_blocks_count, s_inodes_count, etc.) change.
To update the backup superblocks, the online resize uses the function
update_backups() in fs/ext4/resize.c. This function was not updating
the checksum field in the backup superblocks. This wasn't a big deal
previously, because e2fsck didn't care about the checksum field in the
backup superblock. (And indeed, update_backups() goes all the way
back to the ext3 days, well before we had support for metadata
checksums.)

However, there is an alternate, more general way of updating
superblock fields, ext4_update_primary_sb() in fs/ext4/ioctl.c. This
function does check the checksum of the backup superblock, and if it
doesn't match will mark the file system as corrupted. That was
clearly not the intent, so avoid to aborting the resize when a bad
superblock is found.

In addition, teach update_backups() to properly update the checksum in
the backup superblocks. We will eventually want to unify
updapte_backups() with the infrasture in ext4_update_primary_sb(), but
that's for another day.

Note: The problem has been around for a while; it just didn't really
matter until ext4_update_primary_sb() was added by commit bbc605cdb1e1
("ext4: implement support for get/set fs label"). And it became
trivially easy to reproduce after commit 827891a38acc ("ext4: update
the s_overhead_clusters in the backup sb's when resizing") in v6.0.

Cc: stable@xxxxxxxxxx # 5.17+
Fixes: bbc605cdb1e1 ("ext4: implement support for get/set fs label")
Signed-off-by: Theodore Ts'o <tytso@xxxxxxx>

I don't see a formal patch on the linux-ext4 mailing list yet though your previous mail was sent to the ML. Is there any plan to send a formal patch or is your mail enough? I also don't see it on https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git yet.

Basically asking because we enforce that backporting is only allowed for patches that are sent to mailing lists so it's easier to follow progress were there any update to the patch warranted by reviews/feedback after we backported the patch. (In short, anything that can be fetched with b4 shazam can be backported).

Let us know if there's anything we can do to help.

Thanks,
Quentin