Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 029d9252 authored by Michael Ellerman's avatar Michael Ellerman
Browse files

powerpc/mm: Mark __init memory no-execute when STRICT_KERNEL_RWX=y



Currently even with STRICT_KERNEL_RWX we leave the __init text marked
executable after init, which is bad.

Add a hook to mark it NX (no-execute) before we free it, and implement
it for radix and hash.

Note that we use __init_end as the end address, not _einittext,
because overlaps_kernel_text() uses __init_end, because there are
additional executable sections other than .init.text between
__init_begin and __init_end.

Tested on radix and hash with:

  0:mon> p $__init_begin
  *** 400 exception occurred

Fixes: 1e0fc9d1 ("powerpc/Kconfig: Enable STRICT_KERNEL_RWX for some configs")
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent fa7f9189
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ static inline int hash__pgd_bad(pgd_t pgd)
}
#ifdef CONFIG_STRICT_KERNEL_RWX
extern void hash__mark_rodata_ro(void);
extern void hash__mark_initmem_nx(void);
#endif

extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
+1 −0
Original line number Diff line number Diff line
@@ -1192,5 +1192,6 @@ static inline const int pud_pfn(pud_t pud)
	BUILD_BUG();
	return 0;
}

#endif /* __ASSEMBLY__ */
#endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@

#ifdef CONFIG_STRICT_KERNEL_RWX
extern void radix__mark_rodata_ro(void);
extern void radix__mark_initmem_nx(void);
#endif

static inline unsigned long __radix_pte_update(pte_t *ptep, unsigned long clr,
+7 −0
Original line number Diff line number Diff line
@@ -80,6 +80,13 @@ unsigned long vmalloc_to_phys(void *vmalloc_addr);

void pgtable_cache_add(unsigned shift, void (*ctor)(void *));
void pgtable_cache_init(void);

#ifdef CONFIG_STRICT_KERNEL_RWX
void mark_initmem_nx(void);
#else
static inline void mark_initmem_nx(void) { }
#endif

#endif /* __ASSEMBLY__ */

#endif /* _ASM_POWERPC_PGTABLE_H */
+1 −0
Original line number Diff line number Diff line
@@ -402,6 +402,7 @@ void __init mem_init(void)
void free_initmem(void)
{
	ppc_md.progress = ppc_printk_progress;
	mark_initmem_nx();
	free_initmem_default(POISON_FREE_INITMEM);
}

Loading