Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3663534pxb; Mon, 24 Jan 2022 14:47:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxENhmNds47CfW1RbTYptbtRbsAFId2CGuZ5drzM/oS6TWC54pSmGUCeKH+TdYJ7nS/5fGK X-Received: by 2002:a17:903:11c9:b0:149:bef4:2d7d with SMTP id q9-20020a17090311c900b00149bef42d7dmr16647346plh.48.1643064469802; Mon, 24 Jan 2022 14:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064469; cv=none; d=google.com; s=arc-20160816; b=mxSP2twKDDa74opWm6BDlyfUCa3X0gbiWEy712YOk10f2V9UHzQBlLsMOYUm6x4cjp L9u3M7qPBN8qsKUACFPLJ+uPPliuiOVNUAIle3iX+wRb1AwwPFNyTDYclMgq0XM8D8by NlPDzAOmvJl/QFEyC29JjxAHd9dQRlpKn9H+6gjr3PCVQrtAYeXo7XAWpRgUDVxlFXzC tjdc6bIys51H4+RTFNq9xIqS7JFG1Tl+Qv5LkHO3BlmGTGPcCDX/xq99pXliTEXGdNRl FtKvAacv6pizJy/8VdLhzHGEkcP8XJw3rUNwqZM219IMApcuOfJjuOw3LFH/37AW7ufQ 3gLw== 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=FWzld9QI0m5X8zQw3i9oSV8j8Jq3sXwVUHJxiifb8g8=; b=u69AAQon4Obv+179xyiIkFVKytKA/wl+EI2F7UBWi+Auokc33qr4czvXkpUgq8x+eU Y/b3DBzgjGBDfYuljeSiX1Gi34KyNs0P6PUtTN463X0eNps0k0UShO84sifohvhItbCf feJj237/dJCVKL3GcmeSzxdPRCuEX58elh0kD9UysaYBSg+gwRNWlTxXcfSnNlwJtxt9 iqWMDWdK6dYwv2vvOTtz9BKenMDLhQRKfKA2W5luswbNi26bQLVkTaDiKC5AHVBgtOEu Cu2UifnU7NGKW0MA8GUQmlMYQVhvr+FnpPnp4P+GB1CfQdbIT7cWJ+S8r92fqSk1Yf/6 6FPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N6ZV7o86; 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 mw5si644155pjb.87.2022.01.24.14.47.30; Mon, 24 Jan 2022 14:47:49 -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=N6ZV7o86; 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 S1837993AbiAXWpo (ORCPT + 99 others); Mon, 24 Jan 2022 17:45:44 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47594 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377338AbiAXVh3 (ORCPT ); Mon, 24 Jan 2022 16:37:29 -0500 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 F2D18B81142; Mon, 24 Jan 2022 21:37:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2393CC340E7; Mon, 24 Jan 2022 21:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060237; bh=NoAJVYw6CP/5wj4wKs43vSyyWuXkyI9r0CT4hhQoO8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N6ZV7o86rpTbcfpnGZu53diW3t1PDaPhohU46LfkhkXWEiTNcTAkI/DYrB7DpYPlP pRHjk2i0qC2tqVfV2lvBMYde8zeBIbkJD9I6+xivmOM7O3wsY/skzMlmUGdjzmkb91 00gaZZlrgNOnA7N4gBwX6YoCKIqwZATyUKcVMYZI= 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.16 0884/1039] btrfs: check the root node for uptodate before returning it Date: Mon, 24 Jan 2022 19:44:33 +0100 Message-Id: <20220124184155.007622603@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 @@ -1570,12 +1570,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, @@ -1613,6 +1610,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. @@ -1639,6 +1639,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;