public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix transaction handle leak after verity rollback failure
@ 2021-09-08 15:29 fdmanana
  2021-09-08 17:12 ` Boris Burkov
  2021-09-09 15:28 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: fdmanana @ 2021-09-08 15:29 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

During a verity rollback, if we fail to update the inode or delete the
orphan, we abort the transaction and return without releasing our
transaction handle. Fix that by releasing the handle.

Fixes: 146054090b0859 ("btrfs: initial fsverity support")
Fixes: 705242538ff348 ("btrfs: verity metadata orphan items")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/verity.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/verity.c b/fs/btrfs/verity.c
index 28d443d3ef93..4968535dfff0 100644
--- a/fs/btrfs/verity.c
+++ b/fs/btrfs/verity.c
@@ -451,7 +451,7 @@ static int del_orphan(struct btrfs_trans_handle *trans, struct btrfs_inode *inod
  */
 static int rollback_verity(struct btrfs_inode *inode)
 {
-	struct btrfs_trans_handle *trans;
+	struct btrfs_trans_handle *trans = NULL;
 	struct btrfs_root *root = inode->root;
 	int ret;
 
@@ -473,6 +473,7 @@ static int rollback_verity(struct btrfs_inode *inode)
 	trans = btrfs_start_transaction(root, 2);
 	if (IS_ERR(trans)) {
 		ret = PTR_ERR(trans);
+		trans = NULL;
 		btrfs_handle_fs_error(root->fs_info, ret,
 			"failed to start transaction in verity rollback %llu",
 			(u64)inode->vfs_inode.i_ino);
@@ -490,8 +491,9 @@ static int rollback_verity(struct btrfs_inode *inode)
 		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
-	btrfs_end_transaction(trans);
 out:
+	if (trans)
+		btrfs_end_transaction(trans);
 	return ret;
 }
 
-- 
2.33.0


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

* Re: [PATCH] btrfs: fix transaction handle leak after verity rollback failure
  2021-09-08 15:29 [PATCH] btrfs: fix transaction handle leak after verity rollback failure fdmanana
@ 2021-09-08 17:12 ` Boris Burkov
  2021-09-09 15:28 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Boris Burkov @ 2021-09-08 17:12 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs

On Wed, Sep 08, 2021 at 04:29:26PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> During a verity rollback, if we fail to update the inode or delete the
> orphan, we abort the transaction and return without releasing our
> transaction handle. Fix that by releasing the handle.
> 
> Fixes: 146054090b0859 ("btrfs: initial fsverity support")
> Fixes: 705242538ff348 ("btrfs: verity metadata orphan items")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Oops, I thoughtlessly assumed abort also released the handle. Thank you
for the fix!
Reviewed-by: Boris Burkov <boris@bur.io>
> ---
>  fs/btrfs/verity.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/verity.c b/fs/btrfs/verity.c
> index 28d443d3ef93..4968535dfff0 100644
> --- a/fs/btrfs/verity.c
> +++ b/fs/btrfs/verity.c
> @@ -451,7 +451,7 @@ static int del_orphan(struct btrfs_trans_handle *trans, struct btrfs_inode *inod
>   */
>  static int rollback_verity(struct btrfs_inode *inode)
>  {
> -	struct btrfs_trans_handle *trans;
> +	struct btrfs_trans_handle *trans = NULL;
>  	struct btrfs_root *root = inode->root;
>  	int ret;
>  
> @@ -473,6 +473,7 @@ static int rollback_verity(struct btrfs_inode *inode)
>  	trans = btrfs_start_transaction(root, 2);
>  	if (IS_ERR(trans)) {
>  		ret = PTR_ERR(trans);
> +		trans = NULL;
>  		btrfs_handle_fs_error(root->fs_info, ret,
>  			"failed to start transaction in verity rollback %llu",
>  			(u64)inode->vfs_inode.i_ino);
> @@ -490,8 +491,9 @@ static int rollback_verity(struct btrfs_inode *inode)
>  		btrfs_abort_transaction(trans, ret);
>  		goto out;
>  	}
> -	btrfs_end_transaction(trans);
>  out:
> +	if (trans)
> +		btrfs_end_transaction(trans);
>  	return ret;
>  }
>  
> -- 
> 2.33.0
> 

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

* Re: [PATCH] btrfs: fix transaction handle leak after verity rollback failure
  2021-09-08 15:29 [PATCH] btrfs: fix transaction handle leak after verity rollback failure fdmanana
  2021-09-08 17:12 ` Boris Burkov
@ 2021-09-09 15:28 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2021-09-09 15:28 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs

On Wed, Sep 08, 2021 at 04:29:26PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> During a verity rollback, if we fail to update the inode or delete the
> orphan, we abort the transaction and return without releasing our
> transaction handle. Fix that by releasing the handle.
> 
> Fixes: 146054090b0859 ("btrfs: initial fsverity support")
> Fixes: 705242538ff348 ("btrfs: verity metadata orphan items")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Added to misc-next, thanks.

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

end of thread, other threads:[~2021-09-09 15:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-08 15:29 [PATCH] btrfs: fix transaction handle leak after verity rollback failure fdmanana
2021-09-08 17:12 ` Boris Burkov
2021-09-09 15:28 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox