Received: by 10.223.185.116 with SMTP id b49csp476766wrg; Fri, 16 Feb 2018 02:07:05 -0800 (PST) X-Google-Smtp-Source: AH8x225zUEMQh3vk78t9C+hhuVsWwuEyCOwZLMghIjakw6shWdFnAxno30pQk1x0faitPJGZpAWb X-Received: by 2002:a17:902:b109:: with SMTP id q9-v6mr5479205plr.340.1518775625836; Fri, 16 Feb 2018 02:07:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518775625; cv=none; d=google.com; s=arc-20160816; b=QrbbbrtgRjPl/iGgAQUMXUZrqgyR87xC5n7sZjx5XrML9K1UAdETCBEPQsGTOI0UN4 616iVw9pUkUjd9YayF/FNiD6Pyk36wDyI+ed7VrT5NXA+kfBFybMPchncLqnONOjSVz3 MJyTEaEqBzYDyUurEZxpajlX5/AgxedPoGuLBXQ2ZnIeZIcmoJNIaz8D20nqiqe/FjsN RRawO8+PwQmLCAw+Wi40LSLRVsLo9sUfEb1OaUUKM9Uw/OBqUFjgHaSIYznNQjEc/xz4 mwQPZhhZoX8IIZm04g3XtgFqcBlbfhx9wSA9iRMxnNobLy8sfWTzhgLlQ+bLdfWCQyZS nUcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=8d48o6B1kQEOtzL61sO/XHYzme+7TUfgnE2OZgtjv3s=; b=yf0D5PkGIGT5w0Dw8AQOx6SnTPMy9K2hoQIafYAtL7r2kzREDF+5JoXBqhR9bVJ2w7 BKS0wOXIUKj10PXIcdvYrVA7E3sfCwwaaR6b3A7eujzphDhVPBlTMcO/rOP0FmGs7Xq8 RBK3ZHL4VvGtilM4GlwiJVZm+USb5ykyriMGoAAPz/IdNeLg9hKzVnDPsn6PZbZGQoBm AIjmFp+iDS/X6JS+7pIBLGKKHurc/nFd0KRPFsp7xl+jV1hRO0UswL4DOWxctQZSUBeo CF7y5DZaxsY0ydVhcXq4s3bmSzNRwe2pyyQlZWOJq4McrIDXhU7OnuGZMbOYv2mek/e6 a18A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9-v6si45688plt.293.2018.02.16.02.06.51; Fri, 16 Feb 2018 02:07:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426634AbeBOQyN (ORCPT + 99 others); Thu, 15 Feb 2018 11:54:13 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:59938 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423635AbeBOPj6 (ORCPT ); Thu, 15 Feb 2018 10:39:58 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 18DDB1113; Thu, 15 Feb 2018 15:39:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Laura Abbott , Shanker Donthineni , Will Deacon Subject: [PATCH 4.15 032/202] [Variant 3/Meltdown] arm64: kaslr: Put kernel vectors address in separate data page Date: Thu, 15 Feb 2018 16:15:32 +0100 Message-Id: <20180215151714.661239569@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon Commit 6c27c4082f4f upstream. The literal pool entry for identifying the vectors base is the only piece of information in the trampoline page that identifies the true location of the kernel. This patch moves it into a page-aligned region of the .rodata section and maps this adjacent to the trampoline text via an additional fixmap entry, which protects against any accidental leakage of the trampoline contents. Suggested-by: Ard Biesheuvel Tested-by: Laura Abbott Tested-by: Shanker Donthineni Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/fixmap.h | 1 + arch/arm64/kernel/entry.S | 14 ++++++++++++++ arch/arm64/kernel/vmlinux.lds.S | 5 ++++- arch/arm64/mm/mmu.c | 10 +++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -59,6 +59,7 @@ enum fixed_addresses { #endif /* CONFIG_ACPI_APEI_GHES */ #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + FIX_ENTRY_TRAMP_DATA, FIX_ENTRY_TRAMP_TEXT, #define TRAMP_VALIAS (__fix_to_virt(FIX_ENTRY_TRAMP_TEXT)) #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -1030,7 +1030,13 @@ alternative_else_nop_endif msr tpidrro_el0, x30 // Restored in kernel_ventry .endif tramp_map_kernel x30 +#ifdef CONFIG_RANDOMIZE_BASE + adr x30, tramp_vectors + PAGE_SIZE +alternative_insn isb, nop, ARM64_WORKAROUND_QCOM_FALKOR_E1003 + ldr x30, [x30] +#else ldr x30, =vectors +#endif prfm plil1strm, [x30, #(1b - tramp_vectors)] msr vbar_el1, x30 add x30, x30, #(1b - tramp_vectors) @@ -1073,6 +1079,14 @@ END(tramp_exit_compat) .ltorg .popsection // .entry.tramp.text +#ifdef CONFIG_RANDOMIZE_BASE + .pushsection ".rodata", "a" + .align PAGE_SHIFT + .globl __entry_tramp_data_start +__entry_tramp_data_start: + .quad vectors + .popsection // .rodata +#endif /* CONFIG_RANDOMIZE_BASE */ #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ /* --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -251,7 +251,10 @@ ASSERT(__idmap_text_end - (__idmap_text_ ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) <= SZ_4K, "Hibernate exit text too big or misaligned") #endif - +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, + "Entry trampoline text too big") +#endif /* * If padding is applied before .head.text, virt<->phys conversions will fail. */ --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -541,8 +541,16 @@ static int __init map_entry_trampoline(v __create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS, PAGE_SIZE, prot, pgd_pgtable_alloc, 0); - /* ...as well as the kernel page table */ + /* Map both the text and data into the kernel page table */ __set_fixmap(FIX_ENTRY_TRAMP_TEXT, pa_start, prot); + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { + extern char __entry_tramp_data_start[]; + + __set_fixmap(FIX_ENTRY_TRAMP_DATA, + __pa_symbol(__entry_tramp_data_start), + PAGE_KERNEL_RO); + } + return 0; } core_initcall(map_entry_trampoline);