Skip to content

Commit

Permalink
userfaultfd: hugetlbfs: fix userfaultfd_huge_must_wait() pte access
Browse files Browse the repository at this point in the history
Use huge_ptep_get() to translate huge ptes to normal ptes so we can
check them with the huge_pte_* functions.  Otherwise some architectures
will check the wrong values and will not wait for userspace to bring in
the memory.

Link: http://lkml.kernel.org/r/[email protected]
Fixes: 369cd21 ("userfaultfd: hugetlbfs: userfaultfd_huge_must_wait for hugepmd ranges")
Signed-off-by: Janosch Frank <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Reviewed-by: Mike Kravetz <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
frankjaa authored and torvalds committed Jul 4, 2018
1 parent 410da1e commit 1e2c043
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions fs/userfaultfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,26 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,
unsigned long reason)
{
struct mm_struct *mm = ctx->mm;
pte_t *pte;
pte_t *ptep, pte;
bool ret = true;

VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));

pte = huge_pte_offset(mm, address, vma_mmu_pagesize(vma));
if (!pte)
ptep = huge_pte_offset(mm, address, vma_mmu_pagesize(vma));

if (!ptep)
goto out;

ret = false;
pte = huge_ptep_get(ptep);

/*
* Lockless access: we're in a wait_event so it's ok if it
* changes under us.
*/
if (huge_pte_none(*pte))
if (huge_pte_none(pte))
ret = true;
if (!huge_pte_write(*pte) && (reason & VM_UFFD_WP))
if (!huge_pte_write(pte) && (reason & VM_UFFD_WP))
ret = true;
out:
return ret;
Expand Down

0 comments on commit 1e2c043

Please sign in to comment.