All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Garnier <thgarnie@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Borislav Petkov <bp@suse.de>, Joerg Roedel <jroedel@suse.de>,
	Dave Young <dyoung@redhat.com>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Lv Zheng <lv.zheng@intel.com>,
	Thomas Garnier <thgarnie@google.com>, Baoquan He <bhe@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Mark Salter <msalter@redhat.com>,
	Aleksey Makarov <aleksey.makarov@linaro.org>,
	Kees Cook <keescook@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Fabian Frederick <fabf@skynet.be>, Toshi Kani <toshi.kani@hp.com>,
	Dan Williams <dan.j.williams@intel.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	kernel-hardening@lists.openwall.com
Subject: [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization
Date: Mon,  8 Aug 2016 11:40:06 -0700	[thread overview]
Message-ID: <1470681607-36883-1-git-send-email-thgarnie@google.com> (raw)

Initialize KASLR memory randomization after max_pfn is initialized. Also
ensure the size is rounded up. Could have create problems on machines
with more than 1Tb of memory on certain random addresses.

Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
Based on next-20160805
---
 arch/x86/kernel/setup.c | 4 ++--
 arch/x86/mm/kaslr.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index bcabb88..8dda0ce 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -936,8 +936,6 @@ void __init setup_arch(char **cmdline_p)
 
 	x86_init.oem.arch_setup();
 
-	kernel_randomize_memory();
-
 	iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
 	setup_memory_map();
 	parse_setup_data();
@@ -1071,6 +1069,8 @@ void __init setup_arch(char **cmdline_p)
 	high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
 #endif
 
+	kernel_randomize_memory();
+
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 26dccd6..ec8654f 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -97,7 +97,7 @@ void __init kernel_randomize_memory(void)
 	 * add padding if needed (especially for memory hotplug support).
 	 */
 	BUG_ON(kaslr_regions[0].base != &page_offset_base);
-	memory_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) +
+	memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) +
 		CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
 
 	/* Adapt phyiscal memory region size based on available memory */
-- 
2.8.0.rc3.226.g39d4020

WARNING: multiple messages have this Message-ID (diff)
From: Thomas Garnier <thgarnie@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Borislav Petkov <bp@suse.de>, Joerg Roedel <jroedel@suse.de>,
	Dave Young <dyoung@redhat.com>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Lv Zheng <lv.zheng@intel.com>,
	Thomas Garnier <thgarnie@google.com>, Baoquan He <bhe@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Mark Salter <msalter@redhat.com>,
	Aleksey Makarov <aleksey.makarov@linaro.org>,
	Kees Cook <keescook@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Fabian Frederick <fabf@skynet.be>, Toshi Kani <toshi.kani@hp.com>,
	Dan Williams <dan.j.williams@intel.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	kernel-hardening@lists.openwall.com
Subject: [kernel-hardening] [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization
Date: Mon,  8 Aug 2016 11:40:06 -0700	[thread overview]
Message-ID: <1470681607-36883-1-git-send-email-thgarnie@google.com> (raw)

Initialize KASLR memory randomization after max_pfn is initialized. Also
ensure the size is rounded up. Could have create problems on machines
with more than 1Tb of memory on certain random addresses.

Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
Based on next-20160805
---
 arch/x86/kernel/setup.c | 4 ++--
 arch/x86/mm/kaslr.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index bcabb88..8dda0ce 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -936,8 +936,6 @@ void __init setup_arch(char **cmdline_p)
 
 	x86_init.oem.arch_setup();
 
-	kernel_randomize_memory();
-
 	iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
 	setup_memory_map();
 	parse_setup_data();
@@ -1071,6 +1069,8 @@ void __init setup_arch(char **cmdline_p)
 	high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
 #endif
 
+	kernel_randomize_memory();
+
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 26dccd6..ec8654f 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -97,7 +97,7 @@ void __init kernel_randomize_memory(void)
 	 * add padding if needed (especially for memory hotplug support).
 	 */
 	BUG_ON(kaslr_regions[0].base != &page_offset_base);
-	memory_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) +
+	memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) +
 		CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
 
 	/* Adapt phyiscal memory region size based on available memory */
-- 
2.8.0.rc3.226.g39d4020

             reply	other threads:[~2016-08-08 18:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-08 18:40 Thomas Garnier [this message]
2016-08-08 18:40 ` [kernel-hardening] [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier
2016-08-08 18:40 ` [PATCH v1 2/2] x86/KASLR: Increase BRK pages for " Thomas Garnier
2016-08-08 18:40   ` [kernel-hardening] " Thomas Garnier
2016-08-09  4:01   ` Borislav Petkov
2016-08-09  4:01     ` [kernel-hardening] " Borislav Petkov
2016-08-09  4:14     ` H. Peter Anvin
2016-08-09  4:14       ` [kernel-hardening] " H. Peter Anvin
2016-08-09  5:16   ` Mika Penttilä
2016-08-09  5:16     ` [kernel-hardening] " Mika Penttilä
2016-08-09 14:47     ` Thomas Garnier
2016-08-09 14:47       ` [kernel-hardening] " Thomas Garnier
2016-08-09 15:07 ` [lkp] [x86/KASLR] 20067c4c13: kernel BUG at arch/x86/mm/physaddr.c:26! kernel test robot
2016-08-09 15:07   ` [kernel-hardening] " kernel test robot
2016-08-09 16:00 ` [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier
2016-08-09 16:00   ` [kernel-hardening] " Thomas Garnier
2016-08-09 16:03   ` Joerg Roedel
2016-08-09 16:03     ` [kernel-hardening] " Joerg Roedel
2016-08-09 16:30     ` Thomas Garnier
2016-08-09 16:30       ` [kernel-hardening] " Thomas Garnier

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=1470681607-36883-1-git-send-email-thgarnie@google.com \
    --to=thgarnie@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=aleksey.makarov@linaro.org \
    --cc=bhe@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=bp@suse.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dyoung@redhat.com \
    --cc=fabf@skynet.be \
    --cc=hpa@zytor.com \
    --cc=jroedel@suse.de \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lv.zheng@intel.com \
    --cc=mingo@redhat.com \
    --cc=msalter@redhat.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=tglx@linutronix.de \
    --cc=toshi.kani@hp.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 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.