From patchwork Tue Feb 14 20:52:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9572867 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 5593260578 for ; Tue, 14 Feb 2017 20:55:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44B2326C9B for ; Tue, 14 Feb 2017 20:55:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 396AA2840E; Tue, 14 Feb 2017 20:55:23 +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_SIGNED, 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 437BD26C9B for ; Tue, 14 Feb 2017 20:55:22 +0000 (UTC) Received: (qmail 26061 invoked by uid 550); 14 Feb 2017 20:55:11 -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 25819 invoked from network); 14 Feb 2017 20:55:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9M9y6M5/ljK2N7PglUGYmEj0MEaop6XM3Ou5dlunuUQ=; b=Ol9qwzQyYjFVu2e7jwK40lMpmHmiScEAHb8096iWqwHiTBEN15/6GTYQp7PAYeYbeM /CRQ8JY6LjW2y/5B+JmJSjU8BzR8bYTzP8LcY5LodYxhTikwPmsJ/KKcgWXahY450Azu NGRe1spBIyS6ds6cPoikZa1z2eTixP7wltDvA= 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=9M9y6M5/ljK2N7PglUGYmEj0MEaop6XM3Ou5dlunuUQ=; b=ZtxWsHc0jCSl+uwjD4sjKQ0vRpzOTK4pSei3N2NAEUOGXl2XFVqwoy8qG5q7g24MCA Q7wpWJZvk5UbNHzNwlk3qv7cEvN+lK/lBgUlsz7/HQQLF494Hr21K/o/c7/I1w43ksOs c8Zs+v9SsuvlInT6Q+x7PQHfsDPojwyMx14s6xycBtG0afSSHeFVSkbwVuYokBTIMwJB LLyBtZ8KDG5ee8S0YAuJ1ZTn9Nnc25QoNE79340zGNEiM857FLEmnXeZvE0+WzDmZoeC b4AN+irh/9P1R/dkv/scHtoPFXIN9QeQnVecMDKzxbAuGZAhc5vR8XMZ7+n3q8v5Bz86 A/bQ== X-Gm-Message-State: AMke39n8v2Esp8zcX5GqKbyk2qXARHawQZnI6HJgyebUBK79S7xLyB3JHvgganZw/SmWfZE7 X-Received: by 10.223.175.71 with SMTP id z65mr4936832wrc.84.1487105698265; Tue, 14 Feb 2017 12:54:58 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, labbott@fedoraproject.org Cc: kernel-hardening@lists.openwall.com, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, andre.przywara@arm.com, suzuki.poulose@arm.com, james.morse@arm.com, keescook@chromium.org, Ard Biesheuvel Date: Tue, 14 Feb 2017 20:52:37 +0000 Message-Id: <1487105558-21897-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487105558-21897-1-git-send-email-ard.biesheuvel@linaro.org> References: <1487105558-21897-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [kernel-hardening] [PATCH v3 4/5] arm64: mmu: map .text as read-only from the outset X-Virus-Scanned: ClamAV using ClamSMTP Now that alternatives patching code no longer relies on the primary mapping of .text being writable, we can remove the code that removes the writable permissions post-init time, and map it read-only from the outset. To preserve the existing behavior under rodata=off, which is relied upon by external debuggers to manage software breakpoints (as pointed out by Mark), add an early_param() check for rodata=, and use RWX permissions if it set to 'off'. Reviewed-by: Laura Abbott Reviewed-by: Kees Cook Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/mmu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index b7ce0b9ad096..70a492b36fe7 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -442,9 +442,6 @@ void mark_rodata_ro(void) { unsigned long section_size; - section_size = (unsigned long)_etext - (unsigned long)_text; - update_mapping_prot(__pa_symbol(_text), (unsigned long)_text, - section_size, PAGE_KERNEL_ROX); /* * mark .rodata as read only. Use __init_begin rather than __end_rodata * to cover NOTES and EXCEPTION_TABLE. @@ -477,6 +474,12 @@ static void __init map_kernel_segment(pgd_t *pgd, void *va_start, void *va_end, vm_area_add_early(vma); } +static int __init parse_rodata(char *arg) +{ + return strtobool(arg, &rodata_enabled); +} +early_param("rodata", parse_rodata); + /* * Create fine-grained mappings for the kernel. */ @@ -484,7 +487,9 @@ static void __init map_kernel(pgd_t *pgd) { static struct vm_struct vmlinux_text, vmlinux_rodata, vmlinux_init, vmlinux_data; - map_kernel_segment(pgd, _text, _etext, PAGE_KERNEL_EXEC, &vmlinux_text); + pgprot_t text_prot = rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; + + map_kernel_segment(pgd, _text, _etext, text_prot, &vmlinux_text); map_kernel_segment(pgd, __start_rodata, __init_begin, PAGE_KERNEL, &vmlinux_rodata); map_kernel_segment(pgd, __init_begin, __init_end, PAGE_KERNEL_EXEC, &vmlinux_init);