[PATCH] x86/mm/init_32: Don't print out kernel memory layout if KASLR

From: Arvind Sankar
Date: Wed Feb 26 2020 - 16:50:44 EST


For security, only show the virtual kernel memory layout if KASLR is
disabled.

Signed-off-by: Arvind Sankar <nivedita@xxxxxxxxxxxx>
---
arch/x86/mm/init_32.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index 23df4885bbed..53635be69102 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -788,6 +788,10 @@ void __init mem_init(void)
x86_init.hyper.init_after_bootmem();

mem_init_print_info(NULL);
+
+ if (kaslr_enabled())
+ goto skip_layout;
+
printk(KERN_INFO "virtual kernel memory layout:\n"
" fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
" cpu_entry : 0x%08lx - 0x%08lx (%4ld kB)\n"
@@ -827,6 +831,7 @@ void __init mem_init(void)
(unsigned long)&_text, (unsigned long)&_etext,
((unsigned long)&_etext - (unsigned long)&_text) >> 10);

+skip_layout:
/*
* Check boundaries twice: Some fundamental inconsistencies can
* be detected at build time already.
--
2.24.1