Skip to content

Commit

Permalink
powerpc/32s: Initialise KUAP and KUEP in C
Browse files Browse the repository at this point in the history
In order to selectively activate KUAP and KUEP in a following patch,
perform KUAP and KUEP initialisation in C.

Unlike PPC64, PPC32 doesn't have an early_setup_secondary(),
so do it in start_secondary().

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/87be72023448dd4e476744ed279b8c04b8d08a1c.1622708530.git.christophe.leroy@csgroup.eu
  • Loading branch information
Christophe Leroy authored and Michael Ellerman committed Jun 16, 2021
1 parent 882136f commit 86f46f3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 0 additions & 6 deletions arch/powerpc/kernel/head_book3s_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -934,12 +934,6 @@ _GLOBAL(load_segment_registers)
li r0, NUM_USER_SEGMENTS /* load up user segment register values */
mtctr r0 /* for context 0 */
li r3, 0 /* Kp = 0, Ks = 0, VSID = 0 */
#ifdef CONFIG_PPC_KUEP
oris r3, r3, SR_NX@h /* Set Nx */
#endif
#ifdef CONFIG_PPC_KUAP
oris r3, r3, SR_KS@h /* Set Ks */
#endif
li r4, 0
3: mtsrin r3, r4
addi r3, r3, 0x111 /* increment VSID */
Expand Down
4 changes: 4 additions & 0 deletions arch/powerpc/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,10 @@ void start_secondary(void *unused)
{
unsigned int cpu = raw_smp_processor_id();

/* PPC64 calls setup_kup() in early_setup_secondary() */
if (IS_ENABLED(CONFIG_PPC32))
setup_kup();

mmgrab(&init_mm);
current->active_mm = &init_mm;

Expand Down
6 changes: 6 additions & 0 deletions arch/powerpc/mm/book3s32/kuap.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include <asm/kup.h>
#include <asm/smp.h>

void __init setup_kuap(bool disabled)
{
kuap_update_sr(mfsr(0) | SR_KS, 0, TASK_SIZE);

if (smp_processor_id() != boot_cpuid)
return;

pr_info("Activating Kernel Userspace Access Protection\n");

if (disabled)
Expand Down
6 changes: 6 additions & 0 deletions arch/powerpc/mm/book3s32/kuep.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include <asm/kup.h>
#include <asm/smp.h>

void __init setup_kuep(bool disabled)
{
kuep_lock();

if (smp_processor_id() != boot_cpuid)
return;

pr_info("Activating Kernel Userspace Execution Prevention\n");

if (disabled)
Expand Down

0 comments on commit 86f46f3

Please sign in to comment.