diff mbox series

[02/13] btrfs: fix extent buffer leak after failure tree mod log failure at split_node()

Message ID 33c0bac2c25c330f773ba765c98efa3992cdc166.1686164803.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: some fixes and updates around handling errors for tree mod log operations | expand

Commit Message

Filipe Manana June 7, 2023, 7:24 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

At split_node(), if we fail to log the tree mod log copy operation, we
return without unlocking the split extent buffer we just allocated and
without decrementing the reference we own on it. Fix this by unlocking
it and decrementing the ref count before returning.

Fixes: 5de865eebb83 ("Btrfs: fix tree mod logging")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/ctree.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Qu Wenruo June 8, 2023, 8:40 a.m. UTC | #1
On 2023/6/8 03:24, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> At split_node(), if we fail to log the tree mod log copy operation, we
> return without unlocking the split extent buffer we just allocated and
> without decrementing the reference we own on it. Fix this by unlocking
> it and decrementing the ref count before returning.
>
> Fixes: 5de865eebb83 ("Btrfs: fix tree mod logging")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   fs/btrfs/ctree.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index 7f7f13965fe9..8496535828de 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -3053,6 +3053,8 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
>
>   	ret = btrfs_tree_mod_log_eb_copy(split, c, 0, mid, c_nritems - mid);
>   	if (ret) {
> +		btrfs_tree_unlock(split);
> +		free_extent_buffer(split);
>   		btrfs_abort_transaction(trans, ret);
>   		return ret;
>   	}
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 7f7f13965fe9..8496535828de 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -3053,6 +3053,8 @@  static noinline int split_node(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_tree_mod_log_eb_copy(split, c, 0, mid, c_nritems - mid);
 	if (ret) {
+		btrfs_tree_unlock(split);
+		free_extent_buffer(split);
 		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}