From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5687C433F5 for ; Sat, 19 Mar 2022 10:24:28 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nVWFi-0002cB-Ej; Sat, 19 Mar 2022 06:24:06 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1nVWFg-0002bz-5a for kernelnewbies@kernelnewbies.org; Sat, 19 Mar 2022 06:24:04 -0400 Received: by mail-lf1-x12a.google.com with SMTP id w27so17626904lfa.5 for ; Sat, 19 Mar 2022 03:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=athQyH6pfrxhsJmD+FoKWS9EzPb0Pylj6pkeBIexXXI=; b=nb3GFXXnPNhwLYrVVEKdiM8CLzo/WZr1icsJecIqEm4DAglRUz8Rc1WKzFbgks5WxE j+3qIyp8DS4IoFfWrKYipwymkz3P5WEEvhsGJ/RzEt+NKkO1Dohbi/My6nKwIEq0YiOA JVYaoXZuLLTd8WIFykbxSc3wE9rnWPkmrYHjjVOSsNDcpPzAi8beo8Bqiw2uQkMWrGi2 lUc/CDa03s+fTbn0fnhrg7gOjx1AQxSLnvqw7yhFbArUvNhzl5HZ4M18O344vVRR9zeE rwblAnVz2JCn41SVtWunNSETlI2PQI7MsnFIXFnct38jQLRSn7R9QGyI0nZ3+WnzWjRb 5lrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=athQyH6pfrxhsJmD+FoKWS9EzPb0Pylj6pkeBIexXXI=; b=mGQ4ILNYZ4w0dl9BE5+xdXeIp97Y0/EVWftN3FTydgzu+/CQ9pNhZRQ7VZ/di5B7rj Yd9PLjkGqmPoao2bjZQDCgxXoGH0byz1CGwph13V/Vdme0btQgsI1ubJEmdUTLoUicoc ToYkaXImZ7bJSsrfpFQ+6n3vGXfik5DyOmbIaR1zntrItnbtD9FvRLctMJNY/NA+CH1F PXWbylmWRwyEYT3aOuNnYPy9vPVwwbZSvwgkHjBRzak/pUXlLA51m4InlwDREPmnl1WH lmJPVwYXO770f+MFF1hf2wVpjW8Tqs2GOgyQiS4E/E+MaRsMvMK9Fgc0uswEPRCwTdef Jd4w== X-Gm-Message-State: AOAM533QcRVq52MfEkw7g5wA4bdMb4Na4UCRPoA+YdAV5WLUctjLL87f K1ef5irxfc+ZBXBz0trIloihn9lRpXgEERMmxC4= X-Google-Smtp-Source: ABdhPJxMbeJgBkSbVNv7JUXTPEPIAK50mMNx67Zk6yfi+TxESGU859QWwV7dRrap9JgyeJK3LuBRa/CTVYj7NPjZ1sw= X-Received: by 2002:a05:6512:3f92:b0:447:769c:1b2c with SMTP id x18-20020a0565123f9200b00447769c1b2cmr8513964lfa.387.1647685440537; Sat, 19 Mar 2022 03:24:00 -0700 (PDT) MIME-Version: 1.0 References: <0b3f01d83a8d$ee6b5180$cb41f480$@etri.re.kr> In-Reply-To: <0b3f01d83a8d$ee6b5180$cb41f480$@etri.re.kr> From: FMDF Date: Sat, 19 Mar 2022 11:23:32 +0100 Message-ID: Subject: Re: arm64 code looking for variable rodata_enabled when STRICT_KERNEL_RWX = n To: Chan Kim Cc: kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============6801062197084739441==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============6801062197084739441== Content-Type: multipart/alternative; boundary="00000000000062882805da8fa905" --00000000000062882805da8fa905 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 18 Mar 2022, 07:04 Chan Kim, wrote: > Hello all, > > This is what I see when I search =E2=80=9CKERNEL_RWX=E2=80=9D during =E2= =80=9Cmake menuconfig=E2=80=9D for > arm64 kernel(5-10.0-rc5). > > The Kconfig file says CONFIG_STRICT_KERNEL_RWX is for setting text and > rodata read-only. > > Symbol: ARCH_OPTIONAL_KERNEL_RWX [=3Dn] > > Type : bool > > Defined at arch/Kconfig:928 > > Symbol: ARCH_OPTIONAL_KERNEL_RWX_DEFAULT [=3Dn] > > Type : bool > > Defined at arch/Kconfig:931 > > > > Symbol: STRICT_KERNEL_RWX [=3Dy] > > Type : bool > > Defined at arch/Kconfig:937 > > Prompt: Make kernel text and rodata read-only > > Depends on: ARCH_HAS_STRICT_KERNEL_RWX [=3Dy] > > Visible if: ARCH_HAS_STRICT_KERNEL_RWX [=3Dy] && > ARCH_OPTIONAL_KERNEL_RWX [=3Dn] > > Location: > > (1) -> General architecture-dependent options > > I wanted to try setting STRICT_KERNEL_RWX to =3Dn. It says this option is > visible when ARCH_OPTIONAL_KERNEL_RWX is =3Dy which is now =3Dn. > Now I'm a bit confused... why do you say that "It says this option is visible when ARCH_OPTIONAL_KERNEL_RWX is =3Dy"? I haven't ever written Kbuild rules but as far as I understand that message "Symbol: STRICT_KERNEL_RWX [=3Dy] [is] Visible if: ARCH_HAS_STRICT_KERNEL_RWX [=3Dy] && ARCH_OPTIONAL_KERNEL_RWX [=3Dn]" seems= to say that we can see and enable/disable STRICT_KERNEL_RWX if and only if ARCH_HAS_STRICT_KERNEL_RWX is set to "yes" AND ARCH_OPTIONAL_KERNEL_RWX is set to "no". Is it me that I'm misunderstanding the above-mentioned message from "make menuconfig"? > So I modified to ARCH_OPTIONAL_KERNEL_RWX=3Dy in arch/Kconfig line 928. > (BTW, is it correct to modify this Kconfig file directly? I=E2=80=99m not= sure at > the moment) > For sure, I'd never do this. Why don't you simply use make menuconfig for enabling/disabling options? Options are strictly interrelated and largely depend on others. Why do you want to bypass dependency checks? > Then I could see the STRICT_KERNEL_RWX menu in the menuconfig and I set i= t > to =3Dn as I wanted. > > But when I build the kernel, I see this errors. > Again, if it's not me that I'm missing something, the following errors are simply explained by your weird way to enable/disable options. Please correct me if I didn't get something that you wrote (I'm very tired now after a long night staying awoke :)) Regards, Fabio M. De Francesco ckim@ckim-ubuntu:~/ProjX/LinuxDevDrv/kernel-release-RD-INFRA-2020.11.30= $ > makeit > > CALL scripts/atomic/check-atomics.sh > > CALL scripts/checksyscalls.sh > > CHK include/generated/compile.h > > CC arch/arm64/mm/mmu.o > > arch/arm64/mm/mmu.c: In function 'parse_rodata': > > arch/arm64/mm/mmu.c:595:28: error: 'rodata_enabled' undeclared (first > use in this function) > > 595 | int ret =3D strtobool(arg, &rodata_enabled); > > | ^~~~~~~~~~~~~~ > > arch/arm64/mm/mmu.c:595:28: note: each undeclared identifier is > reported only once for each function it appears in > > arch/arm64/mm/mmu.c: In function 'map_entry_trampoline': > > arch/arm64/mm/mmu.c:614:18: error: 'rodata_enabled' undeclared (first > use in this function) > > 614 | pgprot_t prot =3D rodata_enabled ? PAGE_KERNEL_ROX : > PAGE_KERNEL_EXEC; > > | ^~~~~~~~~~~~~~ > > arch/arm64/mm/mmu.c: In function 'map_kernel': > > arch/arm64/mm/mmu.c:669:23: error: 'rodata_enabled' undeclared (first > use in this function) > > 669 | pgprot_t text_prot =3D rodata_enabled ? PAGE_KERNEL_ROX : > PAGE_KERNEL_EXEC; > > | ^~~~~~~~~~~~~~ > > make[2]: *** [scripts/Makefile.build:283: arch/arm64/mm/mmu.o] Error = 1 > > make[1]: *** [scripts/Makefile.build:500: arch/arm64/mm] Error 2 > > make: *** [Makefile:1799: arch/arm64] Error 2 > > variable =E2=80=9Crodata_enabled=E2=80=9D is defined in init/main.c as be= low. > > #if defined(CONFIG_STRICT_KERNEL_RWX) || > defined(CONFIG_STRICT_MODULE_RWX) > > bool rodata_enabled __ro_after_init =3D true; > > static int __init set_debug_rodata(char *str) > > { > > return strtobool(str, &rodata_enabled); > > } > > __setup("rodata=3D", set_debug_rodata); > > #endif > > But now since CONFIG_STRICT_KERNEL_RWX=3Dn, it is not defined > here(CONFIG_STRICT_MODULE_RWX=3Dn too). > > and arch/arm64/mm/mmu.c code is still using `rodata_enabled`. Is this a > bug of the code? Or am I missing something? > > I can modify init/main.c and include/linux/init.h so that this > rodata_enabled and related functions be defined regardless of these CONFI= G > values and make the errors go away, but I=E2=80=99m curious if this a kin= d of > kernel bug raising compiler error. > > Any comment will be really appreciated. > > Thank you! > > > > Chan Kim > > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies@kernelnewbies.org > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > --00000000000062882805da8fa905 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, 18 Mar 2022, 07:04 Chan Kim, <ckim@etri.re.kr> wrote:

Hello all,

This is what I see when I search =E2=80=9CKERNEL_RWX=E2=80=9D du= ring =E2=80=9Cmake menuconfig=E2=80=9D for arm64 kernel(5-10.0-rc5).=C2=A0 =

The Kc= onfig file says CONFIG_STRICT_KERNEL_RWX is for setting text and rodata rea= d-only.

=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0Symbol: ARCH_OPTIONAL_KERNEL_RWX [=3Dn]=C2=A0=C2=A0

=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0Type=C2=A0 : bool=C2=A0=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= Defined at arch/Kconfig:928=C2=A0=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0 Symbol: ARCH_OPTIONAL_KERNEL_RWX_D= EFAULT [=3Dn]=C2=A0=C2=A0

<= span lang=3D"DE">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= Type=C2=A0 : bool=C2=A0=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Defined at arch/Kconf= ig:931=C2=A0=C2=A0

=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0 Symbol: STRICT_KERNEL_RWX [=3Dy]=C2= =A0=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Type=C2=A0 : bool=C2=A0=C2=A0 <= /u>

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0Defined at arch/Kconfig:937=C2=A0=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0Prompt: Make kernel text and rodata read-only=C2=A0=C2=A0=

=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Depends on: ARCH_HAS_STRICT_KERNEL_R= WX [=3Dy]=C2=A0=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Visible if: ARCH_= HAS_STRICT_KERNEL_RWX [=3Dy] && ARCH_OPTIONAL_KERNEL_RWX [=3Dn]=C2= =A0=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Location:=C2=A0=C2=A0 =

=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0(1) -> General architecture-dependent options=C2=A0=C2= =A0

I wanted to try s= etting STRICT_KERNEL_RWX to =3Dn. It says this option is visible when ARCH_= OPTIONAL_KERNEL_RWX is =3Dy which is now =3Dn.

Now I'm a bit confused... why do y= ou say that "It says this option is visible when ARCH_OPTIONAL_KERNEL_= RWX is =3Dy"?

I haven't ever written Kbuild rules but as far as I = understand that message=C2=A0 "Symbol: STRICT_KERNEL_RWX [=3Dy] [is] V= isible if: ARCH_HAS_STRICT_KERNEL_RWX [=3Dy] && ARCH_OPTIONAL_KERNE= L_RWX [=3Dn]" seems to say that we can see and enable/disable STRICT_K= ERNEL_RWX if and only if ARCH_HAS_STRICT_KERNEL_RWX is set to "yes&quo= t; AND ARCH_OPTIONAL_KERNEL_RWX is set to "no".

Is it me that I'm misunderstanding th= e above-mentioned message from "make menuconfig"?

<= /u>

So I modified to = ARCH_OPTIONAL_KERNEL_RWX=3Dy in arch/Kconfig line 928. (BTW, is it correct = to modify this Kconfig file directly? I=E2=80=99m not sure at the moment)

For sure, I= 'd never do this. Why don't you simply use make menuconfig for enab= ling/disabling options? Options are strictly interrelated and largely=C2=A0= depend on others. Why do you want to bypass dependency checks?

Then I cou= ld see the STRICT_KERNEL_RWX menu in the menuconfig and I set it to =3Dn as= I wanted.=C2=A0

But when I build the kernel, I see this errors.=C2=A0

=
Again, if it's n= ot me that I'm missing something, the following errors are simply expla= ined by your weird way to enable/disable options.
Please correct me if I didn't get something t= hat you wrote (I'm very tired now after a long night staying awoke :))<= /div>

