Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp917078imu; Wed, 28 Nov 2018 01:28:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/WLzbLT0aNxGZbpb/kEtV6ny3U1Ba1K5UIu+yFVcQZJbnZjj9bTPdtuGJ8GCI09B+t8tu5O X-Received: by 2002:a17:902:6e16:: with SMTP id u22mr35616701plk.175.1543397297124; Wed, 28 Nov 2018 01:28:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543397297; cv=none; d=google.com; s=arc-20160816; b=AybaUwJJNXpPoOM710YxHyeh+Fq5DygY95yCKlYxEfox9NYmUxyPksyE1zB9w7hzrV aFv6rpRNXpn6i3S11GbhpBvW//TcGRLdLv2GgAeFrt5/x6EE6I3PzCDLfSOMCXqycwmq llIEfeEVIL3QhNV/qWNBbQI9iHDtkSx9c4BnZEny7G5mm7X6HObD/lah/HMR6qFt8mhO GDYQRULXPAwnER1bm12dYA2ttGVLKlg6mTC9I7/4CTnMk3E+1YVOatiP7ECmFyz/JSvp GAvXWoLZ4RIFFZ2j10UmE9o6r644B80SSwfCG403tduJNfO2Rbl0LrPX7ftmi60D5wIZ RT/w== 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=zQzsdv26GTgLFCj2lH2l80LS33f4Jc4DUkOV/sJvSaY=; b=L1GnH8ky/VjoHh9syWTryUWtQbo3dApUWByWmhG5nvTO0YfEQ2TDEdmJrss+etzFsz FaOAZiF/yJGlVjTs0IAkVTw6Lx08DxEFGvx6N1c2K0UyU/tz5hD0cYof4kjVjd5jspK2 lZYqSKnyoGlJBfypl2UTRZnHP4x9JAYgAoB6+GAL1vgYjwcdnaXWE+tuSoei9lz0oe3+ DuF5nKyZPEJqSv48X65bAfANH9x88nSaSTp/fFdbe6405nc1yNnx/mh1ga0PySqF9AQn DXHtKoQCZJWlCWxEb8oSlJW/sVrYSAp7SoqBMFdohX4D6o5/D8UwTbJyGgCob9OzQF93 /L3w== 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 o9si7135862pfe.63.2018.11.28.01.28.02; Wed, 28 Nov 2018 01:28:17 -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 S1728134AbeK1U2N (ORCPT + 99 others); Wed, 28 Nov 2018 15:28:13 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:57584 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727676AbeK1U2M (ORCPT ); Wed, 28 Nov 2018 15:28:12 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 434Zzz6jcpz9vBKF; Wed, 28 Nov 2018 10:27:11 +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 0TzUtfh15KXA; Wed, 28 Nov 2018 10:27:11 +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 434Zzz6CCmz9vBK9; Wed, 28 Nov 2018 10:27:11 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C1FFB8B85D; Wed, 28 Nov 2018 10:27:12 +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 VbHt3Dw9gysn; Wed, 28 Nov 2018 10:27:12 +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 AB9318B853; Wed, 28 Nov 2018 10:27:12 +0100 (CET) Received: by po14163vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 992DE69AFA; Wed, 28 Nov 2018 09:27:12 +0000 (UTC) Message-Id: In-Reply-To: <76d777b36e54e7b8d4c196405decc712fc5eaf45.1543356926.git.christophe.leroy@c-s.fr> References: <76d777b36e54e7b8d4c196405decc712fc5eaf45.1543356926.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [RFC PATCH v2 05/11] 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, 28 Nov 2018 09:27:12 +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 | 12 ++++++++++++ arch/powerpc/platforms/Kconfig.cputype | 1 + 3 files changed, 19 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..f14ceb507d98 100644 --- a/arch/powerpc/mm/8xx_mmu.c +++ b/arch/powerpc/mm/8xx_mmu.c @@ -194,3 +194,15 @@ void flush_instruction_cache(void) mtspr(SPRN_IC_CST, IDC_INVALL); isync(); } + +#ifdef CONFIG_PPC_KUEP +void __init setup_kuep(bool disabled) +{ + if (disabled) + return; + + pr_info("Activating Kernel Userspace Execution Prevention\n"); + + mtspr(SPRN_MI_AP, MI_APG_KUEP); +} +#endif diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index 68eaafd54aca..d1757cedf60b 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