From: Thomas Garnier <thgarnie@google.com>
To: "H . Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@suse.de>,
Andy Lutomirski <luto@kernel.org>,
Thomas Garnier <thgarnie@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Dan Williams <dan.j.williams@intel.com>,
Kees Cook <keescook@chromium.org>,
Stephen Smalley <sds@tycho.nsa.gov>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Jonathan Corbet <corbet@lwn.net>,
Matt Fleming <matt@codeblueprint.co.uk>,
Toshi Kani <toshi.kani@hpe.com>,
Alexander Kuleshov <kuleshovmail@gmail.com>,
Alexander Popov <alpopov@ptsecurity.com>,
Joerg Roedel <jroedel@suse.de>, Dave Young <dyoung@redhat.com>,
Baoquan He <bhe@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Mark Salter <msalter@redhat.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, gthelen@google.com,
kernel-hardening@lists.openwall.com
Subject: [PATCH 4/4] x86, boot: Memory hotplug support for KASLR memory randomization
Date: Mon, 25 Apr 2016 09:37:13 -0700 [thread overview]
Message-ID: <1461602233-67310-5-git-send-email-thgarnie@google.com> (raw)
In-Reply-To: <1461602233-67310-1-git-send-email-thgarnie@google.com>
Add a new option (CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING) to define
the padding used for the physical memory mapping section when KASLR
memory is enabled. It ensures there is enough virtual address space when
CONFIG_MEMORY_HOTPLUG is used. The default value is 10 terabytes. If
CONFIG_MEMORY_HOTPLUG is not used, no space is reserved increasing the
entropy available.
Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
Based on next-20160422
---
arch/x86/Kconfig | 15 +++++++++++++++
arch/x86/mm/kaslr.c | 14 ++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 7c786d4..cc01b69 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2018,6 +2018,21 @@ config RANDOMIZE_MEMORY
If unsure, say N.
+config RANDOMIZE_MEMORY_PHYSICAL_PADDING
+ hex "Physical memory mapping padding" if EXPERT
+ depends on RANDOMIZE_MEMORY
+ default "0xa" if MEMORY_HOTPLUG
+ default "0x0"
+ range 0x1 0x40 if MEMORY_HOTPLUG
+ range 0x0 0x40
+ ---help---
+ Define the padding in terabyte added to the existing physical memory
+ size during kernel memory randomization. It is useful for memory
+ hotplug support but reduces the entropy available for address
+ randomization.
+
+ If unsure, leave at the default value.
+
config HOTPLUG_CPU
bool "Support for hot-pluggable CPUs"
depends on SMP
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 3b330a9..ef3dc19 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -68,15 +68,25 @@ void __init kernel_randomize_memory(void)
{
size_t i;
unsigned long addr = memory_rand_start;
- unsigned long padding, rand, mem_tb;
+ unsigned long padding, rand, mem_tb, page_offset_padding;
struct rnd_state rnd_st;
unsigned long remain_padding = memory_rand_end - memory_rand_start;
if (!kaslr_enabled())
return;
+ /*
+ * Update Physical memory mapping to available and
+ * add padding if needed (especially for memory hotplug support).
+ */
+ page_offset_padding = CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
+
+#ifdef CONFIG_MEMORY_HOTPLUG
+ page_offset_padding = max(1UL, page_offset_padding);
+#endif
+
BUG_ON(kaslr_regions[0].base != &page_offset_base);
- mem_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT);
+ mem_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) + page_offset_padding;
if (mem_tb < kaslr_regions[0].size_tb)
kaslr_regions[0].size_tb = mem_tb;
--
2.8.0.rc3.226.g39d4020
prev parent reply other threads:[~2016-04-25 16:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-25 16:37 Thomas Garnier
2016-04-25 16:37 ` [PATCH 1/4] x86, boot: Refactor KASLR entropy functions Thomas Garnier
2016-04-25 16:37 ` [PATCH 2/4] x86, boot: PUD VA support for physical mapping (x86_64) Thomas Garnier
2016-04-25 16:37 ` [PATCH 3/4] x86, boot: Implement ASLR for kernel memory sections (x86_64) Thomas Garnier
2016-04-25 16:37 ` Thomas Garnier [this message]
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=1461602233-67310-5-git-send-email-thgarnie@google.com \
--to=thgarnie@google.com \
--cc=alpopov@ptsecurity.com \
--cc=bhe@redhat.com \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@suse.de \
--cc=corbet@lwn.net \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dvyukov@google.com \
--cc=dyoung@redhat.com \
--cc=gthelen@google.com \
--cc=hpa@zytor.com \
--cc=jroedel@suse.de \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=kuleshovmail@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=matt@codeblueprint.co.uk \
--cc=mingo@redhat.com \
--cc=msalter@redhat.com \
--cc=pbonzini@redhat.com \
--cc=sds@tycho.nsa.gov \
--cc=tglx@linutronix.de \
--cc=toshi.kani@hpe.com \
--cc=wangkefeng.wang@huawei.com \
--cc=x86@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;
as well as URLs for NNTP newsgroup(s).