Skip to content

Commit 95c85fb

Browse files
josefbacikkdave
authored andcommitted
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: fa9c0d7 ("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>
1 parent 3660d0b commit 95c85fb

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

fs/btrfs/free-space-cache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,8 +2801,10 @@ static void __btrfs_return_cluster_to_free_space(
28012801
struct rb_node *node;
28022802

28032803
spin_lock(&cluster->lock);
2804-
if (cluster->block_group != block_group)
2805-
goto out;
2804+
if (cluster->block_group != block_group) {
2805+
spin_unlock(&cluster->lock);
2806+
return;
2807+
}
28062808

28072809
cluster->block_group = NULL;
28082810
cluster->window_start = 0;
@@ -2840,8 +2842,6 @@ static void __btrfs_return_cluster_to_free_space(
28402842
entry->offset, &entry->offset_index, bitmap);
28412843
}
28422844
cluster->root = RB_ROOT;
2843-
2844-
out:
28452845
spin_unlock(&cluster->lock);
28462846
btrfs_put_block_group(block_group);
28472847
}

0 commit comments

Comments
 (0)