Skip to content

Commit 457a98b

Browse files
Hugh Dickinstorvalds
authored andcommitted
mm, x86: fix pte_page() crash in gup_pte_range()
Commit 3565fce ("mm, x86: get_user_pages() for dax mappings") has moved up the pte_page(pte) in x86's fast gup_pte_range(), for no discernible reason: put it back where it belongs, after the pte_flags check and the pfn_valid cross-check. That may be the cause of the NULL pointer dereference in gup_pte_range(), seen when vfio called vaddr_get_pfn() when starting a qemu-kvm based VM. Signed-off-by: Hugh Dickins <[email protected]> Reported-by: Michael Long <[email protected]> Tested-by: Michael Long <[email protected]> Acked-by: Dan Williams <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0918f1c commit 457a98b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/x86/mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ static noinline int gup_pte_range(pmd_t pmd, unsigned long addr,
102102
return 0;
103103
}
104104

105-
page = pte_page(pte);
106105
if (pte_devmap(pte)) {
107106
pgmap = get_dev_pagemap(pte_pfn(pte), pgmap);
108107
if (unlikely(!pgmap)) {
@@ -115,6 +114,7 @@ static noinline int gup_pte_range(pmd_t pmd, unsigned long addr,
115114
return 0;
116115
}
117116
VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
117+
page = pte_page(pte);
118118
get_page(page);
119119
put_dev_pagemap(pgmap);
120120
SetPageReferenced(page);

0 commit comments

Comments
 (0)