From: Josef Bacik josef@toxicpanda.com
stable inclusion from stable-v5.10.42 commit 0df50d47d17401f9f140dfbe752a65e5d72f9932 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9909R CVE: CVE-2021-47113
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=t...
--------------------------------
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
Conflicts: fs/btrfs/inode.c
Signed-off-by: Long Li leo.lilong@huawei.com --- fs/btrfs/inode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 52da573741ed..51a119ac91cd 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9527,6 +9527,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, int ret; bool root_log_pinned = false; bool dest_log_pinned = false; + bool need_abort = false; struct btrfs_log_ctx ctx_root; struct btrfs_log_ctx ctx_dest; bool sync_log_root = false; @@ -9591,6 +9592,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, old_idx); if (ret) goto out_fail; + need_abort = true; }
/* And now for the dest. */ @@ -9606,8 +9608,11 @@ static int btrfs_rename_exchange(struct inode *old_dir, 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. */
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/5361 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/3...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/5361 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/3...