]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: fix extent map leak in unexpected scenario at unpin_extent_cache()
authorFilipe Manana <fdmanana@suse.com>
Wed, 13 Mar 2024 11:37:31 +0000 (11:37 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Apr 2024 13:32:44 +0000 (15:32 +0200)
[ Upstream commit 8a565ec04d6c43f330e7401e5af3458431b29bc6 ]

At unpin_extent_cache() if we happen to find an extent map with an
unexpected start offset, we jump to the 'out' label and never release the
reference we added to the extent map through the call to
lookup_extent_mapping(), therefore resulting in a leak. So fix this by
moving the free_extent_map() under the 'out' label.

Fixes: c03c89f821e5 ("btrfs: handle errors returned from unpin_extent_cache()")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/extent_map.c

index c02039db5d2470a4ec6c4cd94720cf4b366f39b5..76378382dd8c4bda999388b32fecbbff1524f0f4 100644 (file)
@@ -342,9 +342,9 @@ int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen)
                em->mod_len = em->len;
        }
 
-       free_extent_map(em);
 out:
        write_unlock(&tree->lock);
+       free_extent_map(em);
        return ret;
 
 }