From patchwork Mon Aug 8 18:40:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9269137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 83CAB60839 for ; Mon, 8 Aug 2016 18:40:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7566527F95 for ; Mon, 8 Aug 2016 18:40:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69A772815E; Mon, 8 Aug 2016 18:40:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id A016827F95 for ; Mon, 8 Aug 2016 18:40:52 +0000 (UTC) Received: (qmail 11885 invoked by uid 550); 8 Aug 2016 18:40:49 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: kernel-hardening@lists.openwall.com Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 11666 invoked from network); 8 Aug 2016 18:40:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Iw5w6N2RwRGnusC31Ul35xCACLLRGTeQ/BLZbUvCM04=; b=c1EWpExWk3S0yHGIuaYVch9owYBwSPSt5n2mKnyuyg3MrpqbOl+Nqo2geaTSog924p NbEw3zV//Dhjuq2l/ko4cok/45K0fzDBA41jS06eg1r9CoBVgT7P1FbqHrfk6nUAr7t9 R0mFTlvH4dOvPt+u/BhlcJidS+k9NeV3suFrb5ZUOl1k0yRsSznI+M+13RnQcgh5XFvC P4SIVCgN+ULUvvtzOSWRrWRNmHbqXXM0v9wEefRYEmXxrT/5lpDaI3f7oXppZ4Kc5nym Q+aTVQ7lK56qCHCS+YZplDVElkQ7lnlINV03G7j6w+a1Am3CRuhuNFHU1UKD4eJXCcae 7Tog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Iw5w6N2RwRGnusC31Ul35xCACLLRGTeQ/BLZbUvCM04=; b=EqDGFExJE2f/XkcdOEAT2rxH2eVVBItY+xlS0F/DqTiFuHm0eHCxbNtA5Q0Tnej0YL oL09HLuAGe+mJA8V/duZVa7RXudlG7HBBErwydnjiuNMW7E077mFycHBsWdB3lRTnl5H 45tCCVfk7GjmHtNnXc4COhHFKMoU0iRBwnqh3pXioLp+NKSbWVBtAm2Qcbx4syVj8RVo dhpsxl/Fy6xncxHUyiil2BqlplJRbphw2PTypm1xt0NPdE8lP9EdOaQlgwXPaaWKk45C 4eHf4+kebejFkawONsMoiQzp7Tru4ZMC9fybW23S44sErzb7D60+5JA7eWU50SlHHiHV pMbw== X-Gm-Message-State: AEkoouvnoiUj65vuL/nre7OI4kN+LYu12yfB5hfNGZgTb0u2m5aj6nHfitgnX5H7MFAbYdAn X-Received: by 10.67.7.229 with SMTP id df5mr14819465pad.6.1470681636163; Mon, 08 Aug 2016 11:40:36 -0700 (PDT) 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 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> Subject: [kernel-hardening] [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization X-Virus-Scanned: ClamAV using ClamSMTP 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;