Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1458947

[PATCH v2 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

From Thomas Garnier <thgarnie@google.com>
Newsgroups linux.kernel
Subject [PATCH v2 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization
Date 2016-08-09 18:40 +0200
Message-ID <s4ien-1Aq-87@gated-at.bofh.it> (permalink)
References <s4ien-1Aq-79@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Default implementation expects 6 pages maximum are needed for low page
allocations. If KASLR memory randomization is enabled, the worse case
of e820 layout would require 12 pages (no large pages). It is due to the
PUD level randomization and the variable e820 memory layout.

This bug was found while doing extensive testing of KASLR memory
randomization on different type of hardware.

Fixes: 021182e52fe0 ("Enable KASLR for physical mapping memory regions")
Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
Based on next-20160805
---
 arch/x86/mm/init.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 6209289..796e7af 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -122,8 +122,18 @@ __ref void *alloc_low_pages(unsigned int num)
 	return __va(pfn << PAGE_SHIFT);
 }
 
-/* need 3 4k for initial PMD_SIZE,  3 4k for 0-ISA_END_ADDRESS */
-#define INIT_PGT_BUF_SIZE	(6 * PAGE_SIZE)
+/*
+ * By default need 3 4k for initial PMD_SIZE,  3 4k for 0-ISA_END_ADDRESS.
+ * With KASLR memory randomization, depending on the machine e860 memory layout
+ * and the PUD alignement. We may need twice more pages when KASLR memoy
+ * randomization is enabled.
+ */
+#ifndef CONFIG_RANDOMIZE_MEMORY
+#define INIT_PGD_PAGE_COUNT      6
+#else
+#define INIT_PGD_PAGE_COUNT      12
+#endif
+#define INIT_PGT_BUF_SIZE	(INIT_PGD_PAGE_COUNT * PAGE_SIZE)
 RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);
 void  __init early_alloc_pgt_buf(void)
 {
-- 
2.8.0.rc3.226.g39d4020

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-09 18:40 +0200
  [PATCH v2 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-09 18:40 +0200
    Re: [PATCH v2 2/2] x86/KASLR: Increase BRK pages for KASLR memory  randomization Borislav Petkov <bp@suse.de> - 2016-08-09 19:00 +0200
      Re: [PATCH v2 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-09 19:10 +0200

csiph-web