Skip to content

Commit

Permalink
powerpc/vmlinux.lds: Add an explicit symbol for the SRWX boundary
Browse files Browse the repository at this point in the history
[ Upstream commit b150a4d ]

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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Stable-dep-of: 111bcb3 ("powerpc/64s/radix: Fix RWX mapping with relocated kernel")
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
mpe authored and gregkh committed Feb 24, 2023
1 parent f951b71 commit de82609
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions arch/powerpc/include/asm/sections.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <asm-generic/sections.h>

extern char __head_end[];
extern char __srwx_boundary[];

#ifdef __powerpc64__

Expand Down
9 changes: 7 additions & 2 deletions arch/powerpc/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/mm/book3s32/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/mm/book3s64/radix_pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit de82609

Please sign in to comment.