提交 0d2eae50 编写于 作者: J Josef Bacik 提交者: Zheng Zengkai

btrfs: abort in rename_exchange if we fail to insert the second ref

stable inclusion
from stable-5.10.43
commit 0df50d47d17401f9f140dfbe752a65e5d72f9932
bugzilla: 109284
CVE: NA

--------------------------------

commit dc09ef35 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: NJosef Bacik <josef@toxicpanda.com>
Reviewed-by: NDavid Sterba <dsterba@suse.com>
Signed-off-by: NDavid Sterba <dsterba@suse.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 eb0d64a8
...@@ -8890,6 +8890,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, ...@@ -8890,6 +8890,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
int ret2; int ret2;
bool root_log_pinned = false; bool root_log_pinned = false;
bool dest_log_pinned = false; bool dest_log_pinned = false;
bool need_abort = false;
/* we only allow rename subvolume link between subvolumes */ /* we only allow rename subvolume link between subvolumes */
if (old_ino != BTRFS_FIRST_FREE_OBJECTID && root != dest) if (old_ino != BTRFS_FIRST_FREE_OBJECTID && root != dest)
...@@ -8946,6 +8947,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, ...@@ -8946,6 +8947,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
old_idx); old_idx);
if (ret) if (ret)
goto out_fail; goto out_fail;
need_abort = true;
} }
/* And now for the dest. */ /* And now for the dest. */
...@@ -8961,9 +8963,12 @@ static int btrfs_rename_exchange(struct inode *old_dir, ...@@ -8961,9 +8963,12 @@ static int btrfs_rename_exchange(struct inode *old_dir,
new_ino, new_ino,
btrfs_ino(BTRFS_I(old_dir)), btrfs_ino(BTRFS_I(old_dir)),
new_idx); new_idx);
if (ret) if (ret) {
if (need_abort)
btrfs_abort_transaction(trans, ret);
goto out_fail; goto out_fail;
} }
}
/* Update inode version and ctime/mtime. */ /* Update inode version and ctime/mtime. */
inode_inc_iversion(old_dir); inode_inc_iversion(old_dir);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册