Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp919337imu; Wed, 28 Nov 2018 01:30:52 -0800 (PST) X-Google-Smtp-Source: AFSGD/X+mHOtaz2i/ZbOstEe0+4C1eHA9Ns9QIzf3cR89dAqd4+KhUubeqdwGEhZSufokyjSWv/5 X-Received: by 2002:a63:1204:: with SMTP id h4mr32504936pgl.51.1543397452812; Wed, 28 Nov 2018 01:30:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543397452; cv=none; d=google.com; s=arc-20160816; b=0IYnrqBo1hAw/6cM7dM08AhOrLkEFHahEgnQ91K7TrApI2pl0KS2NYfm5K/AGxEr6H GNQD7psLt+Dk5J9Si/FVzK/BBk23T0+9xvKZSfvjkH06GV16UJQP3xdeZw5zr/PK0boE zv/jKZ7nhqs42U8avUQFRaLpvcyHtgscQ7EuSsdSqqHB83BZchvnBa6Hn9EHzP/t8ShS 72nii4JDr5VveA5zawwn6lPaMRPfRBTZ9DqSTcUWoXM3JRlO9tZvRoYBs4zKzeQiQD5J JszLNbL1hZ6Vd/Rju/bk2MjiPsgU3eiu8Js5588SVXDKIA4g/vtD8GM55EIKs/kNg0SS Zj0Q== 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=yoGRdBRC6nB5jm5jNnVmQJ9AgXiIA4HtDzCRBPhP6yg=; b=NPnrfH0tmlChETrMn+yPcRh1RrgrDPm+gwzL0jSNL1UKMoLSQaZ19fAJCHD+vzfdYR DIPb81WGy9fIEJC1fMeMESbXC2BUcFd9CKPhwhPpsvFPeWzlqNqpmHVszBNFK3x/M2hT EJ8+Jn63IHWrIRKHYmqAwVEo8ewvJMDeWrJSm7CXjtToT9BkNlZPqkx/gUBGoVE9alVA fmYhnwEMdcEwqn6/LGvmrjGBEVPLeFjz5wkfC677Pcehixb5SPjyPXBDMr+Z3sYGkO1S 1hHLY/zMcSErlWV3YAzKZn08e/l1F/TGAebhL0mpeNyJJMORLJob2l95Ny1FI6Q7SzQv K15g== 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 j184-v6si7514076pfb.149.2018.11.28.01.30.37; Wed, 28 Nov 2018 01:30:52 -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 S1728045AbeK1U2I (ORCPT + 99 others); Wed, 28 Nov 2018 15:28:08 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:34655 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727616AbeK1U2G (ORCPT ); Wed, 28 Nov 2018 15:28:06 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 434Zzs6JDdz9vBKG; Wed, 28 Nov 2018 10:27:05 +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 eioCN6G33gbZ; Wed, 28 Nov 2018 10:27:05 +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 434Zzs5gVqz9vBK9; Wed, 28 Nov 2018 10:27:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AB8878B85D; Wed, 28 Nov 2018 10:27:06 +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 uIV2XMwDv7Ca; Wed, 28 Nov 2018 10:27:06 +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 907658B853; Wed, 28 Nov 2018 10:27:06 +0100 (CET) Received: by po14163vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 8851469AFA; Wed, 28 Nov 2018 09:27:06 +0000 (UTC) Message-Id: <7260e8d9a642c60d4f4db0e8b66ec485a1f474d5.1543356926.git.christophe.leroy@c-s.fr> 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 02/11] powerpc: Add framework for Kernel Userspace Protection 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:06 +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 Protection functionnalities like Kernel Userspace Access Protection and Kernel Userspace Execution Prevention The subsequent implementation of KUAP for radix makes use of a MMU feature in order to patch out assembly when KUAP is disabled or unsupported. This won't work unless there's an entry point for KUP support before the feature magic happens, so for PPC64 setup_kup() is called early in setup. On PPC32, feature_fixup is done too early to allow the same. Suggested-by: Russell Currey Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/kup.h | 11 +++++++++++ arch/powerpc/kernel/setup_64.c | 7 +++++++ arch/powerpc/mm/init-common.c | 5 +++++ arch/powerpc/mm/init_32.c | 3 +++ 4 files changed, 26 insertions(+) create mode 100644 arch/powerpc/include/asm/kup.h diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h new file mode 100644 index 000000000000..7a88b8b9b54d --- /dev/null +++ b/arch/powerpc/include/asm/kup.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_POWERPC_KUP_H_ +#define _ASM_POWERPC_KUP_H_ + +#ifndef __ASSEMBLY__ + +void setup_kup(void); + +#endif /* !__ASSEMBLY__ */ + +#endif /* _ASM_POWERPC_KUP_H_ */ diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index 236c1151a3a7..771f280a6bf6 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -68,6 +68,7 @@ #include #include #include +#include #include "setup.h" @@ -331,6 +332,12 @@ void __init early_setup(unsigned long dt_ptr) */ configure_exceptions(); + /* + * Configure Kernel Userspace Protection. This needs to happen before + * feature fixups for platforms that implement this using features. + */ + setup_kup(); + /* Apply all the dynamic patching */ apply_feature_fixups(); setup_feature_keys(); diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c index 2b656e67f2ea..a72bbfc3add6 100644 --- a/arch/powerpc/mm/init-common.c +++ b/arch/powerpc/mm/init-common.c @@ -24,6 +24,11 @@ #include #include #include +#include + +void __init setup_kup(void) +{ +} static void pgd_ctor(void *addr) { diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c index 3e59e5d64b01..93cfa8cf015d 100644 --- a/arch/powerpc/mm/init_32.c +++ b/arch/powerpc/mm/init_32.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "mmu_decl.h" @@ -182,6 +183,8 @@ void __init MMU_init(void) btext_unmap(); #endif + setup_kup(); + /* Shortly after that, the entire linear mapping will be available */ memblock_set_current_limit(lowmem_end_addr); } -- 2.13.3