Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3858166pxb; Mon, 1 Mar 2021 23:45:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWLPB88YZlWvGyUEY3+VA2P+qkLLrmgiIlzVyGRnUGLc6vzrksfAHAgcbfi44/VB/YLUsG X-Received: by 2002:a17:906:ecf3:: with SMTP id qt19mr13694914ejb.467.1614671112617; Mon, 01 Mar 2021 23:45:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614671112; cv=none; d=google.com; s=arc-20160816; b=aX1mC0NzAlzJ3sV3+gZAbZeisbdyZCRpigaPaCmMrKQnxKH2EeRlA+A1HLXmejJuuU od8ogfjN4YqJNMrcXuiwGz9zmVPoA2Y1n5Kaqh3JTu+GfVjai4CMUBuiLX3UTIvP2pTi AduP8rP9hpplev5Hs+aadrz8um3nxGkt1lj0XSDlR6Yn+mhIwE5HApoNylE+3I4J+BK4 J3/B2pTm9wg2MIf5OzMpongKJ3xrrVwWv2Ryehc+HyoShOh5IFs63KvDqBqhSJqgcfY9 EEtXOEKqEnbA23WbLszdnTUCv1vIX2fogw39rVjE4T2y7DFbnqyRosBpAzIMw8zuILe5 jL8Q== 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=PXkljQnK4XNW4RFrRiNjLBTm8xFHHbSeCc77z32RFR8=; b=GhjVUTdQv8OnCcJqdCoS8UNPJo54JQz2BC4jPVvNJpyoiUnv+ydPf40xL4JDyxthty /DZ1bfBTyt0z/A9HHorgoIa0AkchHqF64BWgBqBWB34Q28AUw/ZZAvusd+hU0+RPy6Mv R6bOD/InY0kR58lsI+6mO0q6nzkNJScI38xB62BqhaGFDmEMwEqg80TTARc81eYDCMOD rByxavQyctP4LSp8PIKvtNytLtQkU1e25sX96jti16qa88qIgzoerHY6fPwQ/rDvKPS5 pvA5GFJaYvpFi0mdiosp8HBw2ZR3UKIKI4pnr+AEpi83XwstAkUY2FQf1K1K5Vr5Ubv+ U+bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=COGkaXlh; 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 o26si12864513edw.74.2021.03.01.23.44.49; Mon, 01 Mar 2021 23:45:12 -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=COGkaXlh; 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 S240484AbhCBA7n (ORCPT + 99 others); Mon, 1 Mar 2021 19:59:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:54272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234837AbhCAStl (ORCPT ); Mon, 1 Mar 2021 13:49:41 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id CE4CD65248; Mon, 1 Mar 2021 17:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619659; bh=nSiaW/OjZpuOy3q63iX/DV1X59gPOFmiUbN5Dd7e5sY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=COGkaXlh795BLYZxTdT9oso0BGNs9pPqPRKhXO4bpFAh+1skng5vU6p3No+ODUNw1 6fjQQPZY0LUPPYDsoARWPq66iAl9qP4EjnlIUOjEWOVxaHMfEDZ9IqSrgIOqfqWIKg 5Io+9oA6Umt2iwqU0PkVLvTV1qA32lWx08dbJ1yE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 5.10 535/663] btrfs: fix reloc root leak with 0 ref reloc roots on recovery Date: Mon, 1 Mar 2021 17:13:03 +0100 Message-Id: <20210301161208.322718165@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@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 c78a10aebb275c38d0cfccae129a803fe622e305 upstream. When recovering a relocation, if we run into a reloc root that has 0 refs we simply add it to the reloc_control->reloc_roots list, and then clean it up later. The problem with this is __del_reloc_root() doesn't do anything if the root isn't in the radix tree, which in this case it won't be because we never call __add_reloc_root() on the reloc_root. This exit condition simply isn't correct really. During normal operation we can remove ourselves from the rb tree and then we're meant to clean up later at merge_reloc_roots() time, and this happens correctly. During recovery we're depending on free_reloc_roots() to drop our references, but we're short-circuiting. Fix this by continuing to check if we're on the list and dropping ourselves from the reloc_control root list and dropping our reference appropriately. Change the corresponding BUG_ON() to an ASSERT() that does the correct thing if we aren't in the rb tree. CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/relocation.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -669,9 +669,7 @@ static void __del_reloc_root(struct btrf RB_CLEAR_NODE(&node->rb_node); } spin_unlock(&rc->reloc_root_tree.lock); - if (!node) - return; - BUG_ON((struct btrfs_root *)node->data != root); + ASSERT(!node || (struct btrfs_root *)node->data == root); } /*