Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3348294imu; Wed, 7 Nov 2018 08:58:07 -0800 (PST) X-Google-Smtp-Source: AJdET5dqnvN61eiBrGuwIq10OjDrgRiyCNDaoW4bVO2f8Fx/sNvD0HHLbk1xBMlt4dzVgePGNJRg X-Received: by 2002:a62:1552:: with SMTP id 79-v6mr966402pfv.120.1541609887024; Wed, 07 Nov 2018 08:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541609886; cv=none; d=google.com; s=arc-20160816; b=Uyy1zcV8WMWaja+WiGg9Ncf5v3a/nhuX3L78x7LCWxCPHlg1VPO0DZO+fn/iaGAt8K aMhZoDhBga67OBTmfYURwzgFLGx+43s8DNofzpJ6gySQVHHAnkaWtLGMyp2LQXl0m07P c17/x9yXRiwnGtOuwPNO7r5KmKMPBeaUoX1MJLDg7QV4K2NrWb7kfeoa9Mku0BjDD+We UoCRqT7cOJ19nX9YzS28lxxb1CAuBiWJI6l3e8fhn2ycoMpqgfTQcF2KSaFLXuxFYvku cIimlOkq+/qDrWkWdwLcBXNcG5H6ld14QOF/clxjeCNbMgXJfoMgy6aKa4zD16/Ic/Eg Mzsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=tRzRrq140dwek8c/0uV5qfOcYGo08MTYILt7JwnbvXo=; b=b4x8bQqdkBMHRTyuD5B2tUkLB33xSMCshVAh3s6ERrcezkU48XDpqbSPYQchW4O2vC pGmsdTmBk2iPMpmsrgeKvJb9QEqr4Hns4pZHeCndVOJu59aTqs01cUSSmA2+LZFWFj1b uPj5OLFzVCvOlxfE/vuCX4mwDWJPGi/6xkDxa9CXQYv8XtjAX+yAC25nvp+YMFQonjGM ASNgH+n8mlXFN7oR0qY67umOmZ2rYqs1+T+sTTmoV3hO/ttONUrq3KuAkCLdkvtN31WQ cmXO1aIHFP2ZVaYDuQ/u/UljaRNXgFT4knAnPU6ggWJnzYgrimC+Pbr5M4ok7d3HLlSI 7eAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7-v6si1025826pgn.82.2018.11.07.08.57.51; Wed, 07 Nov 2018 08:58:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731411AbeKHC1q (ORCPT + 99 others); Wed, 7 Nov 2018 21:27:46 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:54055 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727699AbeKHC1o (ORCPT ); Wed, 7 Nov 2018 21:27:44 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 42qsy53WMsz9tvr0; Wed, 7 Nov 2018 17:56:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id CeMppXwPGisB; Wed, 7 Nov 2018 17:56:29 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 42qsy52yNRz9tvqG; Wed, 7 Nov 2018 17:56:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8E3708B815; Wed, 7 Nov 2018 17:56:31 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ekpdvan6Fb7m; Wed, 7 Nov 2018 17:56:31 +0100 (CET) Received: from po14163vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 61FA08B814; Wed, 7 Nov 2018 17:56:31 +0100 (CET) Received: by po14163vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 58DF76995E; Wed, 7 Nov 2018 16:56:31 +0000 (UTC) Message-Id: <1b27e980fa8dda09955b35be09c99bb1e22fef70.1541568127.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [RFC PATCH v1 3/6] powerpc: Add skeleton for Kernel Userspace Execution Prevention To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , ruscur@russell.cc Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:56:31 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Documentation/admin-guide/kernel-parameters.txt | 2 +- arch/powerpc/include/asm/mmu.h | 6 ++++++ arch/powerpc/mm/fault.c | 3 ++- arch/powerpc/mm/init-common.c | 11 +++++++++++ arch/powerpc/platforms/Kconfig.cputype | 12 ++++++++++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 81d1d5a74728..1103549363bb 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2796,7 +2796,7 @@ 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. diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h index 39c51dcba8f4..cf92f2a813a8 100644 --- a/arch/powerpc/include/asm/mmu.h +++ b/arch/powerpc/include/asm/mmu.h @@ -270,6 +270,12 @@ static inline u16 get_mm_addr_key(struct mm_struct *mm, unsigned long address) void setup_kup(void); +#ifdef CONFIG_PPC_KUEP +void setup_kuep(bool disabled); +#else +static inline void setup_kuep(bool disabled) { } +#endif + #endif /* !__ASSEMBLY__ */ /* The kernel use the constants below to index in the page sizes array. diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 50e5c790d11e..e57bd46cf25b 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -230,8 +230,9 @@ static bool bad_kernel_fault(bool is_exec, unsigned long error_code, 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) -" + " %s page (%lx) -" "exploit attempt? (uid: %d)\n", + address >= TASK_SIZE ? "exec-protected" : "user", address, from_kuid(&init_user_ns, current_uid())); } diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c index e469814e8290..89c8bd58509e 100644 --- a/arch/powerpc/mm/init-common.c +++ b/arch/powerpc/mm/init-common.c @@ -25,8 +25,19 @@ #include #include +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 setup_kup(void) { + setup_kuep(disable_kuep); } static void pgd_ctor(void *addr) diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index f4e2c5729374..70830cb3c18a 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -351,6 +351,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 -- 2.13.3