From patchwork Wed Feb 28 03:56:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129892 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp567945lja; Tue, 27 Feb 2018 19:58:38 -0800 (PST) X-Google-Smtp-Source: AH8x225cmXoOwFqA7p+KMXQe71gDzQEW11jVu56zrerKp2hRFvjFH2yBMSdyTvKx/fv02gD3bRE7 X-Received: by 2002:a17:902:225:: with SMTP id 34-v6mr16566998plc.415.1519790318126; Tue, 27 Feb 2018 19:58:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519790318; cv=none; d=google.com; s=arc-20160816; b=NdKitEeJIcE78JN5osLstIoYA7ZmmHjz7hzcazFEZ9M5Cz7yxDBOSZpnlMFOctBgCG RG7zFxOmamLqiWULMOYFmGKrRbpl0PNTmUjLIgAjf7sYuOO1dEFYv9rQDfbliYxvxlc/ kMpGkTnrw+nyEAuB8T37EejNWHPijUavd0lQEIWJLgG9S+S4mdAQVua7sy6sO5rr+OeP vSzr77dfoAegKSLMOABF073ACBHnpWB2uy+jt0xHxoZ89W1BgW4ldH/aZcykRiBn1psg GAZ/rWbPbvXXxvFU59ZLAlswlQ+vfuYwBp92auCxpGONiRYsVCswWo3TKqyLzMKdAQGe 6YMw== 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:dkim-signature:arc-authentication-results; bh=9AGPVua7FerW9MHbnW3GGajj8cb4hN8hkiOyT6YzHrQ=; b=HEooCQg8R4jHlp7AlfAJKZPb9L9VJiuGMzX5EtwkMxDjH1etL55iukRr/v2pSV8CG/ ZY+yxr9Kbie7oOHykvdWS86hF0bxjNVo69eofrkUpt36eGqH+eu3p016yxYDaBRGVfqP NCtEgR8wdrNEFA08mcHGrgmC6sYAzbq1+0PXnqcnjlQUfb6wHKQ7/w96taqWSQByc3LC BFpp2+5T38FEjrWDkQL2w8Hyn3kx611TJ2IWZLCQtTmZ9jEgHmni+KbHrM7F4U5aB+sW HVtRcd7otRbxcnKwtxzYRgsC2tq7FRrHnOB2AxajCKgG1gFZfE9rFq8eoCShnlsUTnOW PtdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DgNjoIR8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4-v6si586704plb.114.2018.02.27.19.58.37; Tue, 27 Feb 2018 19:58:38 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=DgNjoIR8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752130AbeB1D6f (ORCPT + 28 others); Tue, 27 Feb 2018 22:58:35 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:40640 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752110AbeB1D6c (ORCPT ); Tue, 27 Feb 2018 22:58:32 -0500 Received: by mail-pf0-f196.google.com with SMTP id m5so506915pff.7 for ; Tue, 27 Feb 2018 19:58:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9AGPVua7FerW9MHbnW3GGajj8cb4hN8hkiOyT6YzHrQ=; b=DgNjoIR8+juvDroKwmeklTID+hCjbk6wTFRxycGBE9p45Ac7l+uBgbtXIfuSHDc1We 6yGWjLMdwBz1sl6OGQM2aQZJ39/4CHIDV1icB9uqM6B4coRgslHC6PYXZ+VsfC+24oft YNUEW8YDyp0ETa8LFoHka3tswCezYg5oHE/ks= 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=9AGPVua7FerW9MHbnW3GGajj8cb4hN8hkiOyT6YzHrQ=; b=MZRwoqcwxAB7OJyLmLNTUoCKyMAU7wgwapPp6IaZPfG4jAJ1NlcqdADejABeKCxlYN MHD4P15aOuFOWQ7l7ITC2MSbKlcfzgegN4YgMNxMgXU9KaubuEEy1pFOxuqDtb8MvY5p LGS+jreX4cmqUtS/tBNHW2v6h6z/KeD6HjFe0RzHjUbLzGaU+tZx95S2joTukCGTdSFf QSg0ZsPgXpwj9DXsUSc2yOIwOqVuvd8QLR8TuL8AJlFc3CbuQ+F2PL0nWdK/6X95jq3n rRtDbgTHq/0CiDRM5mekcwpwxopt8ivWwZ2eDKnYXVH0iinS32pQPOVew75prm+caK4A dgVg== X-Gm-Message-State: APf1xPDmNO9VGBDQfZDhFgB5k8XohfVVLGOZ4tnNYiNQQqO69UP46UWs Tzwg0XWoS7AQUDbORTKxjMIOaA== X-Received: by 10.101.81.204 with SMTP id i12mr13056152pgq.206.1519790312181; Tue, 27 Feb 2018 19:58:32 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id q17sm739911pgt.7.2018.02.27.19.58.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 19:58:31 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: AKASHI Takahiro , Jessica Yu , Alex Shi Subject: [PATCH 08/29] module: extend 'rodata=off' boot cmdline parameter to module mappings Date: Wed, 28 Feb 2018 11:56:30 +0800 Message-Id: <1519790211-16582-9-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519790211-16582-1-git-send-email-alex.shi@linaro.org> References: <1519790211-16582-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Conflicts: keeping kaiser.h in init/main.c --- include/linux/init.h | 3 +++ init/main.c | 7 +++++-- kernel/module.c | 20 +++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/include/linux/init.h b/include/linux/init.h index 8e346d1..4dfe300 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 99f0265..f22957a 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 07bfb99..0651f2d 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); }