From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752737AbcFZLET (ORCPT ); Sun, 26 Jun 2016 07:04:19 -0400 Received: from terminus.zytor.com ([198.137.202.10]:51728 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752047AbcFZLER (ORCPT ); Sun, 26 Jun 2016 07:04:17 -0400 Date: Sun, 26 Jun 2016 04:03:22 -0700 From: tip-bot for Yinghai Lu Message-ID: Cc: keescook@chromium.org, akpm@linux-foundation.org, aryabinin@virtuozzo.com, bhe@redhat.com, hpa@zytor.com, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, jpoimboe@redhat.com, peterz@infradead.org, dvyukov@google.com, hjl.tools@gmail.com, brgerst@gmail.com, bp@alien8.de, yinghai@kernel.org, linux-kernel@vger.kernel.org, luto@kernel.org, dvlasenk@redhat.com Reply-To: dvlasenk@redhat.com, linux-kernel@vger.kernel.org, luto@kernel.org, yinghai@kernel.org, bp@alien8.de, peterz@infradead.org, dvyukov@google.com, brgerst@gmail.com, hjl.tools@gmail.com, jpoimboe@redhat.com, mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com, torvalds@linux-foundation.org, bhe@redhat.com, aryabinin@virtuozzo.com, akpm@linux-foundation.org, keescook@chromium.org In-Reply-To: <1464216334-17200-6-git-send-email-keescook@chromium.org> References: <1464216334-17200-6-git-send-email-keescook@chromium.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/boot] x86/KASLR: Allow randomization below the load address Git-Commit-ID: e066cc47776a89bbdaf4184c0e75f7d389f9ab48 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: e066cc47776a89bbdaf4184c0e75f7d389f9ab48 Gitweb: http://git.kernel.org/tip/e066cc47776a89bbdaf4184c0e75f7d389f9ab48 Author: Yinghai Lu AuthorDate: Wed, 25 May 2016 15:45:34 -0700 Committer: Ingo Molnar CommitDate: Sun, 26 Jun 2016 12:32:05 +0200 x86/KASLR: Allow randomization below the load address Currently the kernel image physical address randomization's lower boundary is the original kernel load address. For bootloaders that load kernels into very high memory (e.g. kexec), this means randomization takes place in a very small window at the top of memory, ignoring the large region of physical memory below the load address. Since mem_avoid[] is already correctly tracking the regions that must be avoided, this patch changes the minimum address to whatever is less: 512M (to conservatively avoid unknown things in lower memory) or the load address. Now, for example, if the kernel is loaded at 8G, [512M, 8G) will be added to the list of possible physical memory positions. Signed-off-by: Yinghai Lu [ Rewrote the changelog, refactored the code to use min(). ] Signed-off-by: Kees Cook Cc: Andrew Morton Cc: Andrey Ryabinin Cc: Andy Lutomirski Cc: Baoquan He Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: Dmitry Vyukov Cc: H. Peter Anvin Cc: H.J. Lu Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1464216334-17200-6-git-send-email-keescook@chromium.org [ Edited the changelog some more, plus the code comment as well. ] Signed-off-by: Ingo Molnar --- arch/x86/boot/compressed/kaslr.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 36e2811..749c9e0 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -492,7 +492,7 @@ void choose_random_location(unsigned long input, unsigned long output_size, unsigned long *virt_addr) { - unsigned long random_addr; + unsigned long random_addr, min_addr; /* By default, keep output position unchanged. */ *virt_addr = *output; @@ -510,8 +510,15 @@ void choose_random_location(unsigned long input, /* Record the various known unsafe memory ranges. */ mem_avoid_init(input, input_size, *output); + /* + * Low end of the randomization range should be the + * smaller of 512M or the initial kernel image + * location: + */ + min_addr = min(*output, 512UL << 20); + /* Walk e820 and find a random address. */ - random_addr = find_random_phys_addr(*output, output_size); + random_addr = find_random_phys_addr(min_addr, output_size); if (!random_addr) { warn("KASLR disabled: could not find suitable E820 region!"); } else {