mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: tglx@linutronix.de, hpa@zytor.com, mingo@redhat.com
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	keescook@chromium.org, yinghai@kernel.org, bp@suse.de,
	anderson@redhat.com, luto@kernel.org, thgarnie@google.com,
	kuleshovmail@gmail.com, Baoquan He <bhe@redhat.com>
Subject: [PATCH v4 2/3] x86/64/KASLR: Change kernel mapping size to 1G unconditionally
Date: Thu,  2 Feb 2017 20:54:36 +0800	[thread overview]
Message-ID: <1486040077-3719-3-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1486040077-3719-1-git-send-email-bhe@redhat.com>

The current KASLR changes kernel mapping size from 512M to 1G as long
as CONFIG_RANDOMIZE_BASE is enabled, though "nokaslr" kernel option is
added. This is buggy. When people specify "nokaslr", whether KASLR code
compiled in or not, they expect to see no KASLR change at all, including
the size of kernel mapping area and module mapping area.

Kees explained the only reason he made kernel mapping size as an option
was for kernel module space. It wasn't clear at the time if enough space
remained for modules in all use-cases.

Boris suggested we can make the kernel mapping 1G unconditionally since
practically kaslr will be enabled on the majority of the systems anyway,
so we will have 1G text mapping size on most. And he further pointed out
that: [Quote his words as follows]
"""""
Realistically, on a typical bigger machine, the modules take up
something like <10M:

$ lsmod | awk '{ sum +=$2 } END { print sum }'
7188480

so I'm not really worried if we reduce it by default to 1G. Besides, the
reduction has been there for a while now - since CONFIG_RANDOMIZE_BASE -
so we probably would've heard complaints already...
"""""

Hence in this patch change kernel mapping size to 1G unconditionally.

Signed-off-by: Baoquan He <bhe@redhat.com>
Suggested-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/include/asm/page_64_types.h |  9 +--------
 arch/x86/kernel/head_64.S            | 10 ++++------
 2 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
index 24c9098..4120cfe 100644
--- a/arch/x86/include/asm/page_64_types.h
+++ b/arch/x86/include/asm/page_64_types.h
@@ -57,15 +57,8 @@
 
 /*
  * Kernel mapping size is limited to 1GiB due to the fixmap living in the
- * next 1GiB (see level2_kernel_pgt in arch/x86/kernel/head_64.S). Use
- * 512MiB by default, leaving 1.5GiB for modules once the page tables
- * are fully set up. If kernel ASLR is configured, it can extend the
- * kernel page table mapping, reducing the size of the modules area.
+ * next 1GiB (see level2_kernel_pgt in arch/x86/kernel/head_64.S).
  */
-#if defined(CONFIG_RANDOMIZE_BASE)
 #define KERNEL_MAPPING_SIZE	(1024 * 1024 * 1024)
-#else
-#define KERNEL_MAPPING_SIZE	(512 * 1024 * 1024)
-#endif
 
 #endif /* _ASM_X86_PAGE_64_DEFS_H */
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index cdfe4dc..3cc6dc6 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -458,14 +458,12 @@ NEXT_PAGE(level3_kernel_pgt)
 
 NEXT_PAGE(level2_kernel_pgt)
 	/*
-	 * 512 MB kernel mapping. We spend a full page on this pagetable
-	 * anyway.
+	 * 1 GB kernel mapping. We spend a full page on this pagetable.
 	 *
-	 * The kernel code+data+bss must not be bigger than that.
+	 * The kernel image size including code+data+bss must not be bigger
+	 * than this.
 	 *
-	 * (NOTE: at +512MB starts the module area, see MODULES_VADDR.
-	 *  If you want to increase this then increase MODULES_VADDR
-	 *  too.)
+	 * (NOTE: at +1GB starts the module area, see MODULES_VADDR.
 	 */
 	PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
 		KERNEL_MAPPING_SIZE/PMD_SIZE)
-- 
2.5.5

  parent reply	other threads:[~2017-02-02 12:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-02 12:54 [PATCH v4 0/3] " Baoquan He
2017-02-02 12:54 ` [PATCH v4 1/3] x86: Introduce a new constant KERNEL_MAPPING_SIZE Baoquan He
2017-02-14 17:32   ` Borislav Petkov
2017-02-26  4:09     ` Baoquan He
2017-03-03 11:43       ` Borislav Petkov
2017-03-03 12:06         ` Baoquan He
2017-03-03 12:16           ` Borislav Petkov
2017-03-03 12:52             ` Baoquan He
2017-03-03 13:11               ` Baoquan He
2017-03-03 14:28                 ` Borislav Petkov
2017-03-03 15:07                   ` Baoquan He
2017-03-03 15:08                     ` Baoquan He
2017-03-03 15:23                       ` Borislav Petkov
2017-03-04 10:10                         ` Baoquan He
2017-03-04 11:55                           ` Borislav Petkov
2017-03-04 13:59                             ` Baoquan He
2017-03-16  8:14                         ` Ingo Molnar
2017-03-16  9:44                           ` Baoquan He
2017-02-02 12:54 ` Baoquan He [this message]
2017-02-02 12:54 ` [PATCH v4 3/3] x86/64/doc: Update the ranges of kernel text and modules mapping Baoquan He
2017-02-02 19:40 ` [PATCH v4 0/3] x86/64/KASLR: Change kernel mapping size to 1G unconditionally Kees Cook
2017-03-04 14:26 ` Baoquan He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1486040077-3719-3-git-send-email-bhe@redhat.com \
    --to=bhe@redhat.com \
    --cc=anderson@redhat.com \
    --cc=bp@suse.de \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=kuleshovmail@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=thgarnie@google.com \
    --cc=x86@kernel.org \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome