btrfs: avoid double put of block group when emptying cluster
authorJosef Bacik <josef@toxicpanda.com>
Mon, 25 Jan 2021 21:42:35 +0000 (16:42 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 22 Feb 2021 17:07:45 +0000 (18:07 +0100)
commit95c85fba1f64c3249c67f0078a29f8a125078189
tree94759fd6b4bb04faa4daabca4a1c75583be1757d
parent3660d0bcdb82807d434da9d2e57d88b37331182d
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: fa9c0d795f7b ("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>
fs/btrfs/free-space-cache.c