Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3585738imb; Tue, 5 Mar 2019 13:22:03 -0800 (PST) X-Google-Smtp-Source: APXvYqyailBMK8CsP4ug0RlT9ZfwFz+yOq13lnsyNSJQDyMs791X1yeHgRbOBKmVX7BBFCORSz+m X-Received: by 2002:a63:f753:: with SMTP id f19mr3136205pgk.437.1551820923821; Tue, 05 Mar 2019 13:22:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551820923; cv=none; d=google.com; s=arc-20160816; b=nz5er81Dgbo27cb9hk9prUkG+Z2YyMNZc7LalaDHb0qn5rBw2Vg5N3N7VxGExHqOuJ kaq3sxvpHo5mqphXsWx32yWyL4yy2Yhk/PHMvaIfjEmq3nQYkNVHC31UaUzrjJhEOCMa X0AcnmZET5sKVZQhH+zMHsjPGzAWiKNEWFStDiRwsX59Mh0DfBKgIi3Sbzwjcw1G0a4D pvc8sk8/YixsuNShD7+7UcrtSYvcp74whEUQ5XAel4LY7ir6tup3MWHnxC5s+oUlG8H9 1rs6avdkhSNLAHxDWxhN7qEZcW0GIN2c7M09y0RpfNmgY/a3t58XJYDuKUuqQQ0vlGbF mfWw== 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:dkim-signature; bh=J2snRjsJwZQgUxCze7YuCoxtC4D3rNW9vbqso4nGn0o=; b=Vb3dzg0XeXOGfcCk029AvvmY8oshv/ndmUr0uc679CYy9bqCkIuGGdopsqATYeWpF3 HAQzY5XoB4FfZg8T/ctTDh2n8R7rQR2kA00j4iLDuHTYaCLG+lvCmefzUUMgzTLmYOwa O80HGwpin9Sv5/UWYEWckGKZyXDf5rLJrUz2uxjvGGpk+3bRk3P/LB6dVc+Q7gtifVmp y6A6/2dFh27zDzAKkfHrsocvqS/wPTcg6/T7hqjU1wD1TYBoRqJH9ThAlwG9fApl5oyD 9HryEwdchrQts9Odwn3nDajBMVaC6rxYk08E+jmG1zYvLPfawu9mKVXIC+7rsOz49gwz v7TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=buK9qt5k; 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 c6si9015459plr.166.2019.03.05.13.21.48; Tue, 05 Mar 2019 13:22:03 -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; dkim=pass header.i=@c-s.fr header.s=mail header.b=buK9qt5k; 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 S1728875AbfCEVSp (ORCPT + 99 others); Tue, 5 Mar 2019 16:18:45 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:7459 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727253AbfCEVST (ORCPT ); Tue, 5 Mar 2019 16:18:19 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44DV9j1yQ3z9v6LV; Tue, 5 Mar 2019 22:18:17 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=buK9qt5k; dkim-adsp=pass; dkim-atps=neutral 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 pmbhqQvpZHN4; Tue, 5 Mar 2019 22:18:17 +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 44DV9j0Y8pz9v6LR; Tue, 5 Mar 2019 22:18:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551820697; bh=J2snRjsJwZQgUxCze7YuCoxtC4D3rNW9vbqso4nGn0o=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=buK9qt5k8EZndPM+wO/mXVGwn8oNrps4QCJLijRYVBoBa+It4/sxNeY4Yz7lGdTIL VBz82rg1ZVnR2c6GsqLChPvfsGiCBwh5QjrHnqvprm1cVruW93ooXMLa+LLLz9RQEj 59DOEv0OJdQ48qkZzDyPweLT3Q+/aiAXfi34s97Y= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3D8808B860; Tue, 5 Mar 2019 22:18:17 +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 urgTIgCn6E3N; Tue, 5 Mar 2019 22:18:17 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 123BA8B83A; Tue, 5 Mar 2019 22:18:17 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id C95336F8CD; Tue, 5 Mar 2019 21:18:16 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH 3/7] 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: Tue, 5 Mar 2019 21:18:16 +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/nohash/32/mmu-8xx.h | 7 +++++++ arch/powerpc/mm/8xx_mmu.c | 12 ++++++++++++ arch/powerpc/platforms/Kconfig.cputype | 1 + 3 files changed, 20 insertions(+) diff --git a/arch/powerpc/include/asm/nohash/32/mmu-8xx.h b/arch/powerpc/include/asm/nohash/32/mmu-8xx.h index fc5a653d5dd2..3cb743284e09 100644 --- a/arch/powerpc/include/asm/nohash/32/mmu-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/mmu-8xx.h @@ -41,6 +41,13 @@ */ #define MI_APG_INIT 0x4fffffff +/* + * 0 => Kernel => 01 (all accesses performed according to page definition) + * 1 => User => 10 (all accesses performed according to swaped page definition) + * 2-16 => NA => 11 (all accesses performed as user iaw page definition) + */ +#define MI_APG_KUEP 0x6fffffff + /* 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 fe1f6443d57f..e257a0c9bd08 100644 --- a/arch/powerpc/mm/8xx_mmu.c +++ b/arch/powerpc/mm/8xx_mmu.c @@ -213,3 +213,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 5e53b9fd62aa..08966e3127bb 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -34,6 +34,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