mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-04 09:59:32 +00:00
btrfs: avoid double put of block group when emptying cluster
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: fa9c0d795f
("Btrfs: rework allocation clustering")
CC: stable@vger.kernel.org # 4.4+
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
3660d0bcdb
commit
95c85fba1f
1 changed files with 4 additions and 4 deletions
|
@ -2801,8 +2801,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;
|
||||||
|
@ -2840,8 +2842,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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue