Skip to content

Commit 813d32f

Browse files
djwongtytso
authored andcommitted
ext4: check s_chksum_driver when looking for bg csum presence
Convert the ext4_has_group_desc_csum predicate to look for a checksum driver instead of the metadata_csum flag and change the bg checksum calculation function to look for GDT_CSUM before taking the crc16 path. Without this patch, if we mount with ^uninit_bg,^metadata_csum and later metadata_csum gets turned on by accident, the block group checksum functions will incorrectly assume that checksumming is enabled (metadata_csum) but that crc16 should be used (!s_chksum_driver). This is totally wrong, so fix the predicate and the checksum formula selection. (Granted, if the metadata_csum feature bit gets enabled on a live FS then something underhanded is going on, but we could at least avoid writing garbage into the on-disk fields.) Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Dmitry Monakhov <dmonakhov@openvz.org> Cc: stable@vger.kernel.org
1 parent aef4885 commit 813d32f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

fs/ext4/ext4.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,8 +2333,8 @@ extern int ext4_register_li_request(struct super_block *sb,
23332333
static inline int ext4_has_group_desc_csum(struct super_block *sb)
23342334
{
23352335
return EXT4_HAS_RO_COMPAT_FEATURE(sb,
2336-
EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
2337-
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
2336+
EXT4_FEATURE_RO_COMPAT_GDT_CSUM) ||
2337+
(EXT4_SB(sb)->s_chksum_driver != NULL);
23382338
}
23392339

23402340
static inline int ext4_has_metadata_csum(struct super_block *sb)

fs/ext4/super.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,6 +2005,10 @@ static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
20052005
}
20062006

20072007
/* old crc16 code */
2008+
if (!(sbi->s_es->s_feature_ro_compat &
2009+
cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)))
2010+
return 0;
2011+
20082012
offset = offsetof(struct ext4_group_desc, bg_checksum);
20092013

20102014
crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));

0 commit comments

Comments
 (0)