From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Kees Cook <kees@kernel.org>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Arnd Bergmann <arnd@arndb.de>,
Luis Chamberlain <mcgrof@kernel.org>
Cc: "linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-modules@vger.kernel.org" <linux-modules@vger.kernel.org>,
Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH 1/3] init: Declare rodata_enabled and mark_rodata_ro() at all time
Date: Fri, 22 Dec 2023 18:23:16 +0000 [thread overview]
Message-ID: <15e7109f-8362-4216-a56c-f6591a3ebaf9@csgroup.eu> (raw)
In-Reply-To: <D5F308F6-C394-4CC3-9C0C-923EDB055D0D@kernel.org>
Le 22/12/2023 à 06:35, Kees Cook a écrit :
> [Vous ne recevez pas souvent de courriers de kees@kernel.org. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
>
> On December 21, 2023 4:16:56 AM PST, Michael Ellerman <mpe@ellerman.id.au> wrote:
>> Cc +Kees
>>
>> Christophe Leroy <christophe.leroy@csgroup.eu> writes:
>>> Declaring rodata_enabled and mark_rodata_ro() at all time
>>> helps removing related #ifdefery in C files.
>>>
>>> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
>>> ---
>>> 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) {
>
> I think this will break without rodata_enabled actual existing on other architectures. (Only declaration was made visible, not the definition, which is above here and still behind ifdefs?)
The compiler constant-folds IS_ENABLED(CONFIG_STRICT_KERNEL_RWX).
When it is false, the second part is dropped.
Exemple:
bool test(void)
{
if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX) && rodata_enabled)
return true;
else
return false;
}
With CONFIG_STRICT_KERNEL_RWX set, it directly returns the content of
rodata_enabled:
00000160 <test>:
160: 3d 20 00 00 lis r9,0
162: R_PPC_ADDR16_HA rodata_enabled
164: 88 69 00 00 lbz r3,0(r9)
166: R_PPC_ADDR16_LO rodata_enabled
168: 4e 80 00 20 blr
With CONFIG_STRICT_KERNEL_RWX unset, it returns 0 and doesn't reference
rodata_enabled at all:
000000bc <test>:
bc: 38 60 00 00 li r3,0
c0: 4e 80 00 20 blr
Many places in the kernel use this approach to minimise amount of #ifdefs.
Christophe
next prev parent reply other threads:[~2023-12-22 18:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-21 9:02 [PATCH 1/3] init: Declare rodata_enabled and mark_rodata_ro() at all time Christophe Leroy
2023-12-21 9:02 ` [PATCH 2/3] modules: Remove #ifdef CONFIG_STRICT_MODULE_RWX around rodata_enabled Christophe Leroy
2023-12-21 9:02 ` [PATCH 3/3] powerpc: Simplify strict_kernel_rwx_enabled() Christophe Leroy
2023-12-21 12:16 ` [PATCH 1/3] init: Declare rodata_enabled and mark_rodata_ro() at all time Michael Ellerman
2023-12-22 5:35 ` Kees Cook
2023-12-22 18:23 ` Christophe Leroy [this message]
2024-01-29 20:09 ` Luis Chamberlain
2024-01-30 9:16 ` Chen-Yu Tsai
2024-01-30 11:03 ` Christophe Leroy
[not found] ` <CGME20240130174812eucas1p166f62549457fd188fed6ed72b6b4b9cd@eucas1p1.samsung.com>
2024-01-30 17:48 ` Marek Szyprowski
2024-01-30 20:27 ` Luis Chamberlain
2024-01-31 6:53 ` Christophe Leroy
2024-01-31 22:16 ` Luis Chamberlain
2024-01-31 11:58 ` Christophe Leroy
2024-01-31 15:17 ` Marek Szyprowski
2024-01-31 20:07 ` Christophe Leroy
2024-01-31 22:10 ` Marek Szyprowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15e7109f-8362-4216-a56c-f6591a3ebaf9@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=arnd@arndb.de \
--cc=kees@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mcgrof@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).