From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758623Ab3KMHAd (ORCPT ); Wed, 13 Nov 2013 02:00:33 -0500 Received: from caiajhbdcahe.dreamhost.com ([208.97.132.74]:53609 "EHLO homiemail-a20.g.dreamhost.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758324Ab3KMHAX (ORCPT ); Wed, 13 Nov 2013 02:00:23 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; d=novalis.org; h=message-id:subject :from:to:cc:date:in-reply-to:references:content-type :mime-version:content-transfer-encoding; q=dns; s=novalis.org; b=k4TMGXmNupDhxLuo1nNbdx5WUl4oOiFUozewOGkNUYAhoeGrhnP7NOaeNKePo VZwxtXcWD7kjyaXhZivkDL2lc5v8uB2iURygohRWt7NHknuiQw/ObQdL1OCjcvcV ZlZ9bRToX2VOZTBWNL4s2WgXPzF2binsMKtJ5Y93bEF238= Message-ID: <1384326020.8994.186.camel@chiang> Subject: [PATCH v4 2/2] e2fsck: Correct ext4 dates generated by old kernels. From: David Turner To: Andreas Dilger Cc: "Theodore Ts'o" , Mark Harris , Jan Kara , Ext4 Developers List , Linux Kernel Mailing List Date: Wed, 13 Nov 2013 02:00:20 -0500 In-Reply-To: <6DE0AF86-98E6-4DE9-BB7F-40FB32E1BC26@dilger.ca> References: <1383808590.23882.13.camel@chiang> <20131107160341.GA3850@quack.suse.cz> <1383864864.23882.33.camel@chiang> <20131107231445.GG2054@quack.suse.cz> <1383866807.23882.41.camel@chiang> <1383981551.8994.27.camel@chiang> <1384070214.8994.47.camel@chiang> <20131112003018.GA30281@thunk.org> <6DE0AF86-98E6-4DE9-BB7F-40FB32E1BC26@dilger.ca> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.6.4-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch is against e2fsprogs. --- Older kernels on 64-bit machines would incorrectly encode pre-1970 ext4 dates as post-2311 dates. Detect and correct this (assuming the current date is before 2311). Signed-off-by: David Turner --- e2fsck/pass1.c | 37 +++++++++++++++++++++++++++++++++++++ e2fsck/problem.c | 7 +++++++ e2fsck/problem.h | 6 ++++++ 3 files changed, 50 insertions(+) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index ab23e42..cb72964 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -348,6 +348,23 @@ fix: EXT2_INODE_SIZE(sb), "pass1"); } +#define EXT4_EPOCH_BITS 2 +#define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1) + +static int large_inode_extra(__u32 xtime, __u32 extra) { + return (xtime & (1 << 31)) != 0 && + (extra & EXT4_EPOCH_MASK) == EXT4_EPOCH_MASK; +} + +#define LARGE_INODE_EXTRA(inode, xtime) \ + large_inode_extra(inode->i_##xtime, \ + inode->i_##xtime##_extra) + +/* When the date is earlier than 2311, we assume that atimes, ctimes, + * and mtimes greater than 2311 are actually pre-1970 dates mis-encoded. + */ +#define EXT4_EXTRA_NEGATIVE_DATE_CUTOFF 6 * (1UL << 32) + static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx) { struct ext2_super_block *sb = ctx->fs->super; @@ -388,6 +405,26 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx) /* it seems inode has an extended attribute(s) in body */ check_ea_in_inode(ctx, pctx); } + + /* + * If the inode's extended atime (ctime, mtime) is stored in + * the old, invalid format, the inode is corrupt. + */ + if (sizeof(time_t) > 4 && ctx->now < EXT4_EXTRA_NEGATIVE_DATE_CUTOFF && + LARGE_INODE_EXTRA(inode, atime) || + LARGE_INODE_EXTRA(inode, ctime) || + LARGE_INODE_EXTRA(inode, mtime)) { + + if (!fix_problem(ctx, PR_1_EA_TIME_OUT_OF_RANGE, pctx)) + return; + + inode->i_atime_extra &= ~EXT4_EPOCH_MASK; + inode->i_ctime_extra &= ~EXT4_EPOCH_MASK; + inode->i_mtime_extra &= ~EXT4_EPOCH_MASK; + e2fsck_write_inode_full(ctx, pctx->ino, pctx->inode, + EXT2_INODE_SIZE(sb), "pass1"); + } + } /* diff --git a/e2fsck/problem.c b/e2fsck/problem.c index 897693a..51fa7c3 100644 --- a/e2fsck/problem.c +++ b/e2fsck/problem.c @@ -1018,6 +1018,13 @@ static struct e2fsck_problem problem_table[] = { N_("@i %i, end of extent exceeds allowed value\n\t(logical @b %c, physical @b %b, len %N)\n"), PROMPT_CLEAR, 0 }, +/* The extended a, c, or mtime on this inode is in the far future, + indicating that it was written with an older, buggy version of the + kernel on a 64-bit machine */ + { PR_1_EA_TIME_OUT_OF_RANGE, + N_("Extended time on @i %i is in the far future.\n" + "Assume that it is in fact a pre-1970 date written by an older, buggy version of Linux?\n"), + PROMPT_FIX, 0 }, /* Pass 1b errors */ diff --git a/e2fsck/problem.h b/e2fsck/problem.h index ae1ed26..a44f6dd 100644 --- a/e2fsck/problem.h +++ b/e2fsck/problem.h @@ -593,6 +593,12 @@ struct problem_context { #define PR_1_EXTENT_INDEX_START_INVALID 0x01006D #define PR_1_EXTENT_END_OUT_OF_BOUNDS 0x01006E + +/* The extended a, c, or mtime on this inode is in the far future, + indicating that it was written with an older, buggy version of + the kernel on a 64-bit machine */ +#define PR_1_EA_TIME_OUT_OF_RANGE 0x01006F + /* * Pass 1b errors */ -- 1.8.1.2