From patchwork Sun Feb 19 10:04:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hoeun Ryu X-Patchwork-Id: 9581509 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 561D5604A0 for ; Sun, 19 Feb 2017 10:04:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48C8C2872C for ; Sun, 19 Feb 2017 10:04:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DB9828734; Sun, 19 Feb 2017 10:04:53 +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 A2A892872C for ; Sun, 19 Feb 2017 10:04:51 +0000 (UTC) Received: (qmail 17454 invoked by uid 550); 19 Feb 2017 10:04:47 -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 16265 invoked from network); 19 Feb 2017 10:04:39 -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=0d+p4oOUHWsfuLKIMAe1Iq726ALVL7m59n7ybwW1rPY=; b=RgP8dPXMEHBW9bn96juXtrhLfinffCVPHMmswkC6sk067tohf+nmTAfl9qx0N4r19o 2DBEt37ZwpEFwDoPc0EpZeGUO/t/DUNO1MMFkjxjQvDEMOM2ww/2WqqR9cp1AR+mJZVg ET0B3qKnhxCsiuib1WurR0H46BOU9TYKc+7tUc/horkLjoJFpNpMSfpXg22Q6SUb19J9 ojoROe1lLmdxxVvJ3lr3S8/IPQBSVXCWPkwUyHwvJUjRLQ/Ueq8FjdiIIaUReeA11tFB 22az2sWYGPBoTT0QPG2W2jGz4wfqwe2iMkzWUG3aykKD9nuxJPLseYV7Ymp++JI/yRuq UiSA== 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=0d+p4oOUHWsfuLKIMAe1Iq726ALVL7m59n7ybwW1rPY=; b=KWyNgpc33Qh4s7NY0aTJARD4Bkc7Wp2cjRuuN3+ddXIQ0JgclLXVzNUp0r4a82T0Ql tv8lgz1UE3yrHhlAkW4asDkV86+8Hh/SFoA9RJ0Yu0uoZNCJ3DKCJHJWdDGY0H5O5tPr Kv92JX4lmUFjR9Mi5NynPGn7ee6MwDa7iCcvKfJ+6hEx1dfUq8Qe9UoI/Vu6U3bYSpe+ rd07MMHfbMWcjK7/LThXYps9MoyD6BfeGjG4miZomdC56ZLkDvbjQv6GTPy6yr4XD6/k 0jdlL8f8i/YyDNS09uVPhVyM615bHNDAoD77UDttehecCDXXIOUtNYNyPaLzGJ2CMUAE Mz5A== X-Gm-Message-State: AMke39lqpo7dQhR6mN4r6F3PLWuY3Lgiq0tTYEcwgV9ecvg1bdG05qMsUrbJ+QlJtEuQuQ== X-Received: by 10.99.48.68 with SMTP id w65mr20642829pgw.107.1487498667724; Sun, 19 Feb 2017 02:04:27 -0800 (PST) From: Hoeun Ryu To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org Cc: Hoeun Ryu , Arnd Bergmann , Kees Cook , Ingo Molnar , linux-arch@vger.kernel.org Date: Sun, 19 Feb 2017 19:04:04 +0900 Message-Id: <1487498660-16600-1-git-send-email-hoeun.ryu@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [kernel-hardening] [RFC 1/7] arch: add __ro_mostly_after_init section marker X-Virus-Scanned: ClamAV using ClamSMTP After `__ro_after_init` marker is included in kernel, many kernel data objects can be read-only-after-init. But there are many other places that would be good to read-only-after-init but `__ro_after_init` can not be simply applicable to them because they should be writable at some points, which are during module_init/exit or dynamic de/registration for a specific subsystem. `__ro_mostly_after_init` is basically the same to `__ro_after_init`. The section is mapped as read-only after kernel init. The different thing is this section is temporarily mapped as read-write during module_init/exit and de/registration of a subsystem using set_ro_mostly_after_init_rw/ro pair. Use `__ro_mostly_after_init` as a way to mark such memory instead when `__ro_after_init` is not applicable because the memory should be writable at the described points of time. They are read-only right after kernel init and writable temporarily only during module_init/exit and dynamic de/registration for a subsystem. Signed-off-by: Hoeun Ryu --- include/asm-generic/sections.h | 1 + include/asm-generic/vmlinux.lds.h | 10 ++++++++++ include/linux/cache.h | 11 +++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index 4df64a1..16a6f21 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -34,6 +34,7 @@ extern char __bss_start[], __bss_stop[]; extern char __init_begin[], __init_end[]; extern char _sinittext[], _einittext[]; extern char __start_data_ro_after_init[], __end_data_ro_after_init[]; +extern char __start_data_ro_mostly_after_init[], __end_data_ro_mostly_after_init[]; extern char _end[]; extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[]; extern char __kprobes_text_start[], __kprobes_text_end[]; diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 4e09b28..cc5f44e 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -265,6 +265,15 @@ __end_data_ro_after_init = .; #endif +#ifndef RO_MOSTLY_AFTER_INIT_DATA +#define RO_MOSTLY_AFTER_INIT_DATA(align) \ + . = ALIGN(align); \ + VMLINUX_SYMBOL(__start_data_ro_mostly_after_init) = .; \ + *(.data..ro_mostly_after_init) \ + . = ALIGN(align); \ + VMLINUX_SYMBOL(__end_data_ro_mostly_after_init) = .; +#endif + /* * Read only Data */ @@ -275,6 +284,7 @@ *(.rodata) *(.rodata.*) \ RO_AFTER_INIT_DATA /* Read only after init */ \ KEEP(*(__vermagic)) /* Kernel version magic */ \ + RO_MOSTLY_AFTER_INIT_DATA(align) \ . = ALIGN(8); \ VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \ KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \ diff --git a/include/linux/cache.h b/include/linux/cache.h index 1be04f8..fd1cb9b 100644 --- a/include/linux/cache.h +++ b/include/linux/cache.h @@ -30,6 +30,17 @@ #define __ro_after_init __attribute__((__section__(".data..ro_after_init"))) #endif +/* + * __ro_mostly_after_init is almost like __ro_after_init. + * but __ro_mostly_after_init section is temporarily writable only during + * module_init/exit or dynamic de/registeration of a subsystem using + * set_ro_mostly_after_init_rw/ro pair. + */ +#ifndef __ro_mostly_after_init +#define __ro_mostly_after_init \ + __attribute__((__section__(".data..ro_mostly_after_init"))) +#endif + #ifndef ____cacheline_aligned #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES))) #endif