Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp275031lqp; Fri, 12 Apr 2024 18:30:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSJq7FhkaAJANcgqAhiEFPvh6EAg1QJcdA4O3m+t6pqfI4UshJn8DVm0Hu2Ga2Z4Vf9xQSJ11u8fbv8FtP8XROhZa1nXNZw9X6KsVKSA== X-Google-Smtp-Source: AGHT+IHSe+/TU5KNyvXVWH0hcwmqk0u/Jo+gqTWiC6FlaEDlomBUo36DaTrxKQhCG2oDHIr9VDUf X-Received: by 2002:a05:620a:f05:b0:78b:ba77:5df9 with SMTP id v5-20020a05620a0f0500b0078bba775df9mr10986988qkl.22.1712971847541; Fri, 12 Apr 2024 18:30:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712971847; cv=pass; d=google.com; s=arc-20160816; b=BGt9rewyqN0olVrpTDvxx8eGWpkqsJ5OCcnMr6n2o8DKqW6HDx676QcKeo/45QNkRE 0639jBYu7PHBAQacxp5vkzlZzLbhzYKesFiinPRdZbcMvDN91rjEs380mVuhqCEWBKqo BY4iHGzHZp7h0YljBveAvc2fkVEhWovEc5gCgOCigmFig95o/t3bcYz8NC7RlC+WG5nq NXF78JvQ5FW+21M7d1sRFwhZ9I69vf65iuQCg6HrqJVLohYSFs28okfCghhMKLeLXoeJ 76cmkGMC7/c7E3YllZUBWf1pobcXb8hraryZrw99KJNUULm8tDXGUe6eIWNCdFjcvNBz EZQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=+j697DQ50xgmedJRB3EBMTVZ3hE9FxJ3QEfEI4MCt9U=; fh=0YRSAtnrSRvhtzUzSfhpD62rtNa0OOsDCBO4xMqK++A=; b=NEJaX9FEfAnOgcc+G8pkFaRWenbtfAawDu1EMbHFj9hbXTifwDAus3fRxOVlJaLttD TJ9a9LF9H5LjvxTQ2Y08BZjysZAejc7j9/kFuBWOzFkpDsL8ixGZF/Nrk5EfwlvbgQP7 1EzTSEZBy5/E7Spu+iI6Xc+zInbERE8w7DFcpz48wVEq/Y/q7obt3s0hpAbvgyCo64Mc ipNm7KODEIfv/P9IroHjAfXWq8Vzh+vyJ9vA52vxJgmQTAJKhal+cK1pbgC7Lhhulal2 GGf+JbKM9lrjYu+cyCcypXTAWGUw/ZixyScmdQQiRcw/Kp5pvPqowFSBZ8Pl5JzdWcLV EcJg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-143490-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143490-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c8-20020ae9e208000000b0078d642effa1si5113130qkc.466.2024.04.12.18.30.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 18:30:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143490-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-143490-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143490-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 444091C20E74 for ; Sat, 13 Apr 2024 01:30:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C96BC10A19; Sat, 13 Apr 2024 01:30:29 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6A034C97; Sat, 13 Apr 2024 01:30:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712971829; cv=none; b=kX24NzR4fn61zW9qFw3L/EvK3IIhi9Dtp4SLnYO3bttovQ8YaSnQyUezD/pS1kvwSmTMwy/PQvXQ3qA4f32/LuTpq2iqAgAl4ydfpsMWGX0MrY8+akaQjUCnpNZZ2KIHqN9ZyOjmbtt5dZWh5jjBTtiAPAh8RnKB6oxT8k9LKeI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712971829; c=relaxed/simple; bh=uAF58WQTwC70AQ4e42dMPhlqM+08OPyMWwp4j46ePBw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=f1va6SUpX6V+FNKDT/KzBJ5OT5krpVaGH4XjnpyOOjf+SSTlp+cv4J54AZv6s1SuzrWBt/IdGEpdHa21LB/Jv+Av6syAbHQ4GHhm9MdLufz+QkaA32NEqOzHr7zrnKG69Tsmlw1jYmCwhB+v0U5eZkgoyqzzKOxYoVTPR46TqEM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4VGbQK4bmKz1hwV8; Sat, 13 Apr 2024 09:27:21 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id A60D31A0172; Sat, 13 Apr 2024 09:30:15 +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_256_GCM_SHA384) id 15.1.2507.35; Sat, 13 Apr 2024 09:30:15 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH v2] jbd2: avoid mount failed when commit block is partial submitted Date: Sat, 13 Apr 2024 09:30:56 +0800 Message-ID: <20240413013056.1830515-1-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) We encountered a problem that the file system could not be mounted in the power-off scenario. The analysis of the file system mirror shows that only part of the data is written to the last commit block. The valid data of the commit block is concentrated in the first sector. However, the data of the entire block is involved in the checksum calculation. For different hardware, the minimum atomic unit may be different. If the checksum of a committed block is incorrect, clear the data except the 'commit_header' and then calculate the checksum. If the checkusm is correct, it is considered that the block is partially committed. However, if there are valid description/revoke blocks, it is considered that the data is abnormal and the log replay is stopped. Signed-off-by: Ye Bin --- fs/jbd2/recovery.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index 1f7664984d6e..eb0e026f3109 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c @@ -443,6 +443,27 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf) return provided == cpu_to_be32(calculated); } +static bool jbd2_commit_block_csum_partial_verify(journal_t *j, void *buf) +{ + struct commit_header *h; + __be32 provided; + __u32 calculated; + void *tmpbuf; + + tmpbuf = kzalloc(j->j_blocksize, GFP_KERNEL); + if (!tmpbuf) + return false; + + memcpy(tmpbuf, buf, sizeof(struct commit_header)); + h = tmpbuf; + provided = h->h_chksum[0]; + h->h_chksum[0] = 0; + calculated = jbd2_chksum(j, j->j_csum_seed, tmpbuf, j->j_blocksize); + kfree(tmpbuf); + + return provided == cpu_to_be32(calculated); +} + static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, journal_block_tag3_t *tag3, void *buf, __u32 sequence) @@ -479,6 +500,7 @@ static int do_one_pass(journal_t *journal, int descr_csum_size = 0; int block_error = 0; bool need_check_commit_time = false; + bool has_partial_commit = false; __u64 last_trans_commit_time = 0, commit_time; /* @@ -590,6 +612,14 @@ static int do_one_pass(journal_t *journal, next_log_block); } + if (pass == PASS_SCAN && has_partial_commit) { + pr_err("JBD2: Detect validate descriptor block %lu after incomplete commit block\n", + next_log_block); + err = -EFSBADCRC; + brelse(bh); + goto failed; + } + /* If it is a valid descriptor block, replay it * in pass REPLAY; if journal_checksums enabled, then * calculate checksums in PASS_SCAN, otherwise, @@ -810,6 +840,14 @@ static int do_one_pass(journal_t *journal, if (pass == PASS_SCAN && !jbd2_commit_block_csum_verify(journal, bh->b_data)) { + if (jbd2_commit_block_csum_partial_verify( + journal, + bh->b_data)) { + pr_notice("JBD2: Find incomplete commit block in transaction %u block %lu\n", + next_commit_ID, next_log_block); + has_partial_commit = true; + goto chksum_ok; + } chksum_error: if (commit_time < last_trans_commit_time) goto ignore_crc_mismatch; @@ -824,6 +862,7 @@ static int do_one_pass(journal_t *journal, } } if (pass == PASS_SCAN) { + chksum_ok: last_trans_commit_time = commit_time; head_block = next_log_block; } @@ -843,6 +882,15 @@ static int do_one_pass(journal_t *journal, next_log_block); need_check_commit_time = true; } + + if (pass == PASS_SCAN && has_partial_commit) { + pr_err("JBD2: Detect validate revoke block %lu after incomplete commit block\n", + next_log_block); + err = -EFSBADCRC; + brelse(bh); + goto failed; + } + /* If we aren't in the REVOKE pass, then we can * just skip over this block. */ if (pass != PASS_REVOKE) { -- 2.31.1