Regards,

Fabio M. De Francesco

=C2=A0=C2=A0=C2=A0 ckim@ckim-ubuntu:~/ProjX/LinuxDevDrv/ker= nel-release-RD-INFRA-2020.11.30$ makeit

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CALL=C2=A0= =C2=A0=C2=A0 scripts/atomic/check-atomics.sh

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CALL= =C2=A0=C2=A0=C2=A0 scripts/checksyscalls.sh

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CHK=C2= =A0=C2=A0=C2=A0=C2=A0 include/generated/compile.h

<= p class=3D"MsoNormal">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 C= C=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 arch/arm64/mm/mmu.o

=C2=A0=C2=A0=C2=A0 arch/arm64/= mm/mmu.c: In function 'parse_rodata':

=C2=A0=C2=A0=C2=A0 arch/arm64/mm/mmu= .c:595:28: error: 'rodata_enabled' undeclared (first use in this fu= nction)

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 595 |=C2=A0 int ret =3D strtobool(arg, &= ;rodata_enabled);

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ^~~~~~~~~~~~~~

=C2=A0=C2=A0=C2=A0 arch/arm64/mm/mmu.c:595:28: note: each un= declared identifier is reported only once for each function it appears in

=C2=A0= =C2=A0=C2=A0 arch/arm64/mm/mmu.c: In function 'map_entry_trampoline'= ;:

