From patchwork Tue Apr 3 11:09:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 132717 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3665894ljb; Tue, 3 Apr 2018 04:10:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx48WE982v+R16KUwIs+sdnoFTtLCGy4JQqRpxT+x9lw45aJn1fsrs3L9cBNR4JRHs1RouIJD X-Received: by 2002:a17:902:6ac1:: with SMTP id i1-v6mr13410164plt.152.1522753807003; Tue, 03 Apr 2018 04:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522753806; cv=none; d=google.com; s=arc-20160816; b=FpuaLdfNYx91JrK3X0GXzDhHP5A8W+0s7zz/E53BNstQzr/I8MM6eVIVJC6gDjS0Js VdKO9prIQUB/w7MGw+D3FyX6A2VOIRJCV4TF8FsQAJOWhSR82gK+0H4fgT87rYHlc4vy ofNHNjcTI5BxPW6rtH/4a8W86NtYMRrGjEmLdF04r2WwfeNsI2e32x93dUfh20jgJ68o /d4HvUj8EeFoEY2USB/pfXKDAWZvonk8rD7XOAiqzksJ6IR/+k3gVOu47Zr/zxuyHcUJ 5dN1uRVEAEk5FGYdtkaq0qQcuJOIEGp3XbR2hqE/RO+dHdXBGxEF/LrY1LBFFrJFwWAB We7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=ULEC0sabRFRFzZMXzMCqq8OaN3CA8uhTjvo0X2Gu/L4=; b=YTCnbPZnBfL0wbEEBozvgcOFyVLN+vrCXq/o80qA/1J5qY/r0J1KDM5D6TYgRbKklo BJrvP4Y/MouWZ/kPp/APD5DGnZSqaUlMBh/eZ5aZTiEDaoa9IGpotLDabLitPLWIx2C8 wpRD0N40dxqx9Moo/SyO36bozMF1TGAX1v9yOEeFy00qAhNyEVPTEmYwNuRXEHF72nIX 9K+SA6k/5GVJcfWkjDeshb4FqR8dltKahCq0d7SeOdYElBFXv2AOF7oGXsHpp3rd+l9w G4zFv+V78eBjUG/G0FPbeZmc3EVBokJ96TytoVTAJ/K6vo0O28QP9+43/Q+8SUEIss+2 dRqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 k63si1862166pgc.577.2018.04.03.04.10.06; Tue, 03 Apr 2018 04:10:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755481AbeDCLKC (ORCPT + 11 others); Tue, 3 Apr 2018 07:10:02 -0400 Received: from foss.arm.com ([217.140.101.70]:59316 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755063AbeDCLJ7 (ORCPT ); Tue, 3 Apr 2018 07:09:59 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 72FFC1435; Tue, 3 Apr 2018 04:09:59 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 428AD3F587; Tue, 3 Apr 2018 04:09:58 -0700 (PDT) From: Mark Rutland To: stable@vger.kernel.org Cc: mark.brown@linaro.org, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, will.deacon@arm.com Subject: [PATCH v4.9.y 07/27] module: extend 'rodata=off' boot cmdline parameter to module mappings Date: Tue, 3 Apr 2018 12:09:03 +0100 Message-Id: <20180403110923.43575-8-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180403110923.43575-1-mark.rutland@arm.com> References: <20180403110923.43575-1-mark.rutland@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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] --- include/linux/init.h | 3 +++ init/main.c | 7 +++++-- kernel/module.c | 20 +++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) -- 2.11.0 diff --git a/include/linux/init.h b/include/linux/init.h index 683508f6bb4e..0cca4142987f 100644 --- 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 diff --git a/init/main.c b/init/main.c index 99f026565608..f22957afb37e 100644 --- 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 char *init_filename) 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) diff --git a/kernel/module.c b/kernel/module.c index 07bfb9971f2f..0651f2d25fc9 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1911,6 +1911,9 @@ static void frob_writable_data(const struct module_layout *layout, /* 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 module *mod) 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); }