All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm/mem_encrypt: fix a crash with kmemleak_scan
@ 2019-04-09  4:05 Qian Cai
  2019-04-16 13:44 ` Catalin Marinas
  2019-04-16 17:11 ` Borislav Petkov
  0 siblings, 2 replies; 11+ messages in thread
From: Qian Cai @ 2019-04-09  4:05 UTC (permalink / raw)
  To: dave.hansen, luto, peterz
  Cc: catalin.marinas, tglx, mingo, bp, x86, linux-kernel, Qian Cai

The first kmemleak_scan() after boot would trigger a crash below because

kernel_init
  free_initmem
    mem_encrypt_free_decrypted_mem
      free_init_pages

unmapped some memory inside the .bss.

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+0x58/0x160
Call Trace:
 scan_gray_list+0x1d9/0x280
 kmemleak_scan+0x485/0xad0
 kmemleak_scan_thread+0x9f/0xc4
 kthread+0x1d2/0x1f0
 ret_from_fork+0x35/0x40

Signed-off-by: Qian Cai <cai@lca.pw>
---
 arch/x86/mm/mem_encrypt.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c
index 385afa2b9e17..614ab156024f 100644
--- a/arch/x86/mm/mem_encrypt.c
+++ b/arch/x86/mm/mem_encrypt.c
@@ -18,6 +18,7 @@
 #include <linux/dma-direct.h>
 #include <linux/swiotlb.h>
 #include <linux/mem_encrypt.h>
+#include <linux/kmemleak.h>
 
 #include <asm/tlbflush.h>
 #include <asm/fixmap.h>
@@ -369,6 +370,11 @@ void __init mem_encrypt_free_decrypted_mem(void)
 		}
 	}
 
+	/*
+	 * Inform kmemleak about the hole in the .bss section since the
+	 * corresponding pages will be unmapped with DEBUG_PAGEALLOC=y.
+	 */
+	kmemleak_free_part((void *)vaddr, vaddr_end - vaddr);
 	free_init_pages("unused decrypted", vaddr, vaddr_end);
 }
 
-- 
2.17.2 (Apple Git-113)


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-04-23 15:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-09  4:05 [PATCH] x86/mm/mem_encrypt: fix a crash with kmemleak_scan Qian Cai
2019-04-16 13:44 ` Catalin Marinas
2019-04-16 17:11 ` Borislav Petkov
2019-04-17  0:38   ` Qian Cai
2019-04-18  7:45     ` Borislav Petkov
2019-04-18  9:50       ` Catalin Marinas
2019-04-23 13:25         ` Borislav Petkov
2019-04-23 14:02           ` Catalin Marinas
2019-04-23 15:17             ` Borislav Petkov
2019-04-23 14:16           ` Qian Cai
2019-04-23 15:18             ` Borislav Petkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.