From: Josef Bacik Date: Mon, 28 Jan 2013 14:45:20 +0000 (-0500) Subject: Btrfs: do not merge logged extents if we've removed them from the tree X-Git-Tag: v5.15~20776^2~2^2~5 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=222c81dc3874b4fe98371be665d0447a36447653;p=mirror_ubuntu-kernels.git Btrfs: do not merge logged extents if we've removed them from the tree You can run into this problem where if somebody is fsyncing and writing out the existing extents you will have removed the extent map from the em tree, but it's still valid for the current fsync so we go ahead and write it. The problem is we unconditionally try to merge it back into the em tree, but if we've removed it from the em tree that will cause use after free problems. Fix this to only merge if we are still a part of the tree. Thanks, Signed-off-by: Josef Bacik --- diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index ed88f5ee4bea..9759911dd34e 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -289,7 +289,8 @@ out: void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em) { clear_bit(EXTENT_FLAG_LOGGING, &em->flags); - try_merge_map(tree, em); + if (em->in_tree) + try_merge_map(tree, em); } /**