Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp856543ybb; Wed, 8 Apr 2020 11:13:28 -0700 (PDT) X-Google-Smtp-Source: APiQypKGQNYTNIHL8iUuYNein2HvgpJQCMXBTQ4LJfIfhfntvONjRylJF8urF1SHXQzjBPnK7MF1 X-Received: by 2002:a9d:943:: with SMTP id 61mr6760386otp.3.1586369607864; Wed, 08 Apr 2020 11:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586369607; cv=none; d=google.com; s=arc-20160816; b=ixJLnJSF6MeqQFN5a5h4GRmEpb/AfIgWHQNDaBd9zSh4/q9Y2KDeuyAS8Y2b7hyzoe z817XBbn+BqjRI82frqZyX2K7+q8dTX1jQhEeFUIKnDzBKYPdikAUbpRqKWqgh2Nc7wJ edp/TSw/ZHuDp8LJnJR+7eK1Vvd21klbSdE1tNT2rsR6nKyc/+4R529uznkbK+WGnj5o aonuJI+yfFsxOAxlvgafxJnRaDYjU4dIU6slgiGXiSC8XuQ1cMb2dU1KR5LS+T5yHbmD yXjjtTpeE9tR0dKITyYpHu0V157vk+ElS46To52k6mtT1x/Jtv3CxS5Nno1T54q8dyuf eyvw== 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; bh=zcH/xBjn59VSE7GpMQlkICkOPQ8yC3pif9wtI7AXB+c=; b=MGnOHnwfltmmHqePVi1IZ+/IrJXlqKX0QPRioevQ8cmFG/U9C7Xp3ot+YR6WYUeybg z8E9uh05/BpIHtqbbamYimlkDCXsY7PvxCNMqEiS5vrOUM6L7i1wok61GWuubCi120tA S22FdjRovTpiQqTv2Fvs5c4ZbiFWcQBV3Jxm/0Slq1upJiuACYu73VPCiqfJ6IMfPPZh mscpuurR/qAH+/DW1n/6Lvn96+G8Ve5rkPyqSvS2HhN4BW0wDQtLQw+xzYm/mNQTZehk Ebr6WRdqcedZj36kgnHlz2rPhfio38gJwN3twZN3k/dDppv71bkN4YhtVErCzqRD4FgM gE3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M9CEEWgW; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d16si3005892oti.42.2020.04.08.11.13.13; Wed, 08 Apr 2020 11:13:27 -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; dkim=pass header.i=@kernel.org header.s=default header.b=M9CEEWgW; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729395AbgDHPoZ (ORCPT + 99 others); Wed, 8 Apr 2020 11:44:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:48170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727933AbgDHPoZ (ORCPT ); Wed, 8 Apr 2020 11:44:25 -0400 Received: from linux-8ccs.suse.de (p3EE2C7AC.dip0.t-ipconnect.de [62.226.199.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E8B8F206F5; Wed, 8 Apr 2020 15:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586360664; bh=bliEcMVKnd3LisxyVMV94nASjsWsxhu1Gq03tUP6WYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M9CEEWgWqM+2CIZXusFR9nMVNYqNACFSljYP7gdMjiAg1p7o3HoL3OhUlCMzdd4TC /BBgLo4LrbZ5GrOAWJQd7KlzmQCYJU1Ba7SuRvbqngMYhEnY2zjww6smPvzX4/JzsU bYoBMEFmVZ3GUw80qXwBAW5ec3F+isTnJOtIwNNA= From: Jessica Yu To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , keescook@chromium.org, Josh Poimboeuf , Miroslav Benes , Jessica Yu Subject: [PATCH] module: break nested ARCH_HAS_STRICT_MODULE_RWX and STRICT_MODULE_RWX #ifdefs Date: Wed, 8 Apr 2020 17:43:23 +0200 Message-Id: <20200408154323.20631-1-jeyu@kernel.org> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200408153249.GA26619@linux-8ccs> References: <20200408153249.GA26619@linux-8ccs> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Various frob_* and module_{enable,disable}_* functions are defined in a CONFIG_ARCH_HAS_STRICT_MODULE_RWX ifdef block which also has a nested CONFIG_STRICT_MODULE_RWX ifdef block within it. This is unecessary and makes things hard to read. Not only that, this construction requires redundant empty stubs for module_enable_nx(). I suspect this was originally done for cosmetic reasons - to keep all the frob_* functions in the same place, and all the module_{enable,disable}_* functions right after, but as a result it made the code harder to read. Make this more readable by unnesting the ifdef blocks and getting rid of the redundant empty stubs. Signed-off-by: Jessica Yu --- kernel/module.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index b88ec9cd2a7f..2b28f8bf2322 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1943,7 +1943,6 @@ static void mod_sysfs_teardown(struct module *mod) mod_sysfs_fini(mod); } -#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX /* * LKM RO/NX protection: protect module's text/ro-data * from modification and any data from execution. @@ -1957,6 +1956,14 @@ static void mod_sysfs_teardown(struct module *mod) * * These values are always page-aligned (as is base) */ + +/* + * Since some arches are moving towards PAGE_KERNEL module allocations instead + * of PAGE_KERNEL_EXEC, keep frob_text() and module_enable_x() outside of the + * CONFIG_STRICT_MODULE_RWX block below because they are needed regardless of + * whether we are strict. + */ +#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX static void frob_text(const struct module_layout *layout, int (*set_memory)(unsigned long start, int num_pages)) { @@ -1966,6 +1973,15 @@ static void frob_text(const struct module_layout *layout, layout->text_size >> PAGE_SHIFT); } +static void module_enable_x(const struct module *mod) +{ + frob_text(&mod->core_layout, set_memory_x); + frob_text(&mod->init_layout, set_memory_x); +} +#else /* !CONFIG_ARCH_HAS_STRICT_MODULE_RWX */ +static void module_enable_x(const struct module *mod) { } +#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */ + #ifdef CONFIG_STRICT_MODULE_RWX static void frob_rodata(const struct module_layout *layout, int (*set_memory)(unsigned long start, int num_pages)) @@ -2037,18 +2053,9 @@ static void module_enable_nx(const struct module *mod) } #else /* !CONFIG_STRICT_MODULE_RWX */ +/* module_{enable,disable}_ro() stubs are in module.h */ static void module_enable_nx(const struct module *mod) { } #endif /* CONFIG_STRICT_MODULE_RWX */ -static void module_enable_x(const struct module *mod) -{ - frob_text(&mod->core_layout, set_memory_x); - frob_text(&mod->init_layout, set_memory_x); -} -#else /* !CONFIG_ARCH_HAS_STRICT_MODULE_RWX */ -static void module_enable_nx(const struct module *mod) { } -static void module_enable_x(const struct module *mod) { } -#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */ - #ifdef CONFIG_LIVEPATCH /* -- 2.16.4