提交 f18bb5e3 编写于 作者: M Muchun Song 提交者: Zheng Zengkai

mm: userfaultfd: fix missing cache flush in mcopy_atomic_pte() and __mcopy_atomic()

stable inclusion
from stable-v5.10.116
commit d1ac096f886914ad2630ffad7adf8658d77a2870
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L64K

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=d1ac096f886914ad2630ffad7adf8658d77a2870

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

commit 7c25a0b8 upstream.

userfaultfd calls mcopy_atomic_pte() and __mcopy_atomic() which do not
do any cache flushing for the target page.  Then the target page will be
mapped to the user space with a different address (user address), which
might have an alias issue with the kernel address used to copy the data
from the user to.  Fix this by insert flush_dcache_page() after
copy_from_user() succeeds.

Link: https://lkml.kernel.org/r/20220210123058.79206-7-songmuchun@bytedance.com
Fixes: b6ebaedb ("userfaultfd: avoid mmap_sem read recursion in mcopy_atomic")
Fixes: c1a4de99 ("userfaultfd: mcopy_atomic|mfill_zeropage: UFFDIO_COPY|UFFDIO_ZEROPAGE preparation")
Signed-off-by: NMuchun Song <songmuchun@bytedance.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Fam Zheng <fam.zheng@bytedance.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lars Persson <lars.persson@axis.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Xiongchun Duan <duanxiongchun@bytedance.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 fe8299b0
...@@ -83,6 +83,8 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, ...@@ -83,6 +83,8 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm,
/* don't free the page */ /* don't free the page */
goto out; goto out;
} }
flush_dcache_page(page);
} else { } else {
page = *pagep; page = *pagep;
*pagep = NULL; *pagep = NULL;
...@@ -621,6 +623,7 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, ...@@ -621,6 +623,7 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm,
err = -EFAULT; err = -EFAULT;
goto out; goto out;
} }
flush_dcache_page(page);
goto retry; goto retry;
} else } else
BUG_ON(page); BUG_ON(page);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册