Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1630329

[PATCH] x86/mm/64: Fix crash in remove_pagetable()

From "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Newsgroups linux.kernel
Subject [PATCH] x86/mm/64: Fix crash in remove_pagetable()
Date 2017-04-25 11:30 +0200
Message-ID <tA4Xf-2Ow-5@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Dan Williams <dan.j.williams@intel.com>
Fixes: f2a6a7050109 ("x86: Convert the rest of the code to support p4d_t")
---
 arch/x86/mm/init_64.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index a242139df8fe..745e5e183169 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -962,7 +962,7 @@ remove_pud_table(pud_t *pud_start, unsigned long addr, unsigned long end,
 			continue;
 		}
 
-		pmd_base = (pmd_t *)pud_page_vaddr(*pud);
+		pmd_base = pmd_offset(pud, 0);
 		remove_pmd_table(pmd_base, addr, next, direct);
 		free_pmd_table(pmd_base, pud);
 	}
@@ -988,7 +988,7 @@ remove_p4d_table(p4d_t *p4d_start, unsigned long addr, unsigned long end,
 
 		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);
 		free_pud_table(pud_base, p4d);
 	}
@@ -1013,7 +1013,7 @@ remove_pagetable(unsigned long start, unsigned long end, bool direct)
 		if (!pgd_present(*pgd))
 			continue;
 
-		p4d = (p4d_t *)pgd_page_vaddr(*pgd);
+		p4d = p4d_offset(pgd, 0);
 		remove_p4d_table(p4d, addr, next, direct);
 	}
 
-- 
2.11.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] x86/mm/64: Fix crash in remove_pagetable() "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2017-04-25 11:30 +0200
  Re: [PATCH] x86/mm/64: Fix crash in remove_pagetable() Dan Williams <dan.j.williams@intel.com> - 2017-04-25 18:50 +0200
    Re: [PATCH] x86/mm/64: Fix crash in remove_pagetable() Ingo Molnar <mingo@kernel.org> - 2017-04-25 21:00 +0200
      Re: [PATCH] x86/mm/64: Fix crash in remove_pagetable() Dan Williams <dan.j.williams@intel.com> - 2017-04-25 21:10 +0200
  [tip:x86/mm] x86/mm/64: Fix crash in remove_pagetable() "tip-bot for Kirill A. Shutemov" <tipbot@zytor.com> - 2017-04-26 10:40 +0200

csiph-web