How can I change the CONFIG_ARCH_OPTIONAL_KERNEL_RWX value? by changing arch/Kconfig file directly?

518 Views Asked by At

I had asked a quesion at kernelnewbies email list and later I thought I found the answer (I thought I can put it in my defconfig). But then later found it was my mistake. So I still have the question and I ask it here to get answer.
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. The 'Visible if' descriptionn says this option is visible when ARCH_OPTIONAL_KERNEL_RWX is =y which is now =n. (The STRICT_KERNEL_RWX menu didn't appear as a configurable menu in the menuconfig at this time). This is the lines in arch/Kconfig.

config ARCH_OPTIONAL_KERNEL_RWX
    def_bool n

So I modified to ARCH_OPTIONAL_KERNEL_RWX=y in arch/Kconfig line 928. (BTW, This is question : 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 that CONFIG_STRICT_KERNEL_RWX=n, the above lines are not compiled here (CONFIG_STRICT_MODULE_RWX=n too). However, 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.
So again my question is how should I change ARCH_OPTIONAL_KERNEL_RWX value? I tried setting it in my defconfig file but when I do make xxx_defonfig, the .config file shows still ARCH_OPTIONAL_KERNEL_RWX=n. Should I edit the arch/Kconfig file really?

0

There are 0 best solutions below