Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp611024pxb; Tue, 5 Apr 2022 15:55:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVNtJ+WtUFcQgm25wrfnqVdnsH6meBPkAJ9mWrYtzvAWxsahtGTmxGWO7AbCQNel2e8KHz X-Received: by 2002:a92:c26e:0:b0:2c9:e7f7:5eb0 with SMTP id h14-20020a92c26e000000b002c9e7f75eb0mr2851259ild.143.1649199304480; Tue, 05 Apr 2022 15:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649199304; cv=none; d=google.com; s=arc-20160816; b=NfDTSRjN1Mlc7rknOJwRKsZwqA6cj+FIiAUaZyoO4YpTUGA8hMpQlfbO+QJ7fmdXH3 3wppMS1CJ8XA9c5NiJGalglGF/zhSdPaWrLdbRbHpM2IBUJTv8xrBiDocPqk7DiMBR0/ JryWoBAVe7e0OaC1PepnmQu1QIYPt8qYvbtmljcg0FvvXWYiFcb4RmoGUA458MEykwBA l1oMW3yqDp684QgzK+eO6NiiivshNRPPTaV1pfvtmCx3CXnvlF3yqsUCgDOMXm54GNsP vV5DTuGca0f+bTK/MOt1CVeY7zS+FpLigH2xd6Tj4SJk6s714ro5TsA5y0+6jYReZogA F1og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yGsXohVt/pzhBnPGUeXN3JhwTJ6Im10IdiNPWj51poU=; b=kQej/wQdXD1AtefNVr7xqT3UTFiFbpcJY1W8uKBvntFRbp2pnzNO7xoPWisZPsrRl/ e2G2R98eAf/Hv3ou8I73ZmDYj79VtZKs2qzolZRumx5dW9/S7GHxrlPWsNtixbVfcwzu 7OMPcL7Y3FfPRe/Fsoak51xNWTPZuGvu3YjTy1BRtQua+MlMz08tqtSotpYlxJ5IKMIg 6gRU6UzjiPGu1hdW/QVCoVlEJENRsZn7p2m515KQV0LlWRtNTaZM3+0zn7cG8lEe3pQt jYrZmekgvwZPxJwfKpAspjBZrZQKrt8oDRVprfN0BhXu4Y9JfAkugOCo+WeVny6gMDG0 P2MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linuxfoundation.org header.s=korg header.b=bqxvNd+Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w186-20020a022ac3000000b0032133b8a6f6si6614691jaw.161.2022.04.05.15.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:55:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=fail header.i=@linuxfoundation.org header.s=korg header.b=bqxvNd+Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02166163E2E; Tue, 5 Apr 2022 15:36:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344187AbiDEO7J (ORCPT + 99 others); Tue, 5 Apr 2022 10:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344722AbiDEJmi (ORCPT ); Tue, 5 Apr 2022 05:42:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3BE7BF019; Tue, 5 Apr 2022 02:27:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 535A561698; Tue, 5 Apr 2022 09:27:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60113C385A0; Tue, 5 Apr 2022 09:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150877; bh=G/l9aUJULJwmI7YT0KaZ81Zov+Y/RRth+XG3A6aSc6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bqxvNd+YSePTtSvIo9Ou8egV3llgNgVyQaCJAZsroJq4MqBpBXxC+0TQzlObYo0wP W9NWUApAGS2Jhy+5shUMBcfB6uP0wyOYSj6ADxFGrNHg3NdKabMi0cnuIKgrsK9TA5 pKbx4iLJ4iqetqFrFk+cISuy2uf91AfvGhfLNli4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Anton Mitterer , David Sterba , ree.com@vger.kernel.org Subject: [PATCH 5.15 171/913] btrfs: verify the tranisd of the to-be-written dirty extent buffer Date: Tue, 5 Apr 2022 09:20:33 +0200 Message-Id: <20220405070344.976550703@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit 3777369ff1518b579560611a0d0c33f930154f64 upstream. [BUG] There is a bug report that a bitflip in the transid part of an extent buffer makes btrfs to reject certain tree blocks: BTRFS error (device dm-0): parent transid verify failed on 1382301696 wanted 262166 found 22 [CAUSE] Note the failed transid check, hex(262166) = 0x40016, while hex(22) = 0x16. It's an obvious bitflip. Furthermore, the reporter also confirmed the bitflip is from the hardware, so it's a real hardware caused bitflip, and such problem can not be detected by the existing tree-checker framework. As tree-checker can only verify the content inside one tree block, while generation of a tree block can only be verified against its parent. So such problem remain undetected. [FIX] Although tree-checker can not verify it at write-time, we still have a quick (but not the most accurate) way to catch such obvious corruption. Function csum_one_extent_buffer() is called before we submit metadata write. Thus it means, all the extent buffer passed in should be dirty tree blocks, and should be newer than last committed transaction. Using that we can catch the above bitflip. Although it's not a perfect solution, as if the corrupted generation is higher than the correct value, we have no way to catch it at all. Reported-by: Christoph Anton Mitterer Link: https://lore.kernel.org/linux-btrfs/2dfcbc130c55cc6fd067b93752e90bd2b079baca.camel@scientia.org/ CC: stable@vger.kernel.org # 5.15+ Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/disk-io.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -441,17 +441,31 @@ static int csum_one_extent_buffer(struct else ret = btrfs_check_leaf_full(eb); - if (ret < 0) { - btrfs_print_tree(eb, 0); + if (ret < 0) + goto error; + + /* + * Also check the generation, the eb reached here must be newer than + * last committed. Or something seriously wrong happened. + */ + if (unlikely(btrfs_header_generation(eb) <= fs_info->last_trans_committed)) { + ret = -EUCLEAN; btrfs_err(fs_info, - "block=%llu write time tree block corruption detected", - eb->start); - WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG)); - return ret; + "block=%llu bad generation, have %llu expect > %llu", + eb->start, btrfs_header_generation(eb), + fs_info->last_trans_committed); + goto error; } write_extent_buffer(eb, result, 0, fs_info->csum_size); return 0; + +error: + btrfs_print_tree(eb, 0); + btrfs_err(fs_info, "block=%llu write time tree block corruption detected", + eb->start); + WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG)); + return ret; } /* Checksum all dirty extent buffers in one bio_vec */