From patchwork Sat Oct 8 07:37:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 118459 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 75CAAB6FAF for ; Sat, 8 Oct 2011 18:39:40 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751575Ab1JHHjj (ORCPT ); Sat, 8 Oct 2011 03:39:39 -0400 Received: from e35.co.us.ibm.com ([32.97.110.153]:53476 "EHLO e35.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750991Ab1JHHjj (ORCPT ); Sat, 8 Oct 2011 03:39:39 -0400 Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 8 Oct 2011 01:39:38 -0600 Received: from d03relay05.boulder.ibm.com ([9.17.195.107]) by e35.co.us.ibm.com ([192.168.1.135]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 8 Oct 2011 01:38:00 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p987c0W0094110 for ; Sat, 8 Oct 2011 01:38:00 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p987bwMP020700 for ; Sat, 8 Oct 2011 01:37:59 -0600 Received: from elm3c44.beaverton.ibm.com ([9.47.69.44]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p987bvfd020693; Sat, 8 Oct 2011 01:37:57 -0600 Subject: [PATCH 44/47] e2fsck: Check revoke block checksum during recovery To: Andreas Dilger , Theodore Tso , "Darrick J. Wong" From: "Darrick J. Wong" Cc: Sunil Mushran , Amir Goldstein , Andi Kleen , Mingming Cao , Joel Becker , linux-ext4@vger.kernel.org, Coly Li Date: Sat, 08 Oct 2011 00:37:57 -0700 Message-ID: <20111008073757.17888.62465.stgit@elm3c44.beaverton.ibm.com> In-Reply-To: <20111008073315.17888.22132.stgit@elm3c44.beaverton.ibm.com> References: <20111008073315.17888.22132.stgit@elm3c44.beaverton.ibm.com> User-Agent: StGit/0.15 MIME-Version: 1.0 x-cbid: 11100807-6148-0000-0000-000000139566 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Verify the revoke block checksum when recovering the journal. Signed-off-by: Darrick J. Wong --- e2fsck/recovery.c | 37 +++++++++++++++++++++++++++++++++++-- lib/ext2fs/kernel-jbd.h | 4 ++++ 2 files changed, 39 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c index b669941..8979193 100644 --- a/e2fsck/recovery.c +++ b/e2fsck/recovery.c @@ -674,8 +674,17 @@ static int do_one_pass(journal_t *journal, err = scan_revoke_records(journal, bh, next_commit_ID, info); brelse(bh); - if (err) - goto failed; + if (err) { + if (err != -EINVAL) + goto failed; + /* + * Ignoring corrupt revoke blocks is safe + * because at worst it results in unnecessary + * writes during recovery. + */ + jbd_debug(3, "Skipping corrupt revoke " + "block.\n"); + } continue; default: @@ -715,6 +724,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. */ @@ -729,6 +759,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; diff --git a/lib/ext2fs/kernel-jbd.h b/lib/ext2fs/kernel-jbd.h index 08479d3..187cb38 100644 --- a/lib/ext2fs/kernel-jbd.h +++ b/lib/ext2fs/kernel-jbd.h @@ -157,6 +157,10 @@ typedef struct journal_revoke_header_s int r_count; /* Count of bytes used in the block */ } journal_revoke_header_t; +/* Tail of revoke block, for checksumming */ +struct journal_revoke_tail { + __u32 r_checksum; +}; /* Definitions for the journal tag flags word: */ #define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */