Skip to content

Commit 1e2c043

Browse files
frankjaatorvalds
authored andcommitted
userfaultfd: hugetlbfs: fix userfaultfd_huge_must_wait() pte access
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]>
1 parent 410da1e commit 1e2c043

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

fs/userfaultfd.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,26 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,
222222
unsigned long reason)
223223
{
224224
struct mm_struct *mm = ctx->mm;
225-
pte_t *pte;
225+
pte_t *ptep, pte;
226226
bool ret = true;
227227

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

230-
pte = huge_pte_offset(mm, address, vma_mmu_pagesize(vma));
231-
if (!pte)
230+
ptep = huge_pte_offset(mm, address, vma_mmu_pagesize(vma));
231+
232+
if (!ptep)
232233
goto out;
233234

234235
ret = false;
236+
pte = huge_ptep_get(ptep);
235237

236238
/*
237239
* Lockless access: we're in a wait_event so it's ok if it
238240
* changes under us.
239241
*/
240-
if (huge_pte_none(*pte))
242+
if (huge_pte_none(pte))
241243
ret = true;
242-
if (!huge_pte_write(*pte) && (reason & VM_UFFD_WP))
244+
if (!huge_pte_write(pte) && (reason & VM_UFFD_WP))
243245
ret = true;
244246
out:
245247
return ret;

0 commit comments

Comments
 (0)