From patchwork Sun Feb 19 10:04:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hoeun Ryu X-Patchwork-Id: 9581519 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 E5CC9604A0 for ; Sun, 19 Feb 2017 10:05:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D81AA2872C for ; Sun, 19 Feb 2017 10:05:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBBAB28734; Sun, 19 Feb 2017 10:05:25 +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 060972872C for ; Sun, 19 Feb 2017 10:05:24 +0000 (UTC) Received: (qmail 19901 invoked by uid 550); 19 Feb 2017 10:05:21 -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 19803 invoked from network); 19 Feb 2017 10:05:20 -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=7RLjoKp1Q8ynCFBbEcv7s13BycY4v/GZLjOTdLhyhsY=; b=h+QWUhm2VNU4oJpVdZrPv0Ti0jCsF8Uu6AkhEzWRrqc0STU43zBGHDH0K4GDeYODyj ZqBPehbfmdY8hVkJ48QbZQGsU6uF45N7kEEzumHIqGth7Q3qO4YRfoDAyyix2C0mko3U is8yFu4G5TWU/HqAZoa1BkgMJjOXtNd006BNDfWjqcOl/aqXsZ6xH09/H+SQ/xEkw1Yu +zPREvygFAkW2HBv8K9re/Nr1pVT3iJoahBWhn0wkz7NnGpOSgPkKPOLeWBgIVgCr581 0++4Ih7BzlfxlSnvatmIovWHcK0razRI4w9lklxRALxEnaIDpZLZYkG+0aOgbwBKYxVz 72QA== 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=7RLjoKp1Q8ynCFBbEcv7s13BycY4v/GZLjOTdLhyhsY=; b=lNor4zKk25+kkM08WTygZrKk/XiYHP38HEgir8sAv8yy3iIUaWyIloKpgTUNLWiW0u vW1kvR+U8bOQ0amw3gHa/szCugU4B7afa9REpwM0bZc/q6P64NWHzHD2piG6LvMUhmus K+UzwzFzT0yyuJhlyf5PX4ribMgLV66TOvkCbUFzseJ0Mtc9t6R53/zWx0S3u3dpOw1Q Zlg3vtr5GD8Zv4S6SdZeQzMSExsdPbzaglY0EBco8pfGzlus+KUQlUepBFXRKSqcF4M1 2KGnCV7lQrOMI9fR+4VzVRDBVgI2ex82WleCpibAXYJcPU/xHAuIpS6RSu/NqHQAOsVY Oz1g== X-Gm-Message-State: AMke39nM21xSPnugr+s5dxKo0rHKC1mbAzVtmiQTLP9Vo9Qr/bB4RzNKbxWB1ngriXU2Wg== X-Received: by 10.84.224.65 with SMTP id a1mr23917147plt.28.1487498709232; Sun, 19 Feb 2017 02:05:09 -0800 (PST) From: Hoeun Ryu To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org Cc: Hoeun Ryu , Jessica Yu , Rusty Russell Date: Sun, 19 Feb 2017 19:04:06 +0900 Message-Id: <1487498660-16600-3-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 3/7] module: modify memory attrs for __ro_mostly_after_init during module_init/exit X-Virus-Scanned: ClamAV using ClamSMTP `__ro_mostly_after_init` is almost like `__ro_after_init`. The section is read-only as same as `__ro_after_init` after kernel init. This patch makes `__ro_mostly_after_init` section read-write temporarily only during module_init/module_exit. Signed-off-by: Hoeun Ryu --- kernel/module.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 7eba6de..3b25e0e 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -987,8 +987,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, mutex_unlock(&module_mutex); /* Final destruction now no one is using it. */ - if (mod->exit != NULL) + if (mod->exit != NULL) { + set_ro_mostly_after_init_rw(); mod->exit(); + set_ro_mostly_after_init_ro(); + } blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GOING, mod); klp_module_going(mod); @@ -3396,8 +3399,11 @@ static noinline int do_init_module(struct module *mod) do_mod_ctors(mod); /* Start the module */ - if (mod->init != NULL) + if (mod->init != NULL) { + set_ro_mostly_after_init_rw(); ret = do_one_initcall(mod->init); + set_ro_mostly_after_init_ro(); + } if (ret < 0) { goto fail_free_freeinit; }