From 94d53addd5456af4e0300a0a1130e2ba43138c0a Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Fri, 24 Mar 2023 10:26:20 -0400 Subject: [PATCH] mm-hugetlb-fix-uffd-wr-protection-for-cow-optimization-path-v3 Link: https://lkml.kernel.org/r/20230324142620.2344140-1-peterx@redhat.com Reported-by: Muhammad Usama Anjum Cc: linux-stable Fixes: 166f3ecc0daf ("mm/hugetlb: hook page faults for uffd write protection") Signed-off-by: Peter Xu Signed-off-by: Andrew Morton --- mm/hugetlb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9aea548b665c..245038a9fe4e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5491,11 +5491,11 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, * Never handle CoW for uffd-wp protected pages. It should be only * handled when the uffd-wp protection is removed. * - * Note that only the CoW optimization path can trigger this and - * got skipped, because hugetlb_fault() will always resolve uffd-wp - * bit first. + * Note that only the CoW optimization path (in hugetlb_no_page()) + * can trigger this, because hugetlb_fault() will always resolve + * uffd-wp bit first. */ - if (huge_pte_uffd_wp(pte)) + if (!unshare && huge_pte_uffd_wp(pte)) return 0; /* -- 2.50.1