From d35ed158cf616c23512ce8e393ab00ed2f004b84 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Thu, 2 Aug 2012 20:47:45 -0400 Subject: [PATCH] e2fsck: check revoke block checksum during recovery Verify the revoke block checksum when recovering the journal. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- e2fsck/recovery.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c index a9fc3f7..8bf4401 100644 --- a/e2fsck/recovery.c +++ b/e2fsck/recovery.c @@ -714,6 +714,27 @@ static int do_one_pass(journal_t *journal, return err; } +static int jbd2_revoke_block_csum_verify(journal_t *j, + void *buf) +{ + struct journal_revoke_tail *tail; + __u32 provided, calculated; + + if (!JFS_HAS_INCOMPAT_FEATURE(j, JFS_FEATURE_INCOMPAT_CSUM_V2)) + return 1; + + tail = (struct journal_revoke_tail *)(buf + j->j_blocksize - + sizeof(struct journal_revoke_tail)); + provided = tail->r_checksum; + tail->r_checksum = 0; + calculated = ext2fs_crc32c_le(~0, j->j_superblock->s_uuid, + sizeof(j->j_superblock->s_uuid)); + calculated = ext2fs_crc32c_le(calculated, buf, j->j_blocksize); + tail->r_checksum = provided; + + provided = ext2fs_be32_to_cpu(provided); + return provided == calculated; +} /* Scan a revoke record, marking all blocks mentioned as revoked. */ @@ -728,6 +749,9 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh, offset = sizeof(journal_revoke_header_t); max = be32_to_cpu(header->r_count); + if (!jbd2_revoke_block_csum_verify(journal, header)) + return -EINVAL; + if (JFS_HAS_INCOMPAT_FEATURE(journal, JFS_FEATURE_INCOMPAT_64BIT)) record_len = 8; -- 1.8.3.1