Skip to content

Commit f28de8d

Browse files
josefbacikkdave
authored andcommitted
btrfs: clear DEAD_RELOC_TREE before dropping the reloc root
The DEAD_RELOC_TREE flag is in place in order to avoid a use after free in init_reloc_root, tracking the presence of reloc_root. However adding the explicit tree references in previous patches makes the use after free impossible because at this point we no longer have a reloc_control set on the fs_info and thus cannot enter the function. So move this to be coupled with clearing the root->reloc_root so we're consistent with all other operations of the reloc root. Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> [ update changelog ] Signed-off-by: David Sterba <[email protected]>
1 parent 1a0afa0 commit f28de8d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fs/btrfs/relocation.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,18 +2275,18 @@ static int clean_dirty_subvols(struct reloc_control *rc)
22752275

22762276
list_del_init(&root->reloc_dirty_list);
22772277
root->reloc_root = NULL;
2278-
if (reloc_root) {
2279-
2280-
ret2 = btrfs_drop_snapshot(reloc_root, 0, 1);
2281-
if (ret2 < 0 && !ret)
2282-
ret = ret2;
2283-
}
22842278
/*
22852279
* Need barrier to ensure clear_bit() only happens after
22862280
* root->reloc_root = NULL. Pairs with have_reloc_root.
22872281
*/
22882282
smp_wmb();
22892283
clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
2284+
2285+
if (reloc_root) {
2286+
ret2 = btrfs_drop_snapshot(reloc_root, 0, 1);
2287+
if (ret2 < 0 && !ret)
2288+
ret = ret2;
2289+
}
22902290
btrfs_put_root(root);
22912291
} else {
22922292
/* Orphan reloc tree, just clean it up */

0 commit comments

Comments
 (0)