Received: by 10.213.65.68 with SMTP id h4csp711404imn; Fri, 6 Apr 2018 07:40:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+jDwt+Fh4T6w5b2m4y54ilv+1Zr2ih7lgLK4n9pQRgEzQVjkRavYvQNE8GxW5qUF9usSFj X-Received: by 10.98.211.4 with SMTP id q4mr21052088pfg.0.1523025629802; Fri, 06 Apr 2018 07:40:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523025629; cv=none; d=google.com; s=arc-20160816; b=uATHashInQqfGq/gddGFlrQXfruMl1OA0gFT+JL8gsdPGstD/V2UpERLqfUYNbljn/ dqQtyXxlMgYvIVqVDd1dehkWiRq/+rRiXiT+3jG2SorM/LPsCsLjiKNyh1No4gPporqa s0bth2r2hprvt3t2Aus9m1/HlBo2jlfFC6ex4fnRD4S39CikMnM/GsKKG/qz54Fnfam4 ZDtWU2M2Guq0Ojq/yzIERfmzhfDQlN4AGiyFARO42ofqkKk+WJYoK0qzqW7su9DnKNnl 3+Hew/uxo4K0Uma4L6xRkQIcANa7HGZgv8qcO1op1EQCDwrx1jNVRi8bnphHY0aW3sKq CyrA== 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=+79lN+QtO3s5nak+3TAlcEb+nHykm9AxbCe/hNzrrcU=; b=n27bMnCort7emHTlJXHBah0suz21zBBFa9ruIDx+35Kf8FbkSGFWd07TutzYAgGClB BiSz5Ljl5SzXa5qW4/0AgqRL71HkX9Re0a/k6kz1h6fYpBFQJJsn9RGIPldN6x663Xqx Arogw/kUkqwgPSUsoeJ8NjZctLZ9mRiukoBtcw6QO830yJ7LjLUTfuUOd0oJ8s3GSA2I 2acrk3zDmqMxu7jU2Ob4XrCOZdewFGdyc2Bk2KXYT5o1AaaJhmnwXVd7JxCWsxNRpwRU m9UqeeF8sWADbECvxcupXWh8kmv+DuyOvMp0Q50rc4RdGAyi4f0+IiyQFap3pdBU9E6k ywyg== 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 v12-v6si8434413plk.615.2018.04.06.07.40.15; Fri, 06 Apr 2018 07:40:29 -0700 (PDT) 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 S1755962AbeDFNfC (ORCPT + 99 others); Fri, 6 Apr 2018 09:35:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58576 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755951AbeDFNe6 (ORCPT ); Fri, 6 Apr 2018 09:34:58 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B7490D85; Fri, 6 Apr 2018 13:34:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Mark Rutland , Laura Abbott , Shanker Donthineni , Will Deacon , Alex Shi , Greg Hackmann Subject: [PATCH 4.9 058/102] arm64: mm: Map entry trampoline into trampoline and kernel page tables Date: Fri, 6 Apr 2018 15:23:39 +0200 Message-Id: <20180406084339.761446888@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084331.507038179@linuxfoundation.org> References: <20180406084331.507038179@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon commit 51a0048beb44 upstream. The exception entry trampoline needs to be mapped at the same virtual address in both the trampoline page table (which maps nothing else) and also the kernel page table, so that we can swizzle TTBR1_EL1 on exceptions from and return to EL0. This patch maps the trampoline at a fixed virtual address in the fixmap area of the kernel virtual address space, which allows the kernel proper to be randomized with respect to the trampoline when KASLR is enabled. Reviewed-by: Mark Rutland Tested-by: Laura Abbott Tested-by: Shanker Donthineni Signed-off-by: Will Deacon Signed-off-by: Alex Shi Signed-off-by: Mark Rutland [v4.9 backport] Tested-by: Will Deacon Tested-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/fixmap.h | 5 +++++ arch/arm64/include/asm/pgtable.h | 1 + arch/arm64/kernel/asm-offsets.c | 6 +++++- arch/arm64/mm/mmu.c | 23 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -51,6 +51,11 @@ enum fixed_addresses { FIX_EARLYCON_MEM_BASE, FIX_TEXT_POKE0, + +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + FIX_ENTRY_TRAMP_TEXT, +#define TRAMP_VALIAS (__fix_to_virt(FIX_ENTRY_TRAMP_TEXT)) +#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ __end_of_permanent_fixed_addresses, /* --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -692,6 +692,7 @@ static inline void pmdp_set_wrprotect(st extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; extern pgd_t idmap_pg_dir[PTRS_PER_PGD]; +extern pgd_t tramp_pg_dir[PTRS_PER_PGD]; /* * Encode and decode a swap entry: --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -144,11 +145,14 @@ int main(void) DEFINE(ARM_SMCCC_RES_X2_OFFS, offsetof(struct arm_smccc_res, a2)); DEFINE(ARM_SMCCC_QUIRK_ID_OFFS, offsetof(struct arm_smccc_quirk, id)); DEFINE(ARM_SMCCC_QUIRK_STATE_OFFS, offsetof(struct arm_smccc_quirk, state)); - BLANK(); DEFINE(HIBERN_PBE_ORIG, offsetof(struct pbe, orig_address)); DEFINE(HIBERN_PBE_ADDR, offsetof(struct pbe, address)); DEFINE(HIBERN_PBE_NEXT, offsetof(struct pbe, next)); DEFINE(ARM64_FTR_SYSVAL, offsetof(struct arm64_ftr_reg, sys_val)); + BLANK(); +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + DEFINE(TRAMP_VALIAS, TRAMP_VALIAS); +#endif return 0; } --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -419,6 +419,29 @@ static void __init map_kernel_segment(pg vm_area_add_early(vma); } +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +static int __init map_entry_trampoline(void) +{ + extern char __entry_tramp_text_start[]; + + pgprot_t prot = rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; + phys_addr_t pa_start = __pa_symbol(__entry_tramp_text_start); + + /* The trampoline is always mapped and can therefore be global */ + pgprot_val(prot) &= ~PTE_NG; + + /* Map only the text into the trampoline page table */ + memset(tramp_pg_dir, 0, PGD_SIZE); + __create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS, PAGE_SIZE, + prot, pgd_pgtable_alloc, 0); + + /* ...as well as the kernel page table */ + __set_fixmap(FIX_ENTRY_TRAMP_TEXT, pa_start, prot); + return 0; +} +core_initcall(map_entry_trampoline); +#endif + /* * Create fine-grained mappings for the kernel. */