linux-stable/arch/x86/mm
Andrey Ryabinin 488beeebdd x86/kasan: Fix boot with 5-level paging and KASAN
commit f3176ec942 upstream.

Since commit d52888aa27 ("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
12a8cc7fcf ("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 d52888aa27 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 d52888aa27
__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: 12a8cc7fcf ("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
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-19 08:21:00 +02:00
..
amdtopology.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cpu_entry_area.c x86/cpu_entry_area: Sync cpu_entry_area to initial_page_table 2018-03-08 22:41:07 -08:00
debug_pagetables.c x86/mm/dump_pagetables: Allow dumping current pagetables 2018-01-02 20:31:02 +01:00
dump_pagetables.c x86/dump_pagetables: Fix LDT remap address marker 2019-01-13 10:00:58 +01:00
extable.c x86/xen: Support early interrupts in xen pv guests 2018-02-03 17:39:17 +01:00
fault.c x86/mm: Remove in_nmi() warning from 64-bit implementation of vmalloc_fault() 2019-05-31 06:47:24 -07:00
highmem_32.c
hugetlbpage.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ident_map.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
init.c x86/speculation/l1tf: Drop the swap storage limit restriction when l1tf=off 2019-01-09 17:14:48 +01:00
init_32.c x86/cpu_entry_area: Sync cpu_entry_area to initial_page_table 2018-03-08 22:41:07 -08:00
init_64.c x86/mm: Drop usage of __flush_tlb_all() in kernel_physical_mapping_init() 2019-01-09 17:14:48 +01:00
iomap_32.c
ioremap.c x86/mm/kmmio: Fix mmiotrace for page unaligned addresses 2018-02-25 11:08:03 +01:00
kasan_init_64.c x86/kasan: Fix boot with 5-level paging and KASAN 2019-06-19 08:21:00 +02:00
kaslr.c x86/kaslr: Fix the vaddr_end mess 2018-01-10 09:31:16 +01:00
kmmio.c x86/mm/kmmio: Make the tracer robust against L1TF 2018-08-15 18:13:01 +02:00
Makefile kmemcheck: rip it out 2018-02-22 15:42:24 +01:00
mem_encrypt.c x86: Use __nostackprotect for sme_encrypt_kernel 2018-01-23 19:58:19 +01:00
mem_encrypt_boot.S x86/mm/sme, objtool: Annotate indirect call in sme_encrypt_execute() 2018-03-15 10:54:37 +01:00
mm_internal.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mmap.c x86/speculation/l1tf: Fix off-by-one error when warning that system has too much RAM 2018-09-05 09:26:37 +02:00
mmio-mod.c x86/boot/e820: Move asm/e820.h to asm/e820/api.h 2017-01-28 09:31:13 +01:00
mpx.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
numa.c Merge branch 'x86/boot' into x86/mm, to avoid conflict 2017-04-11 08:56:05 +02:00
numa_32.c x86/mm/32: Set the '__vmalloc_start_set' flag in initmem_init() 2017-05-09 08:12:27 +02:00
numa_64.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
numa_emulation.c x86/numa_emulation: Fix emulated-to-physical node mapping 2018-10-03 17:00:46 -07:00
numa_internal.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pageattr-test.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pageattr.c x86/mm/pat: Disable preemption around __flush_tlb_all() 2018-11-13 11:14:47 -08:00
pat.c x86/mm: Use proper encryption attributes with /dev/mem 2017-07-18 11:38:05 +02:00
pat_internal.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pat_rbtree.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pf_in.c
pf_in.h
pgtable.c x86/mm: Expand static page table for fixmap space 2018-10-03 17:00:54 -07:00
pgtable_32.c x86/mm: Rename flush_tlb_single() and flush_tlb_one() to __flush_tlb_one_[user|kernel]() 2018-02-22 15:42:24 +01:00
physaddr.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
physaddr.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pkeys.c x86/pkeys: Override pkey when moving away from PROT_EXEC 2018-05-22 18:53:59 +02:00
pti.c x86/speculation: Support 'mitigations=' cmdline option 2019-05-14 19:18:46 +02:00
setup_nx.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
srat.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
testmmiotrace.c Annotate hardware config module parameters in arch/x86/mm/ 2017-04-04 16:54:21 +01:00
tlb.c x86/speculation: Prepare for conditional IBPB in switch_mm() 2018-12-05 19:41:21 +01:00