From patchwork Thu Jan 26 16:59:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9539789 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 A64C2604A0 for ; Thu, 26 Jan 2017 17:00:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99E7F26B39 for ; Thu, 26 Jan 2017 17:00:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AC672824F; Thu, 26 Jan 2017 17:00:02 +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 18FEE26B39 for ; Thu, 26 Jan 2017 17:00:00 +0000 (UTC) Received: (qmail 28392 invoked by uid 550); 26 Jan 2017 16:59:58 -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: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 28365 invoked from network); 26 Jan 2017 16:59:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=VPdHxhUXfPNs8juYRqnFFm8/F20wvkC0cFS2a7K9VoM=; b=if9DRAvp2lTwg8At2FNPcOp+rqYFR3cvBTpTgPy94oxEyCbAUksAJZhaJJ1IXDIaeG dmtt48Mj7RWsdca0Io5ZMBmBsD1RynGTI/EY0SdFcJCXoW3agXe/YOW1/sXH/o8o4IYy 2bBqlvN8bm3uAsIaFxOIBNaz64TxpA6LYsI6ScqfEHJdx1FVKWw6eHi50SYPKNbJo2dW vT4BdT5KbeYDSZkwaMeKOivEnA7RdObs4vGYjK2kgv5LQTg91KOz+ww3JohYlVVkeNxG jwcqF6610oMD85MyeTKDC+5geH8iQXxjqlj0XT3HSiUtzDk8VrrxaS/VzWiOMpxV3/ZZ 7Xqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VPdHxhUXfPNs8juYRqnFFm8/F20wvkC0cFS2a7K9VoM=; b=KSJzpZ/gsOpc90qD2BW1XeR4l4ExQOJBXVNiHMmbp5tsxtlmmB02OOjLPlRvFB5g6W 80zNzn3TA9yZBOJ3RYn0utsJuESTl3SwNpQbo86/tayQ7vXnS6dJDJ3Qe/I3Z1KnznUy QPYuxI8IVwPeFKmmd5/xbu0JYle+JAb32c/Ngpsmh3bUIJjE+lfliKV9qsC/HXIvos5h nU+O6QXLdEL8CXQaRn8zjSvViZQmIl/Tmoz2QQafrf40HxaTm7N2BSqTT040d3N9inHp CzcPITvJfRhUVsa/d5tHDhNN9JCXAtpT1/nPXMHdoODBdC8WvIwogKjcgLCoOi6q6FRZ 87Yw== X-Gm-Message-State: AIkVDXI3JWX4nHsmueomrJv9BYslKMKTi5SN0o/4cAFJscG/UDysmwXtSkzuneLsxoGJwJvj X-Received: by 10.84.168.131 with SMTP id f3mr5517907plb.163.1485449985951; Thu, 26 Jan 2017 08:59:45 -0800 (PST) From: Thomas Garnier To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Thomas Garnier , Kees Cook , Andy Lutomirski , Arjan van de Ven , Paul Gortmaker , Borislav Petkov , Andy Lutomirski , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Jiri Kosina , Matt Fleming , Ard Biesheuvel , Boris Ostrovsky , Juergen Gross , Rusty Russell , Christian Borntraeger , Fenghua Yu , He Chen , Brian Gerst , "Luis R . Rodriguez" , Adam Buchbinder , Stanislaw Gruszka , Arnd Bergmann , Dave Hansen , Chen Yucong , Vitaly Kuznetsov , David Vrabel , Josh Poimboeuf , Tim Chen , Rik van Riel , Andi Kleen , Jiri Olsa , Prarit Bhargava , Michael Ellerman , Joerg Roedel , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-pm@vger.kernel.org, linux-efi@vger.kernel.org, xen-devel@lists.xenproject.org, lguest@lists.ozlabs.org, kvm@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Thu, 26 Jan 2017 08:59:38 -0800 Message-Id: <20170126165940.30799-1-thgarnie@google.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog Subject: [kernel-hardening] [PATCH v2 1/3] x86/mm: Adapt MODULES_END based on Fixmap section size X-Virus-Scanned: ClamAV using ClamSMTP This patch aligns MODULES_END to the beginning of the Fixmap section. It optimizes the space available for both sections. The address is pre-computed based on the number of pages required by the Fixmap section. It will allow GDT remapping in the Fixmap section. The current MODULES_END static address does not provide enough space for the kernel to support a large number of processors. Signed-off-by: Thomas Garnier --- Based on next-20170125 --- arch/x86/include/asm/fixmap.h | 8 ++++++++ arch/x86/include/asm/pgtable_64_types.h | 3 --- arch/x86/kernel/module.c | 1 + arch/x86/mm/dump_pagetables.c | 1 + arch/x86/mm/kasan_init_64.c | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h index 8554f960e21b..c46289799b02 100644 --- a/arch/x86/include/asm/fixmap.h +++ b/arch/x86/include/asm/fixmap.h @@ -132,6 +132,14 @@ enum fixed_addresses { extern void reserve_top_address(unsigned long reserve); +/* On 64bit, the module sections ends with the start of the fixmap */ +#ifdef CONFIG_X86_64 +#define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE) +#define MODULES_END __fix_to_virt(__end_of_fixed_addresses + 1) +#define MODULES_LEN (MODULES_END - MODULES_VADDR) +#endif /* CONFIG_X86_64 */ + + #define FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT) #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE) diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h index 3a264200c62f..de8bace10200 100644 --- a/arch/x86/include/asm/pgtable_64_types.h +++ b/arch/x86/include/asm/pgtable_64_types.h @@ -66,9 +66,6 @@ typedef struct { pteval_t pte; } pte_t; #define VMEMMAP_START __VMEMMAP_BASE #endif /* CONFIG_RANDOMIZE_MEMORY */ #define VMALLOC_END (VMALLOC_START + _AC((VMALLOC_SIZE_TB << 40) - 1, UL)) -#define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE) -#define MODULES_END _AC(0xffffffffff000000, UL) -#define MODULES_LEN (MODULES_END - MODULES_VADDR) #define ESPFIX_PGD_ENTRY _AC(-2, UL) #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT) #define EFI_VA_START ( -4 * (_AC(1, UL) << 30)) diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 477ae806c2fa..fad61caac75e 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -35,6 +35,7 @@ #include #include #include +#include #if 0 #define DEBUGP(fmt, ...) \ diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index ea9c49adaa1f..eefd6d015d02 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -18,6 +18,7 @@ #include #include +#include /* * The dumper groups pagetable entries of the same type into one, and for diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c index 0493c17b8a51..34f167cf3316 100644 --- a/arch/x86/mm/kasan_init_64.c +++ b/arch/x86/mm/kasan_init_64.c @@ -8,6 +8,7 @@ #include #include +#include extern pgd_t early_level4_pgt[PTRS_PER_PGD]; extern struct range pfn_mapped[E820_X_MAX];