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 677A5C433EF for ; Fri, 18 Mar 2022 06:04:08 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nV5iQ-0006q4-9L; Fri, 18 Mar 2022 02:03:58 -0400 Received: from mscreen.etri.re.kr ([129.254.9.16]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (Exim 4.94.2) (envelope-from ) id 1nV5iM-0006pb-VF for kernelnewbies@kernelnewbies.org; Fri, 18 Mar 2022 02:03:55 -0400 Received: from unknown (HELO send002-relay.gov-dooray.com) (211.180.235.153) by 129.254.9.16 with ESMTP; 18 Mar 2022 15:03:50 +0900 X-Original-SENDERIP: 211.180.235.153 X-Original-MAILFROM: ckim@etri.re.kr X-Original-RCPTTO: kernelnewbies@kernelnewbies.org Received: from [10.162.225.106] (HELO smtp001-imp.gov-dooray.com) ([10.162.225.106]) by send002-relay.gov-dooray.com with SMTP id a185890f623420c6; Fri, 18 Mar 2022 15:03:50 +0900 DKIM-Signature: a=rsa-sha256; b=jBGMrkdUmYE8+L0gXDj+VnFf9powurfZSSIelIEv+saJXhuoiMjzUOkYmVAE/E6p8vJmfQuJMS V+SNHuduZbNvFDTdGCJefhGwOXccH1w++bzLtiGjDVls3mjhMv0hEJ4jEI1/RgB16AFxQ2vGHhRc xS9cO/9geAvGeY0B3T5FqNhQPdCJ5c+ihAYmZVstS9EEGp43SmUYY89hGSaHdpLBvR5E/LpNPQl6 /wqJWZW955AARglZWEhHFiUsUyjv/1CavjqjnyNaykKCViSHSKZqc2qZhUPCWX4f87eMyYGja8FB B3UbuN85mQ81OGffmKqbtIpB5WfmCZ0sZOPvECXw==; c=relaxed/relaxed; s=selector; d=dooray.com; v=1; bh=sziiZUxfjbnwkFhVD0akxtkn0OUiyXjRIZ7o1NCeZpQ=; h=From:To:Subject:Message-ID; Received: from [129.254.132.39] (HELO CHANKIMPC) ([129.254.132.39]) by smtp001-imp.gov-dooray.com with SMTP id c7bcb4a0623420c5; Fri, 18 Mar 2022 15:03:50 +0900 From: "Chan Kim" To: Subject: arm64 code looking for variable rodata_enabled when STRICT_KERNEL_RWX = n Date: Fri, 18 Mar 2022 15:03:46 +0900 Message-ID: <0b3f01d83a8d$ee6b5180$cb41f480$@etri.re.kr> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Content-Language: ko Thread-Index: Adg6jahT52MN2+8KTPqzoHWEstJVow== 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="===============4216444835908483390==" Errors-To: kernelnewbies-bounces@kernelnewbies.org This is a multipart message in MIME format. --===============4216444835908483390== Content-Type: multipart/alternative; boundary="----=_NextPart_000_0B40_01D83AD9.5E548020" Content-Language: ko This is a multipart message in MIME format. ------=_NextPart_000_0B40_01D83AD9.5E548020 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hello all, This is what I see when I search "KERNEL_RWX" during "make menuconfig" 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 [=n] Type : bool Defined at arch/Kconfig:928 Symbol: ARCH_OPTIONAL_KERNEL_RWX_DEFAULT [=n] Type : bool Defined at arch/Kconfig:931 Symbol: STRICT_KERNEL_RWX [=y] Type : bool Defined at arch/Kconfig:937 Prompt: Make kernel text and rodata read-only Depends on: ARCH_HAS_STRICT_KERNEL_RWX [=y] Visible if: ARCH_HAS_STRICT_KERNEL_RWX [=y] && ARCH_OPTIONAL_KERNEL_RWX [=n] Location: (1) -> General architecture-dependent options I wanted to try setting STRICT_KERNEL_RWX to =n. It says this option is visible when ARCH_OPTIONAL_KERNEL_RWX is =y which is now =n. So I modified to ARCH_OPTIONAL_KERNEL_RWX=y in arch/Kconfig line 928. (BTW, is it correct to modify this Kconfig file directly? I'm not sure at the moment) Then I could see the STRICT_KERNEL_RWX menu in the menuconfig and I set it to =n as I wanted. But when I build the kernel, I see this errors. 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 = 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 = 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 = 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 "rodata_enabled" is defined in init/main.c as below. #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX) 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 But now since CONFIG_STRICT_KERNEL_RWX=n, it is not defined here(CONFIG_STRICT_MODULE_RWX=n 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 CONFIG values and make the errors go away, but I'm curious if this a kind of kernel bug raising compiler error. Any comment will be really appreciated. Thank you! Chan Kim ------=_NextPart_000_0B40_01D83AD9.5E548020 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable

Hello all,

This is what I see when I search = “KERNEL_RWX” during “make menuconfig” 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: &nb= sp;

     (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. =

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’m not sure = at the moment)  

Then I could see the STRICT_KERNEL_RWX menu in the = menuconfig and I set it to =3Dn as I wanted.  =

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

 

    = 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);

          = |            =             &= nbsp;   ^~~~~~~~~~~~~~

    = 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 “rodata_enabled” is defined in = init/main.c as below.

 

    #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 = CONFIG values and make the errors go away, but I’m curious if this = a kind of kernel bug raising compiler error.

Any comment will be really = appreciated.

Thank you!

 

Chan Kim

 

------=_NextPart_000_0B40_01D83AD9.5E548020-- --===============4216444835908483390== 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 --===============4216444835908483390==--