Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp104943rdb; Thu, 21 Dec 2023 04:17:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+p1d67Q3fs758eCvYuTQcpoQbGFOsUR8d7/DnFdCYA1EEKJfPphmVFUOKLiRGRytFWyQe X-Received: by 2002:a05:6214:da1:b0:67f:8bee:a1a0 with SMTP id h1-20020a0562140da100b0067f8beea1a0mr191472qvh.60.1703161028093; Thu, 21 Dec 2023 04:17:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703161028; cv=none; d=google.com; s=arc-20160816; b=DJm1tUSm3oj3ec17SASqGAijHY2d+ryEjclfRIvDyA1+ZhvN5+OCwMF4d67uHKMwmm agdmJLApbp4yWRp1g39Ya2y+uOhx1TDHv7BZqCxbSlOQsi04XuZOIi2YnR63kDW85ceX sKbetL/ULqQfZipQ2m29QYn1X9QDy5xuJ8/RGb9wuONC/foinzoalV2RLRaveJ6cxRvc Q00F8V/Ua2EAZsGu8bgLqlA7UJWTx9l+/YZLIHtV0hqRaeyk89ylldUk9q0m92NarQFT VW6UJPGXHU6L7rKwo1hfC2WtCLKLuhGESRJuc52N7k5JHwhWJSpNId+Qu5rgrjRoDri8 lIoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=5d6zNSFt4jEG/MYae1GPrrzN7fMvSd5x94D4zOd+D6c=; fh=z9uotTRyC/xO41oyeFV6CgFb89o70MMMxCYN2izQ8Gk=; b=Uj4CaHJjGMMUw8y1sNrDvEdCfy+EzJZeH4dvsdZvDXjcICFtWCLbJdzu6cyl7hloNG oKAeX/U47qkRBe6O3fbUnAkAtEBYm3U1Uwcyynv2EPGrYzV7MLn4NqVY5Je88PywGUiD uBElKxs4L5drWS/9pCL8jLN0wScAFFeRpYVcrG0QsEv0StrMI6+8fDm4yeap29hxj/nL 1Xn0JnVEUylmv8f7t/k7NoFKAd6cRh3GNpqd/uAaW0ISy/afFdY3x/yYCFuutXcgULXa oXOU5ew3tP6FdzoVnjSd+Z3YyOwnPnmMOqHtMWS41+vo78HaYbdLBP4BXaTRjijF9+s8 AJ9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=aK0VXIOh; spf=pass (google.com: domain of linux-kernel+bounces-8320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8320-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p1-20020a0ccb81000000b0067f5182055esi1970924qvk.24.2023.12.21.04.17.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 04:17:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=aK0VXIOh; spf=pass (google.com: domain of linux-kernel+bounces-8320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8320-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D3E921C23397 for ; Thu, 21 Dec 2023 12:17:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 143286E5AA; Thu, 21 Dec 2023 12:17:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="aK0VXIOh" X-Original-To: linux-kernel@vger.kernel.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93A876DD18; Thu, 21 Dec 2023 12:16:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ellerman.id.au DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1703161017; bh=5d6zNSFt4jEG/MYae1GPrrzN7fMvSd5x94D4zOd+D6c=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=aK0VXIOh1FUf/WFEnRpyKYs4nqD8TxQgKtq7oLdJcrqrFilx7c4bHGxWDUWArpQ/u yeRuHu2vA64HoeLWzMFt8tgjIgi1Z3hiRIoRYldrHGIALPDMArjhhC+GZvi54Zx4VB KUurwuLLg53bJR08mREjoj6uzaQqHWjeHIXyhljg50kuV/CtkRoEYTGfNKc9CM37Nm JRiG+DhgFndPHxUulPi4Qth105BFTXoMl6ogoVCj3POzOzL/v1+S3tH2aXNkMufSeL ZderwA/Sffhyz4oztBp/xeUbmzYZWtPKqtF1gV6vz27/Wc2+GlgdSeG3sHhuBySsbZ EDsM120yFYm+A== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SwqDS3CxKz4wby; Thu, 21 Dec 2023 23:16:56 +1100 (AEDT) From: Michael Ellerman To: Christophe Leroy , Nicholas Piggin , Arnd Bergmann , Luis Chamberlain Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-modules@vger.kernel.org, Kees Cook Subject: Re: [PATCH 1/3] init: Declare rodata_enabled and mark_rodata_ro() at all time In-Reply-To: <7b5df1782e94a755b4a18733af44d17d8dd8b37b.1703149011.git.christophe.leroy@csgroup.eu> References: <7b5df1782e94a755b4a18733af44d17d8dd8b37b.1703149011.git.christophe.leroy@csgroup.eu> Date: Thu, 21 Dec 2023 23:16:56 +1100 Message-ID: <87bkajlphj.fsf@mail.lhotse> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Cc +Kees Christophe Leroy writes: > Declaring rodata_enabled and mark_rodata_ro() at all time > helps removing related #ifdefery in C files. > > Signed-off-by: Christophe Leroy > --- > include/linux/init.h | 4 ---- > init/main.c | 21 +++++++-------------- > 2 files changed, 7 insertions(+), 18 deletions(-) > > diff --git a/include/linux/init.h b/include/linux/init.h > index 01b52c9c7526..d2b47be38a07 100644 > --- a/include/linux/init.h > +++ b/include/linux/init.h > @@ -168,12 +168,8 @@ extern initcall_entry_t __initcall_end[]; > > extern struct file_system_type rootfs_fs_type; > > -#if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX) > extern bool rodata_enabled; > -#endif > -#ifdef CONFIG_STRICT_KERNEL_RWX > void mark_rodata_ro(void); > -#endif > > extern void (*late_time_init)(void); > > diff --git a/init/main.c b/init/main.c > index e24b0780fdff..807df08c501f 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -1396,10 +1396,9 @@ static int __init set_debug_rodata(char *str) > early_param("rodata", set_debug_rodata); > #endif > > -#ifdef CONFIG_STRICT_KERNEL_RWX > static void mark_readonly(void) > { > - if (rodata_enabled) { > + if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX) && rodata_enabled) { > /* > * load_module() results in W+X mappings, which are cleaned > * up with call_rcu(). Let's make sure that queued work is > @@ -1409,20 +1408,14 @@ static void mark_readonly(void) > rcu_barrier(); > mark_rodata_ro(); > rodata_test(); > - } else > + } else if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) { > pr_info("Kernel memory protection disabled.\n"); > + } else if (IS_ENABLED(CONFIG_ARCH_HAS_STRICT_KERNEL_RWX)) { > + pr_warn("Kernel memory protection not selected by kernel config.\n"); > + } else { > + pr_warn("This architecture does not have kernel memory protection.\n"); > + } > } > -#elif defined(CONFIG_ARCH_HAS_STRICT_KERNEL_RWX) > -static inline void mark_readonly(void) > -{ > - pr_warn("Kernel memory protection not selected by kernel config.\n"); > -} > -#else > -static inline void mark_readonly(void) > -{ > - pr_warn("This architecture does not have kernel memory protection.\n"); > -} > -#endif > > void __weak free_initmem(void) > { > -- > 2.41.0