ext4: fix corrupt backup group descriptors after online resize
authorBaokun Li <libaokun1@huawei.com>
Thu, 17 Nov 2022 04:03:40 +0000 (12:03 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 9 Dec 2022 02:49:24 +0000 (21:49 -0500)
commit8f49ec603ae3e213bfab2799182724e3abac55a1
tree25a035a916ead488a24af4172ea573b5f07290f0
parenta408f33e895e455f16cf964cb5cd4979b658db7b
ext4: fix corrupt backup group descriptors after online resize

In commit 9a8c5b0d0615 ("ext4: update the backup superblock's at the end
of the online resize"), it is assumed that update_backups() only updates
backup superblocks, so each b_data is treated as a backupsuper block to
update its s_block_group_nr and s_checksum. However, update_backups()
also updates the backup group descriptors, which causes the backup group
descriptors to be corrupted.

The above commit fixes the problem of invalid checksum of the backup
superblock. The root cause of this problem is that the checksum of
ext4_update_super() is not set correctly. This problem has been fixed
in the previous patch ("ext4: fix bad checksum after online resize").

However, we do need to set block_group_nr for the backup superblock in
update_backups(). When a block is in a group that contains a backup
superblock, and the block is the first block in the group, the block is
definitely a superblock. We add a helper function that includes setting
s_block_group_nr and updating checksum, and then call it only when the
above conditions are met to prevent the backup group descriptors from
being incorrectly modified.

Fixes: 9a8c5b0d0615 ("ext4: update the backup superblock's at the end of the online resize")
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: stable@kernel.org
Link: https://lore.kernel.org/r/20221117040341.1380702-3-libaokun1@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/resize.c