Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3348750imu; Wed, 7 Nov 2018 08:58:33 -0800 (PST) X-Google-Smtp-Source: AJdET5cVMD9q2zlbmobWxsGLxFUvHWx4FYRtjgZ1OerWMBQUYIsEV9skR6f1SqTnM/nG6MAjQE41 X-Received: by 2002:a62:c42:: with SMTP id u63-v6mr972459pfi.43.1541609913054; Wed, 07 Nov 2018 08:58:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541609913; cv=none; d=google.com; s=arc-20160816; b=Elq3cvNnVOJPBKzf9jiNO6XmHjuk7SKZ7OhOLDzhyp6OT9SD3euJ+sk8zwNzx1dBQk ZZunDOA2jdv+h5Ov8xc2kQMJw0rJg57dzbzu+ZphlA+hgftb1PAVcWCMP/4YBNtkj/Fv /QGEhPoipkFYXTIGGGl5RXBYROLcQhYGp/Vj+vzieo8YM1xF6QMvp9lfAPfPlQfNsAU7 kCSJkB8xnQzQIAF0SnSHVvrS15TDfI/S4yDUlL701878bFvYW3OM+7qutRZ/owmTDfo8 7ME4IDZckKRHJvTPKPRMtF/BzNa62KLME3ccWDhXGhmcnAj82wQWI/GkqBo7OY0wmdm9 rnVQ== 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=lH0PBYAsO5c4bNaoZJAVrOpXky58hUF/twaUjdQn68w=; b=BVDUMmwzaGnv71U1x635loN5A4zeOEcJ9DAzNZN2Mx/1OpcOc31kIiypEtsK+DkSxI tR3C6l1XHmbNrc4QGIKR8yocNJnXhRwQh0kxXKYTTdn92VVjrlabm6AZRKnb73ejUkaB gNE+nX7a3pQbC2zwk1wP7Pz5i2GZrJNOtmQXscLCt8optcMa89HaGN/G6lxWcpowiWOS E5IU8oIZk3+MuYuA56URMFRFCrlFro026Qo4mk7y9H48/YqkWhWU00v3q/19lIva5swB XtRAtNKTfdXrL7aCS5iD9cZvyiNboXtqV2K011aosRWLwtllt10HokPX8puG3qVFG2n7 LOrA== 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 e127-v6si1198698pfe.8.2018.11.07.08.58.18; Wed, 07 Nov 2018 08:58:33 -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 S1731427AbeKHC1r (ORCPT + 99 others); Wed, 7 Nov 2018 21:27:47 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:42724 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731390AbeKHC1q (ORCPT ); Wed, 7 Nov 2018 21:27:46 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 42qsy72rR0z9tvrX; Wed, 7 Nov 2018 17:56:31 +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 18DOhA3iF70I; Wed, 7 Nov 2018 17:56:31 +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 42qsy726YPz9tvqG; Wed, 7 Nov 2018 17:56:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8CB348B815; Wed, 7 Nov 2018 17:56:33 +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 b_SEwL_l4nEI; Wed, 7 Nov 2018 17:56:33 +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 6C5CF8B814; Wed, 7 Nov 2018 17:56:33 +0100 (CET) Received: by po14163vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 5E9F66995E; Wed, 7 Nov 2018 16:56:33 +0000 (UTC) Message-Id: <5c67ca9dd43b4d94b52bdd30ca481c3897e7c2b2.1541568128.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [RFC PATCH v1 4/6] powerpc/8xx: Add 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:33 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds Kernel Userspace Execution Prevention on the 8xx. When a page is Executable, it is set Executable for Key 0 and NX for Key 1. Up to now, the User group is defined with Key 0 for both User and Supervisor. By changing the group to Key 0 for User and Key 1 for Supervisor, this patch prevents the Kernel from being able to execute user code. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/mmu-8xx.h | 6 ++++++ arch/powerpc/mm/8xx_mmu.c | 10 ++++++++++ arch/powerpc/platforms/Kconfig.cputype | 1 + 3 files changed, 17 insertions(+) diff --git a/arch/powerpc/include/asm/mmu-8xx.h b/arch/powerpc/include/asm/mmu-8xx.h index fa05aa566ece..53dbf0788fce 100644 --- a/arch/powerpc/include/asm/mmu-8xx.h +++ b/arch/powerpc/include/asm/mmu-8xx.h @@ -41,6 +41,12 @@ */ #define MI_APG_INIT 0x44444444 +/* + * 0 => No user => 01 (all accesses performed according to page definition) + * 1 => User => 10 (all accesses performed according to swaped page definition) + */ +#define MI_APG_KUEP 0x66666666 + /* The effective page number register. When read, contains the information * about the last instruction TLB miss. When MI_RPN is written, bits in * this register are used to create the TLB entry. diff --git a/arch/powerpc/mm/8xx_mmu.c b/arch/powerpc/mm/8xx_mmu.c index 01b7f5107c3a..597d3bd2d9b5 100644 --- a/arch/powerpc/mm/8xx_mmu.c +++ b/arch/powerpc/mm/8xx_mmu.c @@ -194,3 +194,13 @@ void flush_instruction_cache(void) mtspr(SPRN_IC_CST, IDC_INVALL); isync(); } + +void setup_kuep(bool disabled) +{ + if (disabled) + return; + + pr_warn("Activating Kernel Userspace Execution Prevention\n"); + + mtspr(SPRN_MI_AP, MI_APG_KUEP); +} diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index 70830cb3c18a..bbcae320324c 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -33,6 +33,7 @@ config PPC_8xx bool "Freescale 8xx" select FSL_SOC select SYS_SUPPORTS_HUGETLBFS + select PPC_HAVE_KUEP config 40x bool "AMCC 40x" -- 2.13.3