kernel_optimize_test/arch/x86/mm
Qian Cai 0d02113b31 x86/mm: Fix a crash with kmemleak_scan()
The first kmemleak_scan() call after boot would trigger the crash below
because this callpath:

  kernel_init
    free_initmem
      mem_encrypt_free_decrypted_mem
        free_init_pages

unmaps memory inside the .bss when DEBUG_PAGEALLOC=y.

kmemleak_init() will register the .data/.bss sections and then
kmemleak_scan() will scan those addresses and dereference them looking
for pointer references. If free_init_pages() frees and unmaps pages in
those sections, kmemleak_scan() will crash if referencing one of those
addresses:

  BUG: unable to handle kernel paging request at ffffffffbd402000
  CPU: 12 PID: 325 Comm: kmemleak Not tainted 5.1.0-rc4+ #4
  RIP: 0010:scan_block
  Call Trace:
   scan_gray_list
   kmemleak_scan
   kmemleak_scan_thread
   kthread
   ret_from_fork

Since kmemleak_free_part() is tolerant to unknown objects (not tracked
by kmemleak), it is fine to call it from free_init_pages() even if not
all address ranges passed to this function are known to kmemleak.

 [ bp: Massage. ]

Fixes: b3f0907c71 ("x86/mm: Add .bss..decrypted section to hold shared variables")
Signed-off-by: Qian Cai <cai@lca.pw>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190423165811.36699-1-cai@lca.pw
2019-04-24 11:32:34 +02:00
..
amdtopology.c
cpu_entry_area.c
debug_pagetables.c
dump_pagetables.c x86/mm: Prevent bogus warnings with "noexec=off" 2019-04-16 09:42:10 +02:00
extable.c
fault.c
highmem_32.c
hugetlbpage.c
ident_map.c
init_32.c
init_64.c
init.c x86/mm: Fix a crash with kmemleak_scan() 2019-04-24 11:32:34 +02:00
iomap_32.c
ioremap.c x86/mm: Prevent bogus warnings with "noexec=off" 2019-04-16 09:42:10 +02:00
kasan_init_64.c memblock: drop memblock_alloc_*_nopanic() variants 2019-03-12 10:04:02 -07:00
kaslr.c x86/mm/KASLR: Fix the size of the direct mapping section 2019-04-18 10:42:58 +02:00
kmmio.c
Makefile
mem_encrypt_boot.S
mem_encrypt_identity.c
mem_encrypt.c
mm_internal.h
mmap.c x86/mm: Don't exceed the valid physical address space 2019-03-28 14:13:51 +01:00
mmio-mod.c
mpx.c
numa_32.c
numa_64.c
numa_emulation.c
numa_internal.h
numa.c memblock: drop __memblock_alloc_base() 2019-03-12 10:04:01 -07:00
pageattr-test.c
pageattr.c
pat_internal.h
pat_rbtree.c
pat.c
pf_in.c
pf_in.h
pgtable_32.c
pgtable.c
physaddr.c
physaddr.h
pkeys.c
pti.c x86/mm/pti: Make local symbols static 2019-03-22 13:31:28 +01:00
setup_nx.c
srat.c
testmmiotrace.c
tlb.c x86/mm/tlb: Revert "x86/mm: Align TLB invalidation info" 2019-04-16 10:10:13 +02:00