=C2= =A0=C2=A0=C2=A0 arch/arm64/mm/mmu.c:614:18: error: 'rodata_enabled'= undeclared (first use in this function)

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 614 |=C2= =A0 pgprot_t prot =3D rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;<= u>

=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 ^~~~~~~~~~~~~~

=C2=A0=C2=A0=C2=A0 arch/arm64/mm/mmu.c: In function 'map_ke= rnel':

=C2=A0=C2=A0=C2=A0 arch/arm64/mm/mmu.c:669:23: error: 'rodata_enabl= ed' undeclared (first use in this function)

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 669= |=C2=A0 pgprot_t text_prot =3D rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KER= NEL_EXEC;

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^~~~~~~~~~~~~~

=C2=A0=C2=A0=C2=A0 make[= 2]: *** [scripts/Makefile.build:283: arch/arm64/mm/mmu.o] Error 1=

=C2=A0=C2=A0=C2= =A0 make[1]: *** [scripts/Makefile.build:500: arch/arm64/mm] Error 2=

=C2=A0=C2=A0= =C2=A0 make: *** [Makefile:1799: arch/arm64] Error 2

variable =E2=80=9Crodata_enabled=E2=80=9D i= s defined in init/main.c as below.

=C2=A0=C2=A0=C2=A0 #if defined(CONFIG_STRICT_KERNEL_RWX) || d= efined(CONFIG_STRICT_MODULE_RWX)

