Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3983052pxb; Tue, 25 Jan 2022 00:38:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTyJccuWQ1mIL3m41mHO/CdJPedcncizPRq8+TVI2Fv1uAXp/9yudjYGg+S5BiyHOu4RFS X-Received: by 2002:aa7:de82:: with SMTP id j2mr19275655edv.389.1643099906340; Tue, 25 Jan 2022 00:38:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643099906; cv=none; d=google.com; s=arc-20160816; b=HtAtCMp/YjFg4Q0LF0GyObCE5KMLve7fDZTgqSoXmhnPw5/wjp2tV31VlZYYSmLG5D m6H+hi9PHQQA01wTPj5mW89nCflmgKuXROm2FN8CStAj0PoN/XHiE03eolRq/wp6NaEH idlAnAJ1jXJp/4xDpFqipHcQXvDw6Sfv13oB2Z2OYv47I/sP69rZDAjK4aCcloWMMQDQ DxZgDHGsfyLbGCnmGpgd/YEP+EJxivtsRuuiP6nI1S/a2w9535Ij3MQQvJFYqIBzps7l Ae7ntSojblf/21KPHpXxuPV0xPPIBLZTLwIhhenf2NnVwZJyb3WoJ6kp8MiiM9sUb4DM nl4Q== 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=Wod68ZXybI6zElb6lc34A6gkeBzmEHTk6+PIvD5wA0k=; b=I/6EUwQaSDiqLie9u4Rl00u4H6YRR49uB5Ze+/tJIEuD03Iren90M6qWQcXlI4NlK5 4+GBEt3XsWB+gfHzQUPGH3J3rLQS4I8WV7Lx4AU5aC5C62typy2w9FpytHe6G84xcoNc uQbLY1z2msCvkpT/hP3DE+2NuzwMejQ4hM+u0p016ai+9C3zOsBjJo/B7lfcHSCg9gLd Qf/ydFDAy+LhbZyTxgl7sOkVxtJrVAH3axXCK+0EgpKKyK74n37xg0UM+H5cV89fhpvz B6LyAcnhSn8s852Vht9uBm120CR+ZwPPvVaQjxEhUtk/D2k3ZYDCe15QX62hUjs/EBpz ku/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uG+o+3If; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id go13si10346767ejc.668.2022.01.25.00.38.02; Tue, 25 Jan 2022 00:38:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uG+o+3If; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1314734AbiAYCvh (ORCPT + 99 others); Mon, 24 Jan 2022 21:51:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353979AbiAXVFL (ORCPT ); Mon, 24 Jan 2022 16:05:11 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52D34C068092; Mon, 24 Jan 2022 12:04:46 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 18F25B8119E; Mon, 24 Jan 2022 20:04:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45333C340E5; Mon, 24 Jan 2022 20:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643054683; bh=reE3UCFEJ7VrG77GGUJOYXy17lvnA1Oi9FlqzgLl1Bw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uG+o+3Ifbjd7f870GCdrKYGyNCHHNQb+fRIwwtCeS0O457BmqCbMqfM2G9K89uZ9X ha1a7Y9bo3iAHYOCSEVNBMbPI292tz0IaEX9F3+HjLl/+Bt2oA/MQtPL+GFv50jpn0 ovyx5mcTo/TzRl6MlePFzDHAmHaSYxyoYX69x++Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , Josef Bacik , David Sterba Subject: [PATCH 5.10 470/563] btrfs: check the root node for uptodate before returning it Date: Mon, 24 Jan 2022 19:43:55 +0100 Message-Id: <20220124184040.722129554@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik commit 120de408e4b97504a2d9b5ca534b383de2c73d49 upstream. Now that we clear the extent buffer uptodate if we fail to write it out we need to check to see if our root node is uptodate before we search down it. Otherwise we could return stale data (or potentially corrupt data that was caught by the write verification step) and think that the path is OK to search down. CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Nikolay Borisov Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ctree.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -2589,12 +2589,9 @@ static struct extent_buffer *btrfs_searc { struct btrfs_fs_info *fs_info = root->fs_info; struct extent_buffer *b; - int root_lock; + int root_lock = 0; int level = 0; - /* We try very hard to do read locks on the root */ - root_lock = BTRFS_READ_LOCK; - if (p->search_commit_root) { /* * The commit roots are read only so we always do read locks, @@ -2632,6 +2629,9 @@ static struct extent_buffer *btrfs_searc goto out; } + /* We try very hard to do read locks on the root */ + root_lock = BTRFS_READ_LOCK; + /* * If the level is set to maximum, we can skip trying to get the read * lock. @@ -2658,6 +2658,17 @@ static struct extent_buffer *btrfs_searc level = btrfs_header_level(b); out: + /* + * The root may have failed to write out at some point, and thus is no + * longer valid, return an error in this case. + */ + if (!extent_buffer_uptodate(b)) { + if (root_lock) + btrfs_tree_unlock_rw(b, root_lock); + free_extent_buffer(b); + return ERR_PTR(-EIO); + } + p->nodes[level] = b; if (!p->skip_locking) p->locks[level] = root_lock;