Skip to contentSkip to conversation

ext4: validate external journal superblock checksum

PATCH New Darrick J. Wong 1 participant 1 message Sep 8, 2014 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: validate external journal superblock checksum

If the external journal device has metadata_csum enabled, verify that the superblock checksum matches the block before we try to mount.

---
 fs/ext4/super.c |    9 +++++++++
 1 file changed, 9 insertions(+)
fs/ext4/super.c +9 -0
index 7045f1d..222ed5d 100644
@@ -4372,6 +4372,15 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
 		goto out_bdev;
 	}
 
+	if ((le32_to_cpu(es->s_feature_ro_compat) &
+	     EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
+	    es->s_checksum != ext4_superblock_csum(sb, es)) {
+		ext4_msg(sb, KERN_ERR, "external journal has "
+				       "corrupt superblock");
+		brelse(bh);
+		goto out_bdev;
+	}
+
 	if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
 		ext4_msg(sb, KERN_ERR, "journal UUID does not match");
 		brelse(bh);