=C2=A0=C2=A0=C2=A0 bool rodata_enabled __ro_after= _init =3D true;

=C2=A0=C2=A0=C2=A0 static int __init set_debug_rodata(char *str)=

=C2=A0= =C2=A0=C2=A0 {

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return strtobool(str, &a= mp;rodata_enabled);

=C2=A0=C2=A0=C2=A0 }

=C2=A0=C2=A0=C2=A0 __setup("rodata=3D"= , set_debug_rodata);

=C2=A0=C2=A0=C2=A0 #endif

But now since CONFIG_STRICT_KERNEL_RWX=3Dn, it is not de= fined here(CONFIG_STRICT_MODULE_RWX=3Dn too).

and arch/arm64/mm/mmu.c code is sti= ll using `rodata_enabled`. Is this a bug of the code? Or am I missing somet= hing?

I can modify in= it/main.c and include/linux/init.h so that this rodata_enabled and related = functions be defined regardless of these CONFIG values and make the errors = go away, but I=E2=80=99m curious if this a kind of kernel bug raising compi= ler error.

Any comment will be really appreciated.

Thank you!

=C2=A0

Chan Kim

<= p class=3D"MsoNormal">=C2=A0

<= /div>
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies= .org/mailman/listinfo/kernelnewbies
--00000000000062882805da8fa905-- --===============6801062197084739441== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============6801062197084739441==--