All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix extent buffer leak on failure to copy root
@ 2021-02-04 14:35 fdmanana
  2021-02-04 16:08 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: fdmanana @ 2021-02-04 14:35 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

At btrfs_copy_root(), if the call to btrfs_inc_ref() fails we end up
returning without unlocking and releasing our reference on the extent
buffer named "cow" we previously allocated with btrfs_alloc_tree_block().

So fix that by unlocking the extent buffer and dropping our reference on
it before returning.

Fixes: be20aa9dbadc8c ("Btrfs: Add mount option to turn off data cow")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/ctree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 95d9bae764ab..d56730a67885 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -222,6 +222,8 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 	else
 		ret = btrfs_inc_ref(trans, root, cow, 0);
 	if (ret) {
+		btrfs_tree_unlock(cow);
+		free_extent_buffer(cow);
 		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs: fix extent buffer leak on failure to copy root
  2021-02-04 14:35 [PATCH] btrfs: fix extent buffer leak on failure to copy root fdmanana
@ 2021-02-04 16:08 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-02-04 16:08 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs

On Thu, Feb 04, 2021 at 02:35:44PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> At btrfs_copy_root(), if the call to btrfs_inc_ref() fails we end up
> returning without unlocking and releasing our reference on the extent
> buffer named "cow" we previously allocated with btrfs_alloc_tree_block().
> 
> So fix that by unlocking the extent buffer and dropping our reference on
> it before returning.
> 
> Fixes: be20aa9dbadc8c ("Btrfs: Add mount option to turn off data cow")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-04 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-04 14:35 [PATCH] btrfs: fix extent buffer leak on failure to copy root fdmanana
2021-02-04 16:08 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.