提交 4549e55f 编写于 作者: J Josef Bacik 提交者: Zheng Zengkai

btrfs: avoid double put of block group when emptying cluster

stable inclusion
from stable-5.10.22
commit a01415e5e862a60a52b10081532e09f9b3503592
bugzilla: 50796

--------------------------------

commit 95c85fba upstream.

It's wrong calling btrfs_put_block_group in
__btrfs_return_cluster_to_free_space if the block group passed is
different than the block group the cluster represents. As this means the
cluster doesn't have a reference to the passed block group. This results
in double put and a use-after-free bug.

Fix this by simply bailing if the block group we passed in does not
match the block group on the cluster.

Fixes: fa9c0d79 ("Btrfs: rework allocation clustering")
CC: stable@vger.kernel.org # 4.4+
Signed-off-by: NJosef Bacik <josef@toxicpanda.com>
Reviewed-by: NDavid Sterba <dsterba@suse.com>
[ update changelog ]
Signed-off-by: NDavid Sterba <dsterba@suse.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: N  Weilong Chen <chenweilong@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 3614f2ab
...@@ -2714,8 +2714,10 @@ static void __btrfs_return_cluster_to_free_space( ...@@ -2714,8 +2714,10 @@ static void __btrfs_return_cluster_to_free_space(
struct rb_node *node; struct rb_node *node;
spin_lock(&cluster->lock); spin_lock(&cluster->lock);
if (cluster->block_group != block_group) if (cluster->block_group != block_group) {
goto out; spin_unlock(&cluster->lock);
return;
}
cluster->block_group = NULL; cluster->block_group = NULL;
cluster->window_start = 0; cluster->window_start = 0;
...@@ -2753,8 +2755,6 @@ static void __btrfs_return_cluster_to_free_space( ...@@ -2753,8 +2755,6 @@ static void __btrfs_return_cluster_to_free_space(
entry->offset, &entry->offset_index, bitmap); entry->offset, &entry->offset_index, bitmap);
} }
cluster->root = RB_ROOT; cluster->root = RB_ROOT;
out:
spin_unlock(&cluster->lock); spin_unlock(&cluster->lock);
btrfs_put_block_group(block_group); btrfs_put_block_group(block_group);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册