powerpc/vmlinux.lds: Add an explicit symbol for the SRWX boundary
authorMichael Ellerman <mpe@ellerman.id.au>
Fri, 16 Sep 2022 04:41:24 +0000 (14:41 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 26 Sep 2022 10:58:16 +0000 (20:58 +1000)
Currently __init_begin is used as the boundary for strict RWX between
executable/read-only text and data, and non-executable (after boot) code
and data.

But that's a little subtle, so add an explicit symbol to document that
the SRWX boundary lies there, and add a comment making it clear that
__init_begin must also begin there.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220916131422.318752-2-mpe@ellerman.id.au
arch/powerpc/include/asm/sections.h
arch/powerpc/kernel/vmlinux.lds.S
arch/powerpc/mm/book3s32/mmu.c
arch/powerpc/mm/book3s64/radix_pgtable.c

index babda2677b30b597e0a19379aca495dfb88ce670..9c00c9c0ca8f1724cf575c5f0301cfd852fefb2d 100644 (file)
@@ -13,6 +13,7 @@ typedef struct func_desc func_desc_t;
 #include <asm-generic/sections.h>
 
 extern char __head_end[];
+extern char __srwx_boundary[];
 
 /* Patch sites */
 extern s32 patch__call_flush_branch_caches1;
index dacf8b4302d91ae688aed2733f6b56e3fd360a20..29d891329856be11152e961b9db4c0ce4856a9f7 100644 (file)
@@ -214,11 +214,16 @@ SECTIONS
        }
 #endif
 
+       /*
+        * Various code relies on __init_begin being at the strict RWX boundary.
+        */
+       . = ALIGN(STRICT_ALIGN_SIZE);
+       __srwx_boundary = .;
+       __init_begin = .;
+
 /*
  * Init sections discarded at runtime
  */
-       . = ALIGN(STRICT_ALIGN_SIZE);
-       __init_begin = .;
        .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
                _sinittext = .;
                INIT_TEXT
index a96b73006dfb1481d99f8128ed9f9375482dbcd2..250d174459d4c934b0f6fb9431f0b7277361753d 100644 (file)
@@ -158,7 +158,7 @@ static unsigned long __init __mmu_mapin_ram(unsigned long base, unsigned long to
 unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top)
 {
        unsigned long done;
-       unsigned long border = (unsigned long)__init_begin - PAGE_OFFSET;
+       unsigned long border = (unsigned long)__srwx_boundary - PAGE_OFFSET;
        unsigned long size;
 
        size = roundup_pow_of_two((unsigned long)_einittext - PAGE_OFFSET);
index 698274109c91f39a1c28468c310d0bbbd2eb42c0..9f880f91f584db5b252e3e6cf7b29997b1022e8c 100644 (file)
@@ -259,8 +259,8 @@ print_mapping(unsigned long start, unsigned long end, unsigned long size, bool e
 static unsigned long next_boundary(unsigned long addr, unsigned long end)
 {
 #ifdef CONFIG_STRICT_KERNEL_RWX
-       if (addr < __pa_symbol(__init_begin))
-               return __pa_symbol(__init_begin);
+       if (addr < __pa_symbol(__srwx_boundary))
+               return __pa_symbol(__srwx_boundary);
 #endif
        return end;
 }