From patchwork Thu May 31 10:31:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Yao X-Patchwork-Id: 10440637 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 DB400603B5 for ; Thu, 31 May 2018 10:31:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE6C829204 for ; Thu, 31 May 2018 10:31:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C291E29213; Thu, 31 May 2018 10:31:29 +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=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 E487A29212 for ; Thu, 31 May 2018 10:31:28 +0000 (UTC) Received: (qmail 10199 invoked by uid 550); 31 May 2018 10:31:26 -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 10128 invoked from network); 31 May 2018 10:31:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=2kY3bpBG5GrxcOPqM4cUzIE+rtlkpgkEZYFEaAFHYGk=; b=enl661FTMCE3ed2EL2O2PiD7miOL1VjEAsEIhzjQiV3CmXfLexNZM8UGSEqeS1v+a3 MU4iyX1/tT6aaNuK2QEiPvp2WYfgLngBbrB1yAlQUhvmt2cmkWbQN9jXuCjTVGWkQ7vy 8GhtgvQ218xBqbaFOvHFHntPQociPO8paYton3F/e3C2s1FmQ/EW2AL4EpquEaCB3eTo hY2/ol7s8SRdP61ossKKJgxvG06vA1nqeQsg9N7xcVEO+MJibA4N0nuNSjYyEbhI/2iN FqKXn9MJ49RL0sCGxtlHVPRUeyJLWeXimLtQFHAmUjHJ4ZtVsE/cBZCu+Cleh41pwiqM vpvA== 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=2kY3bpBG5GrxcOPqM4cUzIE+rtlkpgkEZYFEaAFHYGk=; b=hFPSOSPAkQnBXG/Nf6g9Ng+G3FbG3Z5aNE4f2ptZcSh8j16YFZll5CSSSOq1TfGMfQ Ru0zsrQHtcDV7+8QIF9ySZ3sdncZiznniYIpuYTP34cOrQDyOZ4bvgt8t+bglY0ah26n OZQ2aMbm3NYy4O2RNgm6dqdQsNgbojD0ehjaNS8CpOOEeLAFMuGbi2YWJyxF5F27smmR b5wQ7bPlSKwEdJWpzoz5ZzhZSFSNrynxr0rgXPU/2l1mdDNEdNjHXc/NPI2BKjkrNztf 2APNcrS31fdDJyzkEw9aY8nZ4bvXaVJLcMI1NTqlLu+v9yqSq0GN0wU/zhzpE5iXdxkW 6VMg== X-Gm-Message-State: ALKqPweUmX1YswAYK01JNDwycWa+QHDNmhN4cqBKi+Ovk7uZxckZiOXU ReTm2YfTrjYERbtiqp9208s= X-Google-Smtp-Source: ADUXVKIDWxtL8G74EBO+Trjx97r1A1R7QlIqqVrzUw2UmoyhNHQtDFz3Cp19oMwSH/4JjLn4wRy6YQ== X-Received: by 2002:a17:902:1e3:: with SMTP id b90-v6mr6251778plb.273.1527762674007; Thu, 31 May 2018 03:31:14 -0700 (PDT) From: Jun Yao To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: [PATCH v2 1/2] arm64/mm: split tramp_pg_dir off from the data segment Date: Thu, 31 May 2018 18:31:06 +0800 Message-Id: <20180531103106.31740-1-yaojun8558363@gmail.com> X-Mailer: git-send-email 2.17.0 X-Virus-Scanned: ClamAV using ClamSMTP In order to make tramp_pg_dir read-only, split it off from the data segment and create a dedicated pgdir segment for it. Signed-off-by: Jun Yao --- arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/vmlinux.lds.S | 3 +++ arch/arm64/mm/mmu.c | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h index caab039d6305..46a6646e886b 100644 --- a/arch/arm64/include/asm/sections.h +++ b/arch/arm64/include/asm/sections.h @@ -29,5 +29,6 @@ extern char __inittext_begin[], __inittext_end[]; extern char __irqentry_text_start[], __irqentry_text_end[]; extern char __mmuoff_data_start[], __mmuoff_data_end[]; extern char __entry_tramp_text_start[], __entry_tramp_text_end[]; +extern char __tramp_pgdir_segment_start[], __tramp_pgdir_segment_end[]; #endif /* __ASM_SECTIONS_H */ diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 605d1b60469c..c3368782171d 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -220,8 +220,11 @@ SECTIONS . += IDMAP_DIR_SIZE; #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + . = ALIGN(SEGMENT_ALIGN); + __tramp_pgdir_segment_start = .; tramp_pg_dir = .; . += PAGE_SIZE; + __tramp_pgdir_segment_end = .; #endif #ifdef CONFIG_ARM64_SW_TTBR0_PAN diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 2dbb2c9f1ec1..a675fb88914e 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -573,6 +573,9 @@ static void __init map_kernel(pgd_t *pgdp) { static struct vm_struct vmlinux_text, vmlinux_rodata, vmlinux_inittext, vmlinux_initdata, vmlinux_data; +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + static struct vm_struct vmlinux_tramp_pgdir, vmlinux_data_end; +#endif /* * External debuggers may need to write directly to the text @@ -593,7 +596,17 @@ static void __init map_kernel(pgd_t *pgdp) &vmlinux_inittext, 0, VM_NO_GUARD); map_kernel_segment(pgdp, __initdata_begin, __initdata_end, PAGE_KERNEL, &vmlinux_initdata, 0, VM_NO_GUARD); +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + map_kernel_segment(pgdp, _data, __tramp_pgdir_segment_start, + PAGE_KERNEL, &vmlinux_data, 0, VM_NO_GUARD); + map_kernel_segment(pgdp, __tramp_pgdir_segment_start, + __tramp_pgdir_segment_end, PAGE_KERNEL, + &vmlinux_tramp_pgdir, NO_CONT_MAPPINGS, VM_NO_GUARD); + map_kernel_segment(pgdp, __tramp_pgdir_segment_end, _end, PAGE_KERNEL, + &vmlinux_data_end, 0, 0); +#else map_kernel_segment(pgdp, _data, _end, PAGE_KERNEL, &vmlinux_data, 0, 0); +#endif if (!READ_ONCE(pgd_val(*pgd_offset_raw(pgdp, FIXADDR_START)))) { /*