From patchwork Wed Mar 7 00:03:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 145108 X-Patchwork-Delegate: tytso@mit.edu 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 D2614B6EF1 for ; Wed, 7 Mar 2012 11:03:39 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031614Ab2CGADi (ORCPT ); Tue, 6 Mar 2012 19:03:38 -0500 Received: from e33.co.us.ibm.com ([32.97.110.151]:36965 "EHLO e33.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031610Ab2CGADg (ORCPT ); Tue, 6 Mar 2012 19:03:36 -0500 Received: from /spool/local by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 6 Mar 2012 17:03:36 -0700 Received: from d01dlp03.pok.ibm.com (9.56.224.17) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 6 Mar 2012 17:03:35 -0700 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 73DACC9005C for ; Tue, 6 Mar 2012 19:03:33 -0500 (EST) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2703Owg257208 for ; Tue, 6 Mar 2012 19:03:28 -0500 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q275YE6I023811 for ; Wed, 7 Mar 2012 00:34:16 -0500 Received: from elm3b70.beaverton.ibm.com (elm3b70.beaverton.ibm.com [9.47.67.70]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q275YC7B023629; Wed, 7 Mar 2012 00:34:12 -0500 Subject: [PATCH 50/54] e2fsck: Verify data block checksums when recovering journal 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: Tue, 06 Mar 2012 16:03:17 -0800 Message-ID: <20120307000317.11945.16033.stgit@elm3b70.beaverton.ibm.com> In-Reply-To: <20120306235720.11945.30629.stgit@elm3b70.beaverton.ibm.com> References: <20120306235720.11945.30629.stgit@elm3b70.beaverton.ibm.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12030700-2398-0000-0000-000004D54353 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Check the data block checksums when recovering the journal. Signed-off-by: Darrick J. Wong --- e2fsck/jfs_user.h | 11 ----------- e2fsck/recovery.c | 32 ++++++++++++++++++++++++++++++++ lib/ext2fs/kernel-jbd.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 11 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/jfs_user.h b/e2fsck/jfs_user.h index 9e33306..4baba54 100644 --- a/e2fsck/jfs_user.h +++ b/e2fsck/jfs_user.h @@ -104,17 +104,6 @@ _INLINE_ void do_cache_destroy(lkmem_cache_t *cache) free(cache); } -/* - * helper functions to deal with 32 or 64bit block numbers. - */ -_INLINE_ size_t journal_tag_bytes(journal_t *journal) -{ - if (JFS_HAS_INCOMPAT_FEATURE(journal, JFS_FEATURE_INCOMPAT_64BIT)) - return JBD_TAG_SIZE64; - else - return JBD_TAG_SIZE32; -} - #undef _INLINE_ #endif diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c index 8f55411..d7c470e 100644 --- a/e2fsck/recovery.c +++ b/e2fsck/recovery.c @@ -395,6 +395,25 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf) return provided == calculated; } +static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, + void *buf, __u32 sequence) +{ + __u32 provided, calculated; + + if (!JFS_HAS_INCOMPAT_FEATURE(j, JFS_FEATURE_INCOMPAT_CSUM_V2)) + return 1; + + sequence = ext2fs_cpu_to_be32(sequence); + calculated = ext2fs_crc32c_le(~0, j->j_superblock->s_uuid, + sizeof(j->j_superblock->s_uuid)); + calculated = ext2fs_crc32c_le(calculated, (__u8 *)&sequence, + sizeof(sequence)); + calculated = ext2fs_crc32c_le(calculated, buf, j->j_blocksize); + provided = ext2fs_be32_to_cpu(tag->t_checksum); + + return provided == ext2fs_cpu_to_be32(calculated); +} + static int do_one_pass(journal_t *journal, struct recovery_info *info, enum passtype pass) { @@ -575,6 +594,19 @@ static int do_one_pass(journal_t *journal, goto skip_write; } + /* Look for block corruption */ + if (!jbd2_block_tag_csum_verify( + journal, tag, obh->b_data, + be32_to_cpu(tmp->h_sequence))) { + brelse(obh); + success = -EIO; + printk(KERN_ERR "JBD: Invalid " + "checksum recovering " + "block %ld in log\n", + blocknr); + continue; + } + /* Find a buffer for the new * data being restored */ nbh = __getblk(journal->j_fs_dev, diff --git a/lib/ext2fs/kernel-jbd.h b/lib/ext2fs/kernel-jbd.h index 570bfa6..e9d725d 100644 --- a/lib/ext2fs/kernel-jbd.h +++ b/lib/ext2fs/kernel-jbd.h @@ -261,6 +261,36 @@ typedef struct journal_superblock_s JFS_FEATURE_INCOMPAT_ASYNC_COMMIT|\ JFS_FEATURE_INCOMPAT_64BIT) +#if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) +#ifdef E2FSCK_INCLUDE_INLINE_FUNCS +#define _INLINE_ extern +#else +#ifdef __GNUC__ +#define _INLINE_ extern __inline__ +#else /* For Watcom C */ +#define _INLINE_ extern inline +#endif +#endif + +/* + * helper functions to deal with 32 or 64bit block numbers. + */ +_INLINE_ size_t journal_tag_bytes(journal_t *journal) +{ + journal_block_tag_t tag; + size_t x = 0; + + if (JFS_HAS_INCOMPAT_FEATURE(journal, JFS_FEATURE_INCOMPAT_CSUM_V2)) + x += sizeof(tag.t_checksum); + + if (JFS_HAS_INCOMPAT_FEATURE(journal, JFS_FEATURE_INCOMPAT_64BIT)) + return x + JBD_TAG_SIZE64; + else + return x + JBD_TAG_SIZE32; +} +#undef _INLINE_ +#endif + #ifdef __KERNEL__ #include