From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yu-cheng Yu Subject: [PATCH v10 23/26] ELF: Introduce arch_setup_elf_property() Date: Wed, 29 Apr 2020 15:07:29 -0700 Message-ID: <20200429220732.31602-24-yu-cheng.yu@intel.com> References: <20200429220732.31602-1-yu-cheng.yu@intel.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: Received: from mga09.intel.com ([134.134.136.24]:61306 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728064AbgD2WI6 (ORCPT ); Wed, 29 Apr 2020 18:08:58 -0400 In-Reply-To: <20200429220732.31602-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 Cc: Yu-cheng Yu An ELF file's .note.gnu.property indicates architecture features of the file. These features are extracted earlier and stored in the struct 'arch_elf_state'. Introduce arch_setup_elf_property() to setup and enable these features. The first use-case of this function is shadow stack. Signed-off-by: Yu-cheng Yu --- fs/binfmt_elf.c | 4 ++++ include/linux/elf.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 327a995ff743..d7a4c0a1245e 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1216,6 +1216,10 @@ static int load_elf_binary(struct linux_binprm *bprm) set_binfmt(&elf_format); + retval = arch_setup_elf_property(&arch_state); + if (retval < 0) + goto out; + #ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES retval = arch_setup_additional_pages(bprm, !!interpreter); if (retval < 0) diff --git a/include/linux/elf.h b/include/linux/elf.h index 7bdc6da160c7..81f2161fa4a8 100644 --- a/include/linux/elf.h +++ b/include/linux/elf.h @@ -78,9 +78,15 @@ static inline int arch_parse_elf_property(u32 type, const void *data, { return 0; } + +static inline int arch_setup_elf_property(struct arch_elf_state *arch) +{ + return 0; +} #else extern int arch_parse_elf_property(u32 type, const void *data, size_t datasz, bool compat, struct arch_elf_state *arch); +extern int arch_setup_elf_property(struct arch_elf_state *arch); #endif #endif /* _LINUX_ELF_H */ -- 2.21.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com ([134.134.136.24]:61306 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728064AbgD2WI6 (ORCPT ); Wed, 29 Apr 2020 18:08:58 -0400 From: Yu-cheng Yu Subject: [PATCH v10 23/26] ELF: Introduce arch_setup_elf_property() Date: Wed, 29 Apr 2020 15:07:29 -0700 Message-ID: <20200429220732.31602-24-yu-cheng.yu@intel.com> In-Reply-To: <20200429220732.31602-1-yu-cheng.yu@intel.com> References: <20200429220732.31602-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 , Weijiang Yang Cc: Yu-cheng Yu Message-ID: <20200429220729.uFOB0l7uVOZhszymIkfM7Kz55HuFJrofYc47uaq9fJE@z> An ELF file's .note.gnu.property indicates architecture features of the file. These features are extracted earlier and stored in the struct 'arch_elf_state'. Introduce arch_setup_elf_property() to setup and enable these features. The first use-case of this function is shadow stack. Signed-off-by: Yu-cheng Yu --- fs/binfmt_elf.c | 4 ++++ include/linux/elf.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 327a995ff743..d7a4c0a1245e 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1216,6 +1216,10 @@ static int load_elf_binary(struct linux_binprm *bprm) set_binfmt(&elf_format); + retval = arch_setup_elf_property(&arch_state); + if (retval < 0) + goto out; + #ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES retval = arch_setup_additional_pages(bprm, !!interpreter); if (retval < 0) diff --git a/include/linux/elf.h b/include/linux/elf.h index 7bdc6da160c7..81f2161fa4a8 100644 --- a/include/linux/elf.h +++ b/include/linux/elf.h @@ -78,9 +78,15 @@ static inline int arch_parse_elf_property(u32 type, const void *data, { return 0; } + +static inline int arch_setup_elf_property(struct arch_elf_state *arch) +{ + return 0; +} #else extern int arch_parse_elf_property(u32 type, const void *data, size_t datasz, bool compat, struct arch_elf_state *arch); +extern int arch_setup_elf_property(struct arch_elf_state *arch); #endif #endif /* _LINUX_ELF_H */ -- 2.21.0