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: 9581541 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 70D07604A0 for ; Sun, 19 Feb 2017 10:07:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6136D2868C for ; Sun, 19 Feb 2017 10:07:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5264628708; Sun, 19 Feb 2017 10:07:00 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0B8442868C for ; Sun, 19 Feb 2017 10:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=mW6gWt6mT9YAA4L6cN51ThEPiQ0ID+jO+jIWUNW/0Ew=; b=VG01mFQnbUC/KRiMpwx37Hndrr DbzkKbGA539G+175GXI6LeIhDtCbfV/73BDXLQgf1wP0ZSTa98M+WKI7k9Ooz4jCp+pcQGBhwodsY RD2PYoYg83EpZwbF2DfQBsg0zGhTsP8mHtcZY8+ATaxyxx/zdwUyg8Tgt9URdDByIiKzgM1SR/Unu v0bFOvZwrtNS7URmzQweI3wecT+4J2fBVJ2R1N9ftk01m9iCKdML3dhm2CyBDpK//pf3DMXPRftv7 p5nYntcnkjEhSBKFyF0uQdpcAww7qVXFA8JgDyTOhv2MI/ITCWQN0d+4YBXyfU5jdKhQXxjoCP72n DDQCm6tw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cfOOQ-0003v5-Tk; Sun, 19 Feb 2017 10:06:58 +0000 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cfONu-0003e5-7N for linux-arm-kernel@lists.infradead.org; Sun, 19 Feb 2017 10:06:28 +0000 Received: by mail-pg0-x242.google.com with SMTP id 5so9104366pgj.0 for ; Sun, 19 Feb 2017 02:06:05 -0800 (PST) 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=eey7aYIEYrLploYiLrBo6QFcPnTzotr0wkpyDxjOmzmj6tV/CghS62uGCiUeLEvK+h 5zi0w8RnOC61xfejotG+4PYteI3fKk8ovtdacGXoBQ6pM1uWAKCfiDaN+WP7KWSTlWEu vxEkKHHGO+ZwPB/2q+D/Pk+/fmzZsFRbwcGtFZyL9hu47zudAcnQdurDLi1APAknV402 deFtwvme3UgOu0ELyb1m0iIpE2R5Hk2giJ21TD7v6Hnd/h9Dn8VXwrzDDMuqzq3m+4Cm oW/8dxbQ7S8luyWlYiHtgBLvCDr31dS45Y/6vsvfxP1xPa6+VbpVIggnKoo4mpna2QSF KdYw== X-Gm-Message-State: AMke39kMXs5dX4JDMz/Y83dwYLYP04vv0kUy6bQPQDt8YWMQELaHwiNc531yVS5fu0p1pQ== X-Received: by 10.84.229.9 with SMTP id b9mr23768079plk.175.1487498765450; Sun, 19 Feb 2017 02:06:05 -0800 (PST) Received: from localhost.localdomain ([61.72.81.53]) by smtp.gmail.com with ESMTPSA id v8sm29038141pgo.14.2017.02.19.02.06.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 19 Feb 2017 02:06:05 -0800 (PST) From: Hoeun Ryu To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org Subject: [RFC 7/7] arm64: map seperately rodata sections for __ro_mostly_after_init section 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170219_020626_398776_BB749B77 X-CRM114-Status: GOOD ( 11.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Kefeng Wang , Hoeun Ryu , Ard Biesheuvel , Catalin Marinas , Will Deacon , Jeremy Linton , Laura Abbott , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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);