]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
powerpc: Add skeleton for Kernel Userspace Execution Prevention
authorChristophe Leroy <christophe.leroy@c-s.fr>
Thu, 18 Apr 2019 06:51:19 +0000 (16:51 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 21 Apr 2019 13:05:56 +0000 (23:05 +1000)
This patch adds a skeleton for Kernel Userspace Execution Prevention.

Then subarches implementing it have to define CONFIG_PPC_HAVE_KUEP
and provide setup_kuep() function.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
[mpe: Don't split strings, use pr_crit_ratelimited()]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Documentation/admin-guide/kernel-parameters.txt
arch/powerpc/include/asm/kup.h
arch/powerpc/mm/fault.c
arch/powerpc/mm/init-common.c
arch/powerpc/platforms/Kconfig.cputype

index 2b8ee90bb64470d0d6d6ccadccf8b8fbbf86509d..a53df74589e52489148641bdb62e4528f0ad4bab 100644 (file)
                        Disable SMAP (Supervisor Mode Access Prevention)
                        even if it is supported by processor.
 
-       nosmep          [X86]
+       nosmep          [X86,PPC]
                        Disable SMEP (Supervisor Mode Execution Prevention)
                        even if it is supported by processor.
 
index 7a88b8b9b54d4b00609e9f687a0b0e711c22bb64..a2a959cb4e367b6ed72663ec01a8065af1538e77 100644 (file)
@@ -6,6 +6,12 @@
 
 void setup_kup(void);
 
+#ifdef CONFIG_PPC_KUEP
+void setup_kuep(bool disabled);
+#else
+static inline void setup_kuep(bool disabled) { }
+#endif /* CONFIG_PPC_KUEP */
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_KUP_H_ */
index 887f11bcf3300a638d15c926ac91b883346fd569..3384354abc1d2f769dc1d8e2a1f5070fdb29fc9d 100644 (file)
@@ -229,11 +229,10 @@ static bool bad_kernel_fault(bool is_exec, unsigned long error_code,
        /* NX faults set DSISR_PROTFAULT on the 8xx, DSISR_NOEXEC_OR_G on others */
        if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT |
                                      DSISR_PROTFAULT))) {
-               printk_ratelimited(KERN_CRIT "kernel tried to execute"
-                                  " exec-protected page (%lx) -"
-                                  "exploit attempt? (uid: %d)\n",
-                                  address, from_kuid(&init_user_ns,
-                                                     current_uid()));
+               pr_crit_ratelimited("kernel tried to execute %s page (%lx) - exploit attempt? (uid: %d)\n",
+                                   address >= TASK_SIZE ? "exec-protected" : "user",
+                                   address,
+                                   from_kuid(&init_user_ns, current_uid()));
        }
        return is_exec || (address >= TASK_SIZE);
 }
index 36d28e87228985982577c71dff2f14626a9f6688..83f95a5565d670239b3b30504e8fdf16ddc0071d 100644 (file)
 #include <asm/pgtable.h>
 #include <asm/kup.h>
 
+static bool disable_kuep = !IS_ENABLED(CONFIG_PPC_KUEP);
+
+static int __init parse_nosmep(char *p)
+{
+       disable_kuep = true;
+       pr_warn("Disabling Kernel Userspace Execution Prevention\n");
+       return 0;
+}
+early_param("nosmep", parse_nosmep);
+
 void __init setup_kup(void)
 {
+       setup_kuep(disable_kuep);
 }
 
 #define CTOR(shift) static void ctor_##shift(void *addr) \
index 842b2c7e156aba4cb2a04d8897fb7aa6128c3b4d..7d30bbbaa3c1a3086a2be40862d0ab9de5c2c259 100644 (file)
@@ -345,6 +345,18 @@ config PPC_RADIX_MMU_DEFAULT
 
          If you're unsure, say Y.
 
+config PPC_HAVE_KUEP
+       bool
+
+config PPC_KUEP
+       bool "Kernel Userspace Execution Prevention"
+       depends on PPC_HAVE_KUEP
+       default y
+       help
+         Enable support for Kernel Userspace Execution Prevention (KUEP)
+
+         If you're unsure, say Y.
+
 config ARCH_ENABLE_HUGEPAGE_MIGRATION
        def_bool y
        depends on PPC_BOOK3S_64 && HUGETLB_PAGE && MIGRATION