From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yu-cheng Yu Subject: [PATCH v7 23/27] x86/cet/shstk: ELF header parsing of Shadow Stack Date: Thu, 6 Jun 2019 13:06:42 -0700 Message-ID: <20190606200646.3951-24-yu-cheng.yu@intel.com> References: <20190606200646.3951-1-yu-cheng.yu@intel.com> Return-path: In-Reply-To: <20190606200646.3951-1-yu-cheng.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit Cc: Yu-cheng Yu List-Id: linux-arch.vger.kernel.org Look in .note.gnu.property of an ELF file and check if Shadow Stack needs to be enabled for the task. Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu --- arch/x86/Kconfig | 1 + arch/x86/kernel/process_64.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1664918c2c1c..df8b57de75b2 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1928,6 +1928,7 @@ config X86_INTEL_SHADOW_STACK_USER select ARCH_USES_HIGH_VMA_FLAGS select X86_INTEL_CET select ARCH_HAS_SHSTK + select ARCH_USE_GNU_PROPERTY ---help--- Shadow stack provides hardware protection against program stack corruption. Only when all the following are true will an application diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 250e4c4ac6d9..c51df5b4e116 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -828,3 +828,27 @@ unsigned long KSTK_ESP(struct task_struct *task) { return task_pt_regs(task)->sp; } + +#ifdef CONFIG_ARCH_USE_GNU_PROPERTY +int arch_setup_property(void *ehdr, void *phdr, struct file *f, bool inter) +{ + int r; + uint32_t property; + + r = get_gnu_property(ehdr, phdr, f, GNU_PROPERTY_X86_FEATURE_1_AND, + &property); + + memset(¤t->thread.cet, 0, sizeof(struct cet_status)); + + if (r) + return r; + + if (cpu_feature_enabled(X86_FEATURE_SHSTK)) { + if (property & GNU_PROPERTY_X86_FEATURE_1_SHSTK) + r = cet_setup_shstk(); + if (r < 0) + return r; + } + return r; +} +#endif -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com ([192.55.52.151]:47825 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729456AbfFFUPj (ORCPT ); Thu, 6 Jun 2019 16:15:39 -0400 From: Yu-cheng Yu Subject: [PATCH v7 23/27] x86/cet/shstk: ELF header parsing of Shadow Stack Date: Thu, 6 Jun 2019 13:06:42 -0700 Message-ID: <20190606200646.3951-24-yu-cheng.yu@intel.com> In-Reply-To: <20190606200646.3951-1-yu-cheng.yu@intel.com> References: <20190606200646.3951-1-yu-cheng.yu@intel.com> Sender: linux-arch-owner@vger.kernel.org List-ID: To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin Cc: Yu-cheng Yu Message-ID: <20190606200642.jvbOQgBoK4OhsMsOwIyArjmBiNtCbT7_L_96EjnxHxk@z> Look in .note.gnu.property of an ELF file and check if Shadow Stack needs to be enabled for the task. Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu --- arch/x86/Kconfig | 1 + arch/x86/kernel/process_64.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1664918c2c1c..df8b57de75b2 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1928,6 +1928,7 @@ config X86_INTEL_SHADOW_STACK_USER select ARCH_USES_HIGH_VMA_FLAGS select X86_INTEL_CET select ARCH_HAS_SHSTK + select ARCH_USE_GNU_PROPERTY ---help--- Shadow stack provides hardware protection against program stack corruption. Only when all the following are true will an application diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 250e4c4ac6d9..c51df5b4e116 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -828,3 +828,27 @@ unsigned long KSTK_ESP(struct task_struct *task) { return task_pt_regs(task)->sp; } + +#ifdef CONFIG_ARCH_USE_GNU_PROPERTY +int arch_setup_property(void *ehdr, void *phdr, struct file *f, bool inter) +{ + int r; + uint32_t property; + + r = get_gnu_property(ehdr, phdr, f, GNU_PROPERTY_X86_FEATURE_1_AND, + &property); + + memset(¤t->thread.cet, 0, sizeof(struct cet_status)); + + if (r) + return r; + + if (cpu_feature_enabled(X86_FEATURE_SHSTK)) { + if (property & GNU_PROPERTY_X86_FEATURE_1_SHSTK) + r = cet_setup_shstk(); + if (r < 0) + return r; + } + return r; +} +#endif -- 2.17.1