From patchwork Sun Feb 19 10:04:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hoeun Ryu X-Patchwork-Id: 9581535 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 70C72604A0 for ; Sun, 19 Feb 2017 10:06:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62DED28516 for ; Sun, 19 Feb 2017 10:06:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5714728734; Sun, 19 Feb 2017 10:06:20 +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, FREEMAIL_FROM, 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 5EE0B2872C for ; Sun, 19 Feb 2017 10:06:19 +0000 (UTC) Received: (qmail 24297 invoked by uid 550); 19 Feb 2017 10:06:17 -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 24273 invoked from network); 19 Feb 2017 10:06:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aXtUF/RgxHYBYTXTC5C3r38AEFCPGg91HPc6LqCwOpM=; b=uMRQG1iCXv+K24fUkM2IaLr+pLgyKnk0eMHxDrurvukWh2e/LvLP5KlHFlv6TRvr7v ydDSK5mfP2ZHNdjImq9hCyGwt2FhAmImxIBPPGjEntSmn/mLFEJt3zb64PLlAClF8Dgn P9j6hirwXpaAZoRu1Vr1cg9J6K+WZya0iUh3qxvlbTtgAtucpYjnoVEVpE3rD6Cbier2 6ohJfbML9pO18QUKAthkSCoiM32n32nBbjhjz9ogEqkVfRVikPi7LXxagdjeIVloawuz Ph91UkB+15xGhCmgz8LwZWfugF5bGbnU8Xnip7v/kPtBx36rJbHsmHNctURJ6zf+ZXjC SJqg== 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:in-reply-to :references; bh=aXtUF/RgxHYBYTXTC5C3r38AEFCPGg91HPc6LqCwOpM=; b=ayHxnzvZxUY9CCsZwhPrFELJUAza9dLIaIEgcN6lAUgfXW7VYQSj07+qrcYYJKKhX9 OYVB+L1czKYRJgR2tnK7XoaM7f+zHlFvpJuJQXeq9vQTvtDub+gvNmHcyIh4SsuMaD2H MvSpBMMIkQMqcuQHZrqnwGmxjllcePtO2dhAoi0ncNihfWLKSUtK5MGv4GBmHVGSKQ4Z y0E9AZppCvnCl2xsighn78y64Ye4Mz/Sc6vAsCKj5/OP6+Qze9fI5j8Zp7VK1JIdOYuU v3pABy8WBa73ZKPHoP/8Iao27axUkoIA4KdZTyxTq++DSBvMq+2xWeUVE/e7QNJ0Cf08 cSZQ== X-Gm-Message-State: AMke39kzF+ZpxbZiyqK46LNAJXYwDDo3NmQCQ+9giDTqP2WnwhP5p3RtFJVymaSqHCOCsw== X-Received: by 10.84.229.9 with SMTP id b9mr23768079plk.175.1487498765450; Sun, 19 Feb 2017 02:06:05 -0800 (PST) From: Hoeun Ryu To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org Cc: Hoeun Ryu , Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , Laura Abbott , Kefeng Wang , Jeremy Linton , linux-arm-kernel@lists.infradead.org Date: Sun, 19 Feb 2017 19:04:10 +0900 Message-Id: <1487498660-16600-7-git-send-email-hoeun.ryu@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487498660-16600-1-git-send-email-hoeun.ryu@gmail.com> References: <1487498660-16600-1-git-send-email-hoeun.ryu@gmail.com> Subject: [kernel-hardening] [RFC 7/7] arm64: map seperately rodata sections for __ro_mostly_after_init section X-Virus-Scanned: ClamAV using ClamSMTP Map rodata sections seperately for the new __ro_mostly_after_init section. Attribute of memory for __ro_mostly_after_init section can be changed later so we need a dedicated vmalloced region for set_memory_rw/ro api. Signed-off-by: Hoeun Ryu --- arch/arm64/mm/mmu.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 91271b1..4a89a2e 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -434,8 +434,22 @@ void mark_rodata_ro(void) * mark .rodata as read only. Use __init_begin rather than __end_rodata * to cover NOTES and EXCEPTION_TABLE. */ - section_size = (unsigned long)__init_begin - (unsigned long)__start_rodata; - create_mapping_late(__pa_symbol(__start_rodata), (unsigned long)__start_rodata, + section_size = (unsigned long)__start_data_ro_mostly_after_init - + (unsigned long)__start_rodata; + create_mapping_late(__pa_symbol(__start_rodata), + (unsigned long)__start_rodata, + section_size, PAGE_KERNEL_RO); + + section_size = (unsigned long)__end_data_ro_mostly_after_init - + (unsigned long)__start_data_ro_mostly_after_init; + create_mapping_late(__pa_symbol(__start_data_ro_mostly_after_init), + (unsigned long)__start_data_ro_mostly_after_init, + section_size, PAGE_KERNEL_RO); + + section_size = (unsigned long)__init_begin - + (unsigned long)__end_data_ro_mostly_after_init; + create_mapping_late(__pa_symbol(__end_data_ro_mostly_after_init), + (unsigned long)__end_data_ro_mostly_after_init, section_size, PAGE_KERNEL_RO); /* flush the TLBs after updating live kernel mappings */ @@ -478,10 +492,18 @@ static void __init map_kernel_segment(pgd_t *pgd, void *va_start, void *va_end, */ static void __init map_kernel(pgd_t *pgd) { - static struct vm_struct vmlinux_text, vmlinux_rodata, vmlinux_init, vmlinux_data; + static struct vm_struct vmlinux_text, vmlinux_rodata1, vmlinux_rodata2, vmlinux_ro_mostly_after_init, vmlinux_init, vmlinux_data; map_kernel_segment(pgd, _text, _etext, PAGE_KERNEL_EXEC, &vmlinux_text); - map_kernel_segment(pgd, __start_rodata, __init_begin, PAGE_KERNEL, &vmlinux_rodata); + map_kernel_segment(pgd, __start_rodata, __start_data_ro_mostly_after_init, PAGE_KERNEL, &vmlinux_rodata1); + __map_kernel_segment(pgd, + __start_data_ro_mostly_after_init, + __end_data_ro_mostly_after_init, + PAGE_KERNEL, + &vmlinux_ro_mostly_after_init, + VM_MAP | VM_ALLOC); + map_kernel_segment(pgd, __end_data_ro_mostly_after_init, __init_begin, PAGE_KERNEL, &vmlinux_rodata2); + map_kernel_segment(pgd, __init_begin, __init_end, PAGE_KERNEL_EXEC, &vmlinux_init); map_kernel_segment(pgd, _data, _end, PAGE_KERNEL, &vmlinux_data);