Received: by 10.213.65.68 with SMTP id h4csp712573imn; Fri, 6 Apr 2018 07:41:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx48s++mnw1Ge/ejxFWzg+RiMM84bWq6m+gpmV2nQh8d5rYWrNLDZfPPprAKcbBFKF6psUFac X-Received: by 10.99.127.9 with SMTP id a9mr2330858pgd.347.1523025705118; Fri, 06 Apr 2018 07:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523025705; cv=none; d=google.com; s=arc-20160816; b=amBBYi3cWmxsJTykkmJvfpW8CCBHViQ0Yx6Mdvl3twQimuIpTbMa+C4+mlulMqdwsn wkio7yM2srHLlESFFRTtHHv3p6bgo5M6IcHNCIidw4377KXvkApBM3vgUBo7OlMid1/Q m8yY8llneGPPc4DuOH1rkgGzWm2pogVvpoVB0lsf8Ab3E26Rd3hBL+HJChB3zE+yhnCZ /xyXR1Eq84jGnxco0+3GTx9QX9p4r+47nYJ9X0skVN/uGdi1GezL0P/QW5zXXyKbGNoc qcJGfZ/rotlVl/JekzhK3nNa0dZJd9rLWO1V/F5bCeLjP30/ka/QIfROtZtRCHO1XS7q SUWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=VOTBAD94XvamumPSPxiRicatM2xNDlaZjtR0lhWIgi8=; b=afoaDOOQ8d5k3zzYJ7PZMvbY7ZaF0MjFnTBIyssGE8TUICSkYjLJM9yx4BJZjO6IQd 8LE6jMdUUjWoQvDF78Z+C0DnLdiRelTOc92HKaKj9aMmJUvCLyH9hQwNtbZiqs6ALCgr TdeO39Mv4vZXENEJLa0q4DEd7kmCqInDZBrcCCR60O2Z1sGsx5zePlSvVwOKHRwybBBz /6xlI2u2KEDcVFuCs8iRUoizTAF6J0+ygXfO29LCaXoq9iU1qvIt0bw3Eh41XzfaisSy xN1amswcLmrtBMmqaC17qu091ksIizEZjsmsANK2GClkeOTSny/pPQqhhfqrm6gQGk06 NUuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6-v6si8469883pla.509.2018.04.06.07.41.31; Fri, 06 Apr 2018 07:41:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755947AbeDFNe6 (ORCPT + 99 others); Fri, 6 Apr 2018 09:34:58 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58534 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755629AbeDFNex (ORCPT ); Fri, 6 Apr 2018 09:34:53 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 41DADDBB; Fri, 6 Apr 2018 13:34:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , "and Acked-by: Mark Rutland" , AKASHI Takahiro , Kees Cook , Rusty Russell , Jessica Yu , Will Deacon , Greg Hackmann , Alex Shi Subject: [PATCH 4.9 056/102] module: extend rodata=off boot cmdline parameter to module mappings Date: Fri, 6 Apr 2018 15:23:37 +0200 Message-Id: <20180406084339.504156219@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084331.507038179@linuxfoundation.org> References: <20180406084331.507038179@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: AKASHI Takahiro commit 39290b389ea upstream. The current "rodata=off" parameter disables read-only kernel mappings under CONFIG_DEBUG_RODATA: commit d2aa1acad22f ("mm/init: Add 'rodata=off' boot cmdline parameter to disable read-only kernel mappings") This patch is a logical extension to module mappings ie. read-only mappings at module loading can be disabled even if CONFIG_DEBUG_SET_MODULE_RONX (mainly for debug use). Please note, however, that it only affects RO/RW permissions, keeping NX set. This is the first step to make CONFIG_DEBUG_SET_MODULE_RONX mandatory (always-on) in the future as CONFIG_DEBUG_RODATA on x86 and arm64. Suggested-by: and Acked-by: Mark Rutland Signed-off-by: AKASHI Takahiro Reviewed-by: Kees Cook Acked-by: Rusty Russell Link: http://lkml.kernel.org/r/20161114061505.15238-1-takahiro.akashi@linaro.org Signed-off-by: Jessica Yu Signed-off-by: Alex Shi [v4.9 backport] Signed-off-by: Mark Rutland [v4.9 backport] Tested-by: Will Deacon Tested-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman --- include/linux/init.h | 3 +++ init/main.c | 7 +++++-- kernel/module.c | 20 +++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) --- a/include/linux/init.h +++ b/include/linux/init.h @@ -133,6 +133,9 @@ void prepare_namespace(void); void __init load_default_modules(void); int __init init_rootfs(void); +#if defined(CONFIG_DEBUG_RODATA) || defined(CONFIG_DEBUG_SET_MODULE_RONX) +extern bool rodata_enabled; +#endif #ifdef CONFIG_DEBUG_RODATA void mark_rodata_ro(void); #endif --- a/init/main.c +++ b/init/main.c @@ -81,6 +81,7 @@ #include #include #include +#include #include #include @@ -914,14 +915,16 @@ static int try_to_run_init_process(const static noinline void __init kernel_init_freeable(void); -#ifdef CONFIG_DEBUG_RODATA -static bool rodata_enabled = true; +#if defined(CONFIG_DEBUG_RODATA) || defined(CONFIG_SET_MODULE_RONX) +bool rodata_enabled __ro_after_init = true; static int __init set_debug_rodata(char *str) { return strtobool(str, &rodata_enabled); } __setup("rodata=", set_debug_rodata); +#endif +#ifdef CONFIG_DEBUG_RODATA static void mark_readonly(void) { if (rodata_enabled) --- a/kernel/module.c +++ b/kernel/module.c @@ -1911,6 +1911,9 @@ static void frob_writable_data(const str /* livepatching wants to disable read-only so it can frob module. */ void module_disable_ro(const struct module *mod) { + if (!rodata_enabled) + return; + frob_text(&mod->core_layout, set_memory_rw); frob_rodata(&mod->core_layout, set_memory_rw); frob_ro_after_init(&mod->core_layout, set_memory_rw); @@ -1920,6 +1923,9 @@ void module_disable_ro(const struct modu void module_enable_ro(const struct module *mod, bool after_init) { + if (!rodata_enabled) + return; + frob_text(&mod->core_layout, set_memory_ro); frob_rodata(&mod->core_layout, set_memory_ro); frob_text(&mod->init_layout, set_memory_ro); @@ -1952,6 +1958,9 @@ void set_all_modules_text_rw(void) { struct module *mod; + if (!rodata_enabled) + return; + mutex_lock(&module_mutex); list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) @@ -1968,6 +1977,9 @@ void set_all_modules_text_ro(void) { struct module *mod; + if (!rodata_enabled) + return; + mutex_lock(&module_mutex); list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) @@ -1981,10 +1993,12 @@ void set_all_modules_text_ro(void) static void disable_ro_nx(const struct module_layout *layout) { - frob_text(layout, set_memory_rw); - frob_rodata(layout, set_memory_rw); + if (rodata_enabled) { + frob_text(layout, set_memory_rw); + frob_rodata(layout, set_memory_rw); + frob_ro_after_init(layout, set_memory_rw); + } frob_rodata(layout, set_memory_x); - frob_ro_after_init(layout, set_memory_rw); frob_ro_after_init(layout, set_memory_x); frob_writable_data(layout, set_memory_x); }