]> git.hungrycats.org Git - linux/commit
Btrfs: fix invalid block group rbtree access after bg is removed
authorFilipe Manana <fdmanana@suse.com>
Wed, 26 Nov 2014 15:28:50 +0000 (15:28 +0000)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Fri, 23 Jan 2015 13:21:31 +0000 (08:21 -0500)
commiteae23900563dbba2bde7e18826d57ad0e1856850
tree241f945126065334f614e484e0cd1eb57bc17674
parentab2f4ffe817302e21ad2c75fde74abee5d88551f
Btrfs: fix invalid block group rbtree access after bg is removed

If we grab a block group, for example in btrfs_trim_fs(), we will be holding
a reference on it but the block group can be removed after we got it (via
btrfs_remove_block_group), which means it will no longer be part of the
rbtree.

However, btrfs_remove_block_group() was only calling rb_erase() which leaves
the block group's rb_node left and right child pointers with the same content
they had before calling rb_erase. This was dangerous because a call to
next_block_group() would access the node's left and right child pointers (via
rb_next), which can be no longer valid.

Fix this by clearing a block group's node after removing it from the tree,
and have next_block_group() do a tree search to get the next block group
instead of using rb_next() if our block group was removed.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
(cherry picked from commit 292cbd51ecf85d73195a3e3193937fa770f6ea71)
fs/btrfs/extent-tree.c