This is a note to let you know that I've just added the patch titled btrfs: abort in rename_exchange if we fail to insert the second ref to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: btrfs-abort-in-rename_exchange-if-we-fail-to-insert-the-second-ref.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From dc09ef3562726cd520c8338c1640872a60187af5 Mon Sep 17 00:00:00 2001 From: Josef Bacik <josef@xxxxxxxxxxxxxx> Date: Wed, 19 May 2021 14:04:21 -0400 Subject: btrfs: abort in rename_exchange if we fail to insert the second ref From: Josef Bacik <josef@xxxxxxxxxxxxxx> commit dc09ef3562726cd520c8338c1640872a60187af5 upstream. Error injection stress uncovered a problem where we'd leave a dangling inode ref if we failed during a rename_exchange. This happens because we insert the inode ref for one side of the rename, and then for the other side. If this second inode ref insert fails we'll leave the first one dangling and leave a corrupt file system behind. Fix this by aborting if we did the insert for the first inode ref. CC: stable@xxxxxxxxxxxxxxx # 4.9+ Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx> Reviewed-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/btrfs/inode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8890,6 +8890,7 @@ static int btrfs_rename_exchange(struct int ret2; bool root_log_pinned = false; bool dest_log_pinned = false; + bool need_abort = false; /* we only allow rename subvolume link between subvolumes */ if (old_ino != BTRFS_FIRST_FREE_OBJECTID && root != dest) @@ -8946,6 +8947,7 @@ static int btrfs_rename_exchange(struct old_idx); if (ret) goto out_fail; + need_abort = true; } /* And now for the dest. */ @@ -8961,8 +8963,11 @@ static int btrfs_rename_exchange(struct new_ino, btrfs_ino(BTRFS_I(old_dir)), new_idx); - if (ret) + if (ret) { + if (need_abort) + btrfs_abort_transaction(trans, ret); goto out_fail; + } } /* Update inode version and ctime/mtime. */ Patches currently in stable-queue which might be from josef@xxxxxxxxxxxxxx are queue-5.10/btrfs-fixup-error-handling-in-fixup_inode_link_counts.patch queue-5.10/btrfs-tree-checker-do-not-error-out-if-extent-ref-ha.patch queue-5.10/btrfs-mark-ordered-extent-and-inode-with-error-if-we-fail-to-finish.patch queue-5.10/btrfs-abort-in-rename_exchange-if-we-fail-to-insert-the-second-ref.patch queue-5.10/btrfs-fix-error-handling-in-btrfs_del_csums.patch queue-5.10/btrfs-return-errors-from-btrfs_del_csums-in-cleanup_ref_head.patch