Commit 69795cab authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman
Browse files

powerpc: Add framework for Kernel Userspace Protection



This patch adds a skeleton for Kernel Userspace Protection
functionnalities like Kernel Userspace Access Protection and Kernel
Userspace Execution Prevention

The subsequent implementation of KUAP for radix makes use of a MMU
feature in order to patch out assembly when KUAP is disabled or
unsupported. This won't work unless there's an entry point for KUP
support before the feature magic happens, so for PPC64 setup_kup() is
called early in setup.

On PPC32, feature_fixup() is done too early to allow the same.

Suggested-by: default avatarRussell Currey <ruscur@russell.cc>
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 53a712ba
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_POWERPC_KUP_H_
#define _ASM_POWERPC_KUP_H_

#ifndef __ASSEMBLY__

void setup_kup(void);

#endif /* !__ASSEMBLY__ */

#endif /* _ASM_POWERPC_KUP_H_ */
+7 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@
#include <asm/cputhreads.h>
#include <asm/hw_irq.h>
#include <asm/feature-fixups.h>
#include <asm/kup.h>

#include "setup.h"

@@ -331,6 +332,12 @@ void __init early_setup(unsigned long dt_ptr)
	 */
	configure_exceptions();

	/*
	 * Configure Kernel Userspace Protection. This needs to happen before
	 * feature fixups for platforms that implement this using features.
	 */
	setup_kup();

	/* Apply all the dynamic patching */
	apply_feature_fixups();
	setup_feature_keys();
+5 −0
Original line number Diff line number Diff line
@@ -24,6 +24,11 @@
#include <linux/string.h>
#include <asm/pgalloc.h>
#include <asm/pgtable.h>
#include <asm/kup.h>

void __init setup_kup(void)
{
}

#define CTOR(shift) static void ctor_##shift(void *addr) \
{							\
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
#include <asm/tlb.h>
#include <asm/sections.h>
#include <asm/hugetlb.h>
#include <asm/kup.h>

#include "mmu_decl.h"

@@ -178,6 +179,8 @@ void __init MMU_init(void)
	btext_unmap();
#endif

	setup_kup();

	/* Shortly after that, the entire linear mapping will be available */
	memblock_set_current_limit(lowmem_end_addr);
}