Skip to content

Commit

Permalink
mm/hugetlb: fix cow where page writtable in child
Browse files Browse the repository at this point in the history
When rework early cow of pinned hugetlb pages, we moved huge_ptep_get()
upper but overlooked a side effect that the huge_ptep_get() will fetch the
pte after wr-protection.  After moving it upwards, we need explicit
wr-protect of child pte or we will keep the write bit set in the child
process, which could cause data corrution where the child can write to the
original page directly.

This issue can also be exposed by "memfd_test hugetlbfs" kselftest.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 4eae4ef ("hugetlb: do early cow when page pinned on src mm")
Signed-off-by: Peter Xu <[email protected]>
Reviewed-by: Mike Kravetz <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Joel Fernandes (Google) <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
xzpeter authored and torvalds committed May 15, 2021
1 parent 22247ef commit 84894e1
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions mm/hugetlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4056,6 +4056,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
* See Documentation/vm/mmu_notifier.rst
*/
huge_ptep_set_wrprotect(src, addr, src_pte);
entry = huge_pte_wrprotect(entry);
}

page_dup_rmap(ptepage, true);
Expand Down

0 comments on commit 84894e1

Please sign in to comment.