WSL2-Linux-Kernel/arch/x86/mm
Joerg Roedel 9a62d20027 x86/mm/32: Sync only to VMALLOC_END in vmalloc_sync_all()
The job of vmalloc_sync_all() is to help the lazy freeing of vmalloc()
ranges: before such vmap ranges are reused we make sure that they are
unmapped from every task's page tables.

This is really easy on pagetable setups where the kernel page tables
are shared between all tasks - this is the case on 32-bit kernels
with SHARED_KERNEL_PMD = 1.

But on !SHARED_KERNEL_PMD 32-bit kernels this involves iterating
over the pgd_list and clearing all pmd entries in the pgds that
are cleared in the init_mm.pgd, which is the reference pagetable
that the vmalloc() code uses.

In that context the current practice of vmalloc_sync_all() iterating
until FIX_ADDR_TOP is buggy:

        for (address = VMALLOC_START & PMD_MASK;
             address >= TASK_SIZE_MAX && address < FIXADDR_TOP;
             address += PMD_SIZE) {
                struct page *page;

Because iterating up to FIXADDR_TOP will involve a lot of non-vmalloc
address ranges:

	VMALLOC -> PKMAP -> LDT -> CPU_ENTRY_AREA -> FIX_ADDR

This is mostly harmless for the FIX_ADDR and CPU_ENTRY_AREA ranges
that don't clear their pmds, but it's lethal for the LDT range,
which relies on having different mappings in different processes,
and 'synchronizing' them in the vmalloc sense corrupts those
pagetable entries (clearing them).

This got particularly prominent with PTI, which turns SHARED_KERNEL_PMD
off and makes this the dominant mapping mode on 32-bit.

To make LDT working again vmalloc_sync_all() must only iterate over
the volatile parts of the kernel address range that are identical
between all processes.

So the correct check in vmalloc_sync_all() is "address < VMALLOC_END"
to make sure the VMALLOC areas are synchronized and the LDT
mapping is not falsely overwritten.

The CPU_ENTRY_AREA and the FIXMAP area are no longer synced either,
but this is not really a proplem since their PMDs get established
during bootup and never change.

This change fixes the ldt_gdt selftest in my setup.

[ mingo: Fixed up the changelog to explain the logic and modified the
         copying to only happen up until VMALLOC_END. ]

Reported-by: Borislav Petkov <bp@suse.de>
Tested-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Cc: <stable@vger.kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: hpa@zytor.com
Fixes: 7757d607c6b3: ("x86/pti: Allow CONFIG_PAGE_TABLE_ISOLATION for x86_32")
Link: https://lkml.kernel.org/r/20191126111119.GA110513@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-11-26 21:53:34 +01:00
..
Makefile Merge branch 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-11-26 09:50:14 -08:00
amdtopology.c
cpu_entry_area.c Merge branch 'x86-iopl-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-11-26 11:12:02 -08:00
debug_pagetables.c x86: mm: no need to check return value of debugfs_create functions 2019-06-03 16:18:12 +02:00
dump_pagetables.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00
extable.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
fault.c x86/mm/32: Sync only to VMALLOC_END in vmalloc_sync_all() 2019-11-26 21:53:34 +01:00
highmem_32.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
hugetlbpage.c
ident_map.c
init.c x86/mm: Report which part of kernel image is freed 2019-11-04 18:50:33 +01:00
init_32.c x86/mm: Remove set_pages_x() and set_pages_nx() 2019-09-03 09:26:37 +02:00
init_64.c x86/mm: Report which part of kernel image is freed 2019-11-04 18:50:33 +01:00
iomap_32.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
ioremap.c x86/boot: Introduce setup_indirect 2019-11-12 16:21:15 +01:00
kasan_init_64.c x86/kasan: Fix boot with 5-level paging and KASAN 2019-06-14 16:37:30 +02:00
kaslr.c x86/mm/KASLR: Compute the size of the vmemmap section properly 2019-06-07 23:12:13 +02:00
kmmio.c x86: Use pr_warn instead of pr_warning 2019-10-18 15:00:18 +02:00
maccess.c uaccess: Add strict non-pagefault kernel-space read function 2019-11-02 12:39:12 -07:00
mem_encrypt.c fs/core/vmcore: Move sev_active() reference to x86 arch code 2019-08-09 22:52:10 +10:00
mem_encrypt_boot.S x86/asm: Change all ENTRY+ENDPROC to SYM_FUNC_* 2019-10-18 11:58:33 +02:00
mem_encrypt_identity.c Merge branch 'x86-kdump-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-07-09 11:52:34 -07:00
mm_internal.h
mmap.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
mmio-mod.c x86: Use pr_warn instead of pr_warning 2019-10-18 15:00:18 +02:00
mpx.c signal: Remove task parameter from force_sig 2019-05-27 09:36:28 -05:00
numa.c x86: Fix typos in comments 2019-11-18 10:03:26 +01:00
numa_32.c
numa_64.c
numa_emulation.c x86: Use pr_warn instead of pr_warning 2019-10-18 15:00:18 +02:00
numa_internal.h
pageattr-test.c
pageattr.c x86/mm: Remove the unused set_memory_wt() function 2019-09-03 09:26:37 +02:00
pat.c x86/mm/pat: Drop the rbt_ prefix from external memtype calls 2019-11-21 18:48:07 +01:00
pat_internal.h x86/mm/pat: Drop the rbt_ prefix from external memtype calls 2019-11-21 18:48:07 +01:00
pat_interval.c x86/mm/pat: Rename pat_rbtree.c to pat_interval.c 2019-11-21 18:48:18 +01:00
pf_in.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
pf_in.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
pgtable.c x86/mm: Use the correct function type for native_set_fixmap() 2019-10-11 12:52:32 +02:00
pgtable_32.c
physaddr.c
physaddr.h
pkeys.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
pti.c x86/vmlinux: Actually use _etext for the end of the text segment 2019-11-04 17:54:16 +01:00
setup_nx.c
srat.c
testmmiotrace.c Printk changes for 5.5 2019-11-25 19:40:40 -08:00
tlb.c x86/mm: Avoid redundant interrupt disable in load_mm_cr4() 2019-07-24 14:43:37 +02:00