提交 e6ab9c4d 编写于 作者: K Kirill A. Shutemov 提交者: Ingo Molnar

x86/mm/64: Fix crash in remove_pagetable()

remove_pagetable() does page walk using p*d_page_vaddr() plus cast.
It's not canonical approach -- we usually use p*d_offset() for that.

It works fine as long as all page table levels are present. We broke the
invariant by introducing folded p4d page table level.

As result, remove_pagetable() interprets PMD as PUD and it leads to
crash:

	BUG: unable to handle kernel paging request at ffff880300000000
	IP: memchr_inv+0x60/0x110
	PGD 317d067
	P4D 317d067
	PUD 3180067
	PMD 33f102067
	PTE 8000000300000060

Let's fix this by using p*d_offset() instead of p*d_page_vaddr() for
page walk.
Reported-by: NDan Williams <dan.j.williams@intel.com>
Tested-by: NDan Williams <dan.j.williams@intel.com>
Signed-off-by: NKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-mm@kvack.org
Fixes: f2a6a705 ("x86: Convert the rest of the code to support p4d_t")
Link: http://lkml.kernel.org/r/20170425092557.21852-1-kirill.shutemov@linux.intel.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
上级 6dd29b3d
...@@ -962,7 +962,7 @@ remove_pud_table(pud_t *pud_start, unsigned long addr, unsigned long end, ...@@ -962,7 +962,7 @@ remove_pud_table(pud_t *pud_start, unsigned long addr, unsigned long end,
continue; continue;
} }
pmd_base = (pmd_t *)pud_page_vaddr(*pud); pmd_base = pmd_offset(pud, 0);
remove_pmd_table(pmd_base, addr, next, direct); remove_pmd_table(pmd_base, addr, next, direct);
free_pmd_table(pmd_base, pud); free_pmd_table(pmd_base, pud);
} }
...@@ -988,7 +988,7 @@ remove_p4d_table(p4d_t *p4d_start, unsigned long addr, unsigned long end, ...@@ -988,7 +988,7 @@ remove_p4d_table(p4d_t *p4d_start, unsigned long addr, unsigned long end,
BUILD_BUG_ON(p4d_large(*p4d)); BUILD_BUG_ON(p4d_large(*p4d));
pud_base = (pud_t *)p4d_page_vaddr(*p4d); pud_base = pud_offset(p4d, 0);
remove_pud_table(pud_base, addr, next, direct); remove_pud_table(pud_base, addr, next, direct);
free_pud_table(pud_base, p4d); free_pud_table(pud_base, p4d);
} }
...@@ -1013,7 +1013,7 @@ remove_pagetable(unsigned long start, unsigned long end, bool direct) ...@@ -1013,7 +1013,7 @@ remove_pagetable(unsigned long start, unsigned long end, bool direct)
if (!pgd_present(*pgd)) if (!pgd_present(*pgd))
continue; continue;
p4d = (p4d_t *)pgd_page_vaddr(*pgd); p4d = p4d_offset(pgd, 0);
remove_p4d_table(p4d, addr, next, direct); remove_p4d_table(p4d, addr, next, direct);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册