Skip to content

Commit fb754f9

Browse files
thgarnieIngo Molnar
authored andcommitted
x86/mm/KASLR: Increase BRK pages for KASLR memory randomization
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. Signed-off-by: Thomas Garnier <thgarnie@google.com> Cc: Aleksey Makarov <aleksey.makarov@linaro.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Baoquan He <bhe@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Borislav Petkov <bp@suse.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dave Young <dyoung@redhat.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Fabian Frederick <fabf@skynet.be> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Joerg Roedel <jroedel@suse.de> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Lv Zheng <lv.zheng@intel.com> Cc: Mark Salter <msalter@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Toshi Kani <toshi.kani@hp.com> Cc: kernel-hardening@lists.openwall.com Fixes: 021182e ("Enable KASLR for physical mapping memory regions") Link: http://lkml.kernel.org/r/1470762665-88032-2-git-send-email-thgarnie@google.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent c7d2361 commit fb754f9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/x86/mm/init.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,18 @@ __ref void *alloc_low_pages(unsigned int num)
122122
return __va(pfn << PAGE_SHIFT);
123123
}
124124

125-
/* need 3 4k for initial PMD_SIZE, 3 4k for 0-ISA_END_ADDRESS */
126-
#define INIT_PGT_BUF_SIZE (6 * PAGE_SIZE)
125+
/*
126+
* By default need 3 4k for initial PMD_SIZE, 3 4k for 0-ISA_END_ADDRESS.
127+
* With KASLR memory randomization, depending on the machine e820 memory
128+
* and the PUD alignment. We may need twice more pages when KASLR memory
129+
* randomization is enabled.
130+
*/
131+
#ifndef CONFIG_RANDOMIZE_MEMORY
132+
#define INIT_PGD_PAGE_COUNT 6
133+
#else
134+
#define INIT_PGD_PAGE_COUNT 12
135+
#endif
136+
#define INIT_PGT_BUF_SIZE (INIT_PGD_PAGE_COUNT * PAGE_SIZE)
127137
RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);
128138
void __init early_alloc_pgt_buf(void)
129139
{

0 commit comments

Comments
 (0)