Skip to content

Commit 95902e6

Browse files
chleroympe
authored andcommitted
powerpc/mm: Implement STRICT_KERNEL_RWX on PPC32
This patch implements STRICT_KERNEL_RWX on PPC32. As for CONFIG_DEBUG_PAGEALLOC, it deactivates BAT and LTLB mappings in order to allow page protection setup at the level of each page. As BAT/LTLB mappings are deactivated, there might be a performance impact. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 3184cc4 commit 95902e6

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎arch/powerpc/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ config PPC
176176
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
177177
select HAVE_ARCH_SECCOMP_FILTER
178178
select HAVE_ARCH_TRACEHOOK
179-
select ARCH_HAS_STRICT_KERNEL_RWX if (PPC_BOOK3S_64 && !RELOCATABLE && !HIBERNATION)
179+
select ARCH_HAS_STRICT_KERNEL_RWX if ((PPC_BOOK3S_64 || PPC32) && !RELOCATABLE && !HIBERNATION)
180180
select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
181181
select HAVE_CBPF_JIT if !PPC64
182182
select HAVE_CONTEXT_TRACKING if PPC64

‎arch/powerpc/kernel/vmlinux.lds.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <asm/cache.h>
99
#include <asm/thread_info.h>
1010

11-
#ifdef CONFIG_STRICT_KERNEL_RWX
11+
#if defined(CONFIG_STRICT_KERNEL_RWX) && !defined(CONFIG_PPC32)
1212
#define STRICT_ALIGN_SIZE (1 << 24)
1313
#else
1414
#define STRICT_ALIGN_SIZE PAGE_SIZE

‎arch/powerpc/mm/init_32.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ void __init MMU_setup(void)
113113
__map_without_bats = 1;
114114
__map_without_ltlbs = 1;
115115
}
116+
#ifdef CONFIG_STRICT_KERNEL_RWX
117+
if (rodata_enabled) {
118+
__map_without_bats = 1;
119+
__map_without_ltlbs = 1;
120+
}
121+
#endif
116122
}
117123

118124
/*

‎arch/powerpc/mm/pgtable_32.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <asm/fixmap.h>
3535
#include <asm/io.h>
3636
#include <asm/setup.h>
37+
#include <asm/sections.h>
3738

3839
#include "mmu_decl.h"
3940

@@ -375,6 +376,29 @@ void mark_initmem_nx(void)
375376
change_page_attr(page, numpages, PAGE_KERNEL);
376377
}
377378

379+
#ifdef CONFIG_STRICT_KERNEL_RWX
380+
void mark_rodata_ro(void)
381+
{
382+
struct page *page;
383+
unsigned long numpages;
384+
385+
page = virt_to_page(_stext);
386+
numpages = PFN_UP((unsigned long)_etext) -
387+
PFN_DOWN((unsigned long)_stext);
388+
389+
change_page_attr(page, numpages, PAGE_KERNEL_ROX);
390+
/*
391+
* mark .rodata as read only. Use __init_begin rather than __end_rodata
392+
* to cover NOTES and EXCEPTION_TABLE.
393+
*/
394+
page = virt_to_page(__start_rodata);
395+
numpages = PFN_UP((unsigned long)__init_begin) -
396+
PFN_DOWN((unsigned long)__start_rodata);
397+
398+
change_page_attr(page, numpages, PAGE_KERNEL_RO);
399+
}
400+
#endif
401+
378402
#ifdef CONFIG_DEBUG_PAGEALLOC
379403
void __kernel_map_pages(struct page *page, int numpages, int enable)
380404
{

0 commit comments

Comments
 (0)