Skip to contentSkip to conversation

mm/hugetlb: avoid corrupting page->mapping in hugetlb_mcopy_atomic_pte

PATCH New Axel Rasmussen 1 participant 1 message Aug 29, 2022 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/hugetlb: avoid corrupting page->mapping in hugetlb_mcopy_atomic_pte

From: Miaohe Lin <[email protected]>

commit ab74ef708dc51df7cf2b8a890b9c6990fac5c0c6 upstream.

In MCOPY_ATOMIC_CONTINUE case with a non-shared VMA, pages in the page cache are installed in the ptes. But hugepage_add_new_anon_rmap is called for them mistakenly because they're not vm_shared. This will corrupt the page->mapping used by page cache code.

Fixes f619147104c8 ("userfaultfd: add UFFDIO_CONTINUE ioctl")
Cc Axel Rasmussen <[email protected]>
Cc Peter Xu <[email protected]>
---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c +1 -1
index 405793b8cf0d..d61b665c45d6 100644
@@ -5371,7 +5371,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
 	if (!huge_pte_none(huge_ptep_get(dst_pte)))
 		goto out_release_unlock;
 
-	if (vm_shared) {
+	if (page_in_pagecache) {
 		page_dup_rmap(page, true);
 	} else {
 		ClearHPageRestoreReserve(page);
Signature · 1 line
2.37.2.672.g94769d06f0-goog