From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 904B9C19F2D for ; Wed, 10 Aug 2022 01:22:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229709AbiHJBW7 (ORCPT ); Tue, 9 Aug 2022 21:22:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbiHJBW6 (ORCPT ); Tue, 9 Aug 2022 21:22:58 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33BB55C95F; Tue, 9 Aug 2022 18:22:57 -0700 (PDT) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M2XBx4V4JzXdQw; Wed, 10 Aug 2022 09:18:49 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 10 Aug 2022 09:22:54 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH RFC] jbd2: detect old record when do journal scan Date: Wed, 10 Aug 2022 09:34:42 +0800 Message-ID: <20220810013442.3474533-1-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org As https://github.com/tytso/e2fsprogs/issues/120 describe tune2fs do not update j_tail_sequence when do journal recovery. This maybe recover old journal record, then will lead to file system corruption. To avoid file system corruption in this case, if detect current transaction's commit time earlier than previous transaction's commit time when do journal scan, just return error. Signed-off-by: Ye Bin --- fs/jbd2/recovery.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index f548479615c6..f3def21a96a5 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c @@ -812,8 +812,17 @@ static int do_one_pass(journal_t *journal, break; } } - if (pass == PASS_SCAN) + if (pass == PASS_SCAN) { + if (commit_time < last_trans_commit_time) { + pr_err("JBD2: old journal record found " + "in transaction %u\n", + next_commit_ID); + err = -EFSBADCRC; + brelse(bh); + goto failed; + } last_trans_commit_time = commit_time; + } brelse(bh); next_commit_ID++; continue; -- 2.31.1