]> git.baikalelectronics.ru Git - kernel.git/commit
x86/kasan: Fix boot with 5-level paging and KASAN
authorAndrey Ryabinin <aryabinin@virtuozzo.com>
Fri, 14 Jun 2019 14:31:49 +0000 (17:31 +0300)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 14 Jun 2019 14:37:30 +0000 (16:37 +0200)
commitcce219f6cdd9e53ad7cdfa00bac0677c4c77d63f
tree4686a935b15da786848c46f9e5f41ffd326284b7
parent2747b4bc1915f3d36406a0ad8e7c73f8282a7539
x86/kasan: Fix boot with 5-level paging and KASAN

Since commit d8227888e373 ("x86/mm: Move LDT remap out of KASLR region on
5-level paging") kernel doesn't boot with KASAN on 5-level paging machines.
The bug is actually in early_p4d_offset() and introduced by commit
8fb766e65081 ("x86/kasan: Use the same shadow offset for 4- and 5-level paging")

early_p4d_offset() tries to convert pgd_val(*pgd) value to a physical
address. This doesn't make sense because pgd_val() already contains the
physical address.

It did work prior to commit d8227888e373 because the result of
"__pa_nodebug(pgd_val(*pgd)) & PTE_PFN_MASK" was the same as "pgd_val(*pgd)
& PTE_PFN_MASK". __pa_nodebug() just set some high bits which were masked
out by applying PTE_PFN_MASK.

After the change of the PAGE_OFFSET offset in commit d8227888e373
__pa_nodebug(pgd_val(*pgd)) started to return a value with more high bits
set and PTE_PFN_MASK wasn't enough to mask out all of them. So it returns a
wrong not even canonical address and crashes on the attempt to dereference
it.

Switch back to pgd_val() & PTE_PFN_MASK to cure the issue.

Fixes: 8fb766e65081 ("x86/kasan: Use the same shadow offset for 4- and 5-level paging")
Reported-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: kasan-dev@googlegroups.com
Cc: stable@vger.kernel.org
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/20190614143149.2227-1-aryabinin@virtuozzo.com
arch/x86/mm/kasan_init_64.c