Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp406834pxb; Wed, 3 Mar 2021 06:22:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhiEOMvHFwuDiNX5WZNxDsdRC4GtExEuBw8WeH8+8X4eAH+53ZbVt2b+icJt9mYW0V7mR3 X-Received: by 2002:a17:906:4d44:: with SMTP id b4mr23458342ejv.338.1614781360623; Wed, 03 Mar 2021 06:22:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614781360; cv=none; d=google.com; s=arc-20160816; b=n38Ycm00h0rfUk4P0G/ifOKeTVFJEXyvjjeMzAPEfk2QKu0088t43PZ5odNSga7JuF 2PbJpQ3kd+5ROK4E5hQ7mQTCtN5oSkQ+SkO9BxWAmhgLuUwao0YxDYVmleuG+28ut1X/ 5Ne0JUdYuG4Q3KrMKOm19J+Ht/UttCc8zTevcjuqLwfhNDpBdnzHA+K9nJi5/VdrF3Q4 UGUU0hOTMq/uPb5/gurhlo8RWNcvTUAhtf04jxD9E0aOYWlcl74rttmTD5B5fkCfya4N A6wr2y3vqrRyfolDOOzqT3gZpg4SApDLoReNBdNeMJnX8c9y6hOnqW6jNKptstC1xSlK evhg== 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=5HuuWIlIh/kVCZELBxO4R4OJezM27BsrIatwbOLxpRk=; b=BHMtcEFQpMthrgHpsq+/geDi24jhP+VgYkMnRv1Hshf3FwIpVpaIEwAZbiF6QaQwL3 x4Bu8LiOdG1K3bH7UKi4IlqntusYOZwt6tqXT5uase9watW+F307c+UAWliKhZA1x15w ZBl1EE5TEJhLB4toENxT05hu1vE2vNUxTNpCvZKGGeJdZH3/xOyksHPr/BPbyUcUPubk gJrVLQ5Afkr9agM4+z/LXEwsDv9tBEKmmeRp4ikJSEV5feznqD5borJq/fzeSxAIz2F7 CT6mT2p/pj5TLDpwY5EzydfbrU+dcMZaxoJebrKHrmA3AIB7AF78RNAgwKcbPwUM6nUe TQow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="v/34nNnc"; 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 s20si5678562edq.484.2021.03.03.06.21.45; Wed, 03 Mar 2021 06:22:40 -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="v/34nNnc"; 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 S243035AbhCAVOk (ORCPT + 99 others); Mon, 1 Mar 2021 16:14:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:47630 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237889AbhCARNn (ORCPT ); Mon, 1 Mar 2021 12:13:43 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 209AB6502F; Mon, 1 Mar 2021 16:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617086; bh=dmNY6VhMniOzNzQQzvWXJ8O0SbQOJ+PSRyeNw1rQUk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v/34nNnclv7bhVMj0sbggvVjr1zEeoO4X8ATr7i+66h9JM4rQgl50SJT254xsrN8l kpriusGVjY+f+dlry76XCSMlJXhenrDJwpsIhHFn1D8gcuwnyHn0cpSOjKP5ilURJx AZl50GVxkD3OFHE2ZlR8+xqWRqy39B8Va1C0n+JI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 4.19 198/247] btrfs: fix reloc root leak with 0 ref reloc roots on recovery Date: Mon, 1 Mar 2021 17:13:38 +0100 Message-Id: <20210301161041.345563657@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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 @@ -1291,9 +1291,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); } spin_lock(&fs_info->trans_lock);