btrfs: abort in rename_exchange if we fail to insert the second ref
authorJosef Bacik <josef@toxicpanda.com>
Wed, 19 May 2021 18:04:21 +0000 (14:04 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Jun 2021 11:39:28 +0000 (13:39 +0200)
commit0df50d47d17401f9f140dfbe752a65e5d72f9932
tree2c929a6a00f4cb616a48bf2f2b3fc46255c82251
parent48568f3944ee7357e8fed394804745bd981e978a
btrfs: abort in rename_exchange if we fail to insert the second ref

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@vger.kernel.org # 4.9+
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/inode.c