]> git.baikalelectronics.ru Git - kernel.git/commitdiff
powerpc/32s: Initialise KUAP and KUEP in C
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Thu, 3 Jun 2021 08:41:41 +0000 (08:41 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 16 Jun 2021 14:09:08 +0000 (00:09 +1000)
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
arch/powerpc/kernel/head_book3s_32.S
arch/powerpc/kernel/smp.c
arch/powerpc/mm/book3s32/kuap.c
arch/powerpc/mm/book3s32/kuep.c

index db0e2dc25f862afe51787033768d2bc8891e2a06..0b82672ff7a65ff3ab7355755c21edaff20b4095 100644 (file)
@@ -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 */
index 2e05c783440a33c3ed82bc19486736fb1be615db..820ae31e0231902da99566829eee32de5cc92cd4 100644 (file)
@@ -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;
 
index 1df55392878e0c21f1b6110d22e98fbff9c55db0..5533ed92ab3de4e379add986426c22b79e723195 100644 (file)
@@ -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)
index 919595f47e25f9faaf7e12bc0cb7cfea8c23ef15..3147e2edcf6317a02cfd6a8a2580353faef51552 100644 (file)
@@ -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)