From patchwork Sun Feb 19 10:04:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hoeun Ryu X-Patchwork-Id: 9581515 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 3E3A4604A0 for ; Sun, 19 Feb 2017 10:05:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EF4A2872E for ; Sun, 19 Feb 2017 10:05:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21D332872C; Sun, 19 Feb 2017 10:05:13 +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 5835D2872C for ; Sun, 19 Feb 2017 10:05:11 +0000 (UTC) Received: (qmail 18026 invoked by uid 550); 19 Feb 2017 10:05:10 -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 18001 invoked from network); 19 Feb 2017 10:05:09 -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=LlerfMkjcwEGGIDZ2KI3wPiiT0ykPV2sqxdCgSFxXvw=; b=o5AYnvbuNLSLl30UJm+qhFA/YCVTdAgT09UkrGfLfBxVx7KyYTw4Bjxr04JvnRr6Nm LojpPbo6y00N3R22nzzaWkyzaaAQdMKmTdZ+JgrQYmYP5snzrfywScZqsVBZi9D6QcgW bguFe5Sh+WCt/5BNYH5wNUeWmPIuu7eXfkPHZH66wsw3GbxQf/nknTGAClx1Aq8siic3 T1DP+E1bp/WexTpqH/8VPYfHHhhHA7yW5TX9TW16CxI/jRSAvMr1uKoZAwQSe/H8k23X 8z1H42bKBBwv331AEMbaZkabziDfpf3kjOWSuARLopv71wXqdCsLfmFuRspyJHT1xw+E n3MQ== 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=LlerfMkjcwEGGIDZ2KI3wPiiT0ykPV2sqxdCgSFxXvw=; b=aTbqdxcYUEd8fGwKEBsOEmGzuCTOf85h4l8Qh7HEfECHUNSQUqQhhUgMCoafP9vrm+ LKOppRe9oBmT1LFZbr55RACBhI03sr9/+6sTXjp6bKfZo8V/oEbFo2QwVpL+vx0qb77m Uz7nLbTH5D2Itn+LTBjqHWcZ89UNUVyIMrQZKBSGJ6Q0gdGz3KWfh2hXM1FfxEDBYlGG Y6NVRRCdr2kzcLfgNE0RJVFtdvMVH/+5HUIRrtfn1Ds0ghxF8Wjrk/it8M/1aTEtxlgW IBv8/2jb+x6CLXTFwYyQ0uHvqXZckPdEUmTIZTO6OfmCaJw0KrOkUDS4lq/14wg3Cqwf z7Yg== X-Gm-Message-State: AMke39l0oqEoxq1L4UL9t9WnYKI5G2DB/+K0qVNqIcb/kR9pC6eeqbsTegowGGdhaYQJpQ== X-Received: by 10.84.160.197 with SMTP id v5mr23687144plg.161.1487498698006; Sun, 19 Feb 2017 02:04:58 -0800 (PST) From: Hoeun Ryu To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org Cc: Hoeun Ryu , Kees Cook , Jessica Yu , Ingo Molnar , Andrew Morton , Emese Revfy , AKASHI Takahiro , Fabian Frederick , Helge Deller , Laura Abbott , Nicholas Piggin , Thomas Gleixner , Petr Mladek , Yang Shi , Rasmus Villemoes , Tejun Heo , Prarit Bhargava , Lokesh Vutla Date: Sun, 19 Feb 2017 19:04:05 +0900 Message-Id: <1487498660-16600-2-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 2/7] init: add set_ro_mostly_after_init_rw/ro function X-Virus-Scanned: ClamAV using ClamSMTP Add set_ro_mostly_after_init_rw/ro pair to modify memory attributes for memory marked as `ro_mostly_after_init`. I am doubtful that this is the right place where these functions reside and these functions are suitable for all architectures for memory attributes modification. Please comment. Signed-off-by: Hoeun Ryu --- include/linux/init.h | 6 ++++++ init/main.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/init.h b/include/linux/init.h index 79af096..d68e4f7 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -131,6 +131,12 @@ extern bool rodata_enabled; #endif #ifdef CONFIG_STRICT_KERNEL_RWX void mark_rodata_ro(void); + +void set_ro_mostly_after_init_rw(void); +void set_ro_mostly_after_init_ro(void); +#else +static inline void set_ro_mostly_after_init_rw(void) { } +static inline void set_ro_mostly_after_init_ro(void) { } #endif extern void (*late_time_init)(void); diff --git a/init/main.c b/init/main.c index 4719abf..a5d4873 100644 --- a/init/main.c +++ b/init/main.c @@ -941,6 +941,30 @@ static void mark_readonly(void) } else pr_info("Kernel memory protection disabled.\n"); } + +void set_ro_mostly_after_init_rw(void) +{ + unsigned long start = PFN_ALIGN(__start_data_ro_mostly_after_init); + unsigned long end = PFN_ALIGN(&__end_data_ro_mostly_after_init); + unsigned long nr_pages = (end - start) >> PAGE_SHIFT; + + if (!rodata_enabled) + return; + + set_memory_rw(start, nr_pages); +} + +void set_ro_mostly_after_init_ro(void) +{ + unsigned long start = PFN_ALIGN(__start_data_ro_mostly_after_init); + unsigned long end = PFN_ALIGN(&__end_data_ro_mostly_after_init); + unsigned long nr_pages = (end - start) >> PAGE_SHIFT; + + if (!rodata_enabled) + return; + + set_memory_ro(start, nr_pages); +} #else static inline void mark_readonly(void) {