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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Feb 2023 11:06:44 +0000 (12:06 +0100)
[ Upstream commit b150a4d12b919baf956b807aa305cf78df03d0fe ]

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
Stable-dep-of: 111bcb373853 ("powerpc/64s/radix: Fix RWX mapping with relocated kernel")
Signed-off-by: Sasha Levin <sashal@kernel.org>
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 79cb7a25a5fb69cc97b78f8829b961263866974a..e92d39c0cd1d9831d706950baeb148e4845fdfd5 100644 (file)
@@ -9,6 +9,7 @@
 #include <asm-generic/sections.h>
 
 extern char __head_end[];
+extern char __srwx_boundary[];
 
 #ifdef __powerpc64__
 
index bcbe41c6998ca5f518b5b297ec54eaec63050534..a664d0c4344a934bb660ec5e912f71a087a5d7d6 100644 (file)
@@ -208,11 +208,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 bfca0afe911268ba350ace31aab9d40171e10b18..692c336e4f55b6fbf8186e814b52e082d69e5100 100644 (file)
@@ -159,7 +159,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 a339cb5de5dd18fd6307a7768a5dd3b7f43add1f..52e27fd995da7e96d1d662bea16cc27c7bc44326 100644 (file)
@@ -260,8 +260,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;
 }