From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752541AbcHHSkt (ORCPT ); Mon, 8 Aug 2016 14:40:49 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:35741 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752214AbcHHSkh (ORCPT ); Mon, 8 Aug 2016 14:40:37 -0400 From: Thomas Garnier To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Borislav Petkov , Joerg Roedel , Dave Young , "Rafael J . Wysocki" , Lv Zheng , Thomas Garnier , Baoquan He , Dave Hansen , Mark Salter , Aleksey Makarov , Kees Cook , Andrew Morton , Christian Borntraeger , Fabian Frederick , Toshi Kani , Dan Williams Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization Date: Mon, 8 Aug 2016 11:40:07 -0700 Message-Id: <1470681607-36883-2-git-send-email-thgarnie@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1470681607-36883-1-git-send-email-thgarnie@google.com> References: <1470681607-36883-1-git-send-email-thgarnie@google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Based on next-20160805 --- arch/x86/mm/init.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 6209289..3a27e6a 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -130,6 +130,14 @@ void __init early_alloc_pgt_buf(void) unsigned long tables = INIT_PGT_BUF_SIZE; phys_addr_t base; + /* + * Depending on the machine e860 memory layout and the PUD alignement. + * We may need twice more pages when KASLR memoy randomization is + * enabled. + */ + if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY)) + tables *= 2; + base = __pa(extend_brk(tables, PAGE_SIZE)); pgt_buf_start = base >> PAGE_SHIFT; -- 2.8.0.rc3.226.g39d4020