RISC-V: Fix .init section permission update
authorAtish Patra <atish.patra@wdc.com>
Fri, 29 Jan 2021 19:00:36 +0000 (11:00 -0800)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Wed, 3 Feb 2021 02:35:42 +0000 (18:35 -0800)
.init section permission should only updated to non-execute if
STRICT_KERNEL_RWX is enabled. Otherwise, this will lead to a kernel hang.

Fixes: 19a00869028f ("RISC-V: Protect all kernel sections including init early")
Cc: stable@vger.kernel.org
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/kernel/setup.c

index 3fa3f26dde85664a6ccd993d9ee3bdcdf118eee3..c7c0655dd45b0f617a34d89b315e5829638c43af 100644 (file)
@@ -293,6 +293,8 @@ void free_initmem(void)
        unsigned long init_begin = (unsigned long)__init_begin;
        unsigned long init_end = (unsigned long)__init_end;
 
-       set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+       if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
+               set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+
        free_initmem_default(POISON_FREE_INITMEM);
 }