Skip to content

Commit 86f46f3

Browse files
chleroympe
authored andcommitted
powerpc/32s: Initialise KUAP and KUEP in C
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 <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/87be72023448dd4e476744ed279b8c04b8d08a1c.1622708530.git.christophe.leroy@csgroup.eu
1 parent 882136f commit 86f46f3

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

arch/powerpc/kernel/head_book3s_32.S

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,6 @@ _GLOBAL(load_segment_registers)
934934
li r0, NUM_USER_SEGMENTS /* load up user segment register values */
935935
mtctr r0 /* for context 0 */
936936
li r3, 0 /* Kp = 0, Ks = 0, VSID = 0 */
937-
#ifdef CONFIG_PPC_KUEP
938-
oris r3, r3, SR_NX@h /* Set Nx */
939-
#endif
940-
#ifdef CONFIG_PPC_KUAP
941-
oris r3, r3, SR_KS@h /* Set Ks */
942-
#endif
943937
li r4, 0
944938
3: mtsrin r3, r4
945939
addi r3, r3, 0x111 /* increment VSID */

arch/powerpc/kernel/smp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,10 @@ void start_secondary(void *unused)
15411541
{
15421542
unsigned int cpu = raw_smp_processor_id();
15431543

1544+
/* PPC64 calls setup_kup() in early_setup_secondary() */
1545+
if (IS_ENABLED(CONFIG_PPC32))
1546+
setup_kup();
1547+
15441548
mmgrab(&init_mm);
15451549
current->active_mm = &init_mm;
15461550

arch/powerpc/mm/book3s32/kuap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22

33
#include <asm/kup.h>
4+
#include <asm/smp.h>
45

56
void __init setup_kuap(bool disabled)
67
{
8+
kuap_update_sr(mfsr(0) | SR_KS, 0, TASK_SIZE);
9+
10+
if (smp_processor_id() != boot_cpuid)
11+
return;
12+
713
pr_info("Activating Kernel Userspace Access Protection\n");
814

915
if (disabled)

arch/powerpc/mm/book3s32/kuep.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22

33
#include <asm/kup.h>
4+
#include <asm/smp.h>
45

56
void __init setup_kuep(bool disabled)
67
{
8+
kuep_lock();
9+
10+
if (smp_processor_id() != boot_cpuid)
11+
return;
12+
713
pr_info("Activating Kernel Userspace Execution Prevention\n");
814

915
if (disabled)

0 commit comments

Comments
 (0)