From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yu-cheng Yu Subject: Re: [PATCH] binfmt_elf: Extract .note.gnu.property from an ELF file Date: Thu, 02 May 2019 08:47:06 -0700 Message-ID: <5b2c6cee345e00182e97842ae90c02cdcd830135.camel@intel.com> References: <20190501211217.5039-1-yu-cheng.yu@intel.com> <20190502111003.GO3567@e103592.cambridge.arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20190502111003.GO3567@e103592.cambridge.arm.com> Sender: linux-kernel-owner@vger.kernel.org To: Dave Martin Cc: 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 , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pa List-Id: linux-arch.vger.kernel.org On Thu, 2019-05-02 at 12:10 +0100, Dave Martin wrote: > On Wed, May 01, 2019 at 02:12:17PM -0700, Yu-cheng Yu wrote: > > An ELF file's .note.gnu.property indicates features the executable file > > can support. For example, the property GNU_PROPERTY_X86_FEATURE_1_AND > > indicates the file supports GNU_PROPERTY_X86_FEATURE_1_IBT and/or > > GNU_PROPERTY_X86_FEATURE_1_SHSTK. [...] > A couple of questions before I look in more detail: > > 1) Can we rely on PT_GNU_PROPERTY being present in the phdrs to describe > the NT_GNU_PROPERTY_TYPE_0 note? If so, we can avoid trying to parse > irrelevant PT_NOTE segments. Some older linkers can create multiples of NT_GNU_PROPERTY_TYPE_0. The code scans all PT_NOTE segments to ensure there is only one NT_GNU_PROPERTY_TYPE_0. If there are multiples, then all are considered invalid. > > > 2) Are there standard types for things like the program property header? > If not, can we add something in elf.h? We should try to coordinate with > libc on that. Something like > > typedef __u32 Elf_Word; > > typedef struct { > Elf_Word pr_type; > Elf_Word pr_datasz; > } Elf_Gnu_Prophdr; > > (i.e., just the header part from [1], with a more specific name -- which > I just made up). Yes, I will fix that. [...] > 3) It looks like we have to go and re-parse all the notes for every > property requested by the arch code. As explained above, it is necessary to scan all PT_NOTE segments. But there should be only one NT_GNU_PROPERTY_TYPE_0 in an ELF file. Once that is found, perhaps we can store it somewhere, or call into the arch code as you mentioned below. I will look into that. > > For now there is only one property requested anyway, so this is probably > not too bad. But could we flip things around so that we have some > CONFIG_ARCH_WANTS_ELF_GNU_PROPERTY (say), and have the ELF core code > call into the arch backend for each property found? > > The arch could provide some hook > > int arch_elf_has_gnu_property(const Elf_Gnu_Prophdr *prop, > const void *data); > > to consume the properties as they are found. > > This would effectively replace the arch_setup_property() hook you > currently have. > > Cheers > ---Dave > > [1] https://github.com/hjl-tools/linux-abi/wiki/Linux-Extensions-to-gABI From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com ([192.55.52.43]:43578 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbfEBPyf (ORCPT ); Thu, 2 May 2019 11:54:35 -0400 Message-ID: <5b2c6cee345e00182e97842ae90c02cdcd830135.camel@intel.com> Subject: Re: [PATCH] binfmt_elf: Extract .note.gnu.property from an ELF file From: Yu-cheng Yu Date: Thu, 02 May 2019 08:47:06 -0700 In-Reply-To: <20190502111003.GO3567@e103592.cambridge.arm.com> References: <20190501211217.5039-1-yu-cheng.yu@intel.com> <20190502111003.GO3567@e103592.cambridge.arm.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Dave Martin Cc: 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 , 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 , Szabolcs Nagy , libc-alpha@sourceware.org Message-ID: <20190502154706.K9vp60_SReEEkFqb33mxNM6QuFl2yZ8to8IHr1OO2Lg@z> On Thu, 2019-05-02 at 12:10 +0100, Dave Martin wrote: > On Wed, May 01, 2019 at 02:12:17PM -0700, Yu-cheng Yu wrote: > > An ELF file's .note.gnu.property indicates features the executable file > > can support. For example, the property GNU_PROPERTY_X86_FEATURE_1_AND > > indicates the file supports GNU_PROPERTY_X86_FEATURE_1_IBT and/or > > GNU_PROPERTY_X86_FEATURE_1_SHSTK. [...] > A couple of questions before I look in more detail: > > 1) Can we rely on PT_GNU_PROPERTY being present in the phdrs to describe > the NT_GNU_PROPERTY_TYPE_0 note? If so, we can avoid trying to parse > irrelevant PT_NOTE segments. Some older linkers can create multiples of NT_GNU_PROPERTY_TYPE_0. The code scans all PT_NOTE segments to ensure there is only one NT_GNU_PROPERTY_TYPE_0. If there are multiples, then all are considered invalid. > > > 2) Are there standard types for things like the program property header? > If not, can we add something in elf.h? We should try to coordinate with > libc on that. Something like > > typedef __u32 Elf_Word; > > typedef struct { > Elf_Word pr_type; > Elf_Word pr_datasz; > } Elf_Gnu_Prophdr; > > (i.e., just the header part from [1], with a more specific name -- which > I just made up). Yes, I will fix that. [...] > 3) It looks like we have to go and re-parse all the notes for every > property requested by the arch code. As explained above, it is necessary to scan all PT_NOTE segments. But there should be only one NT_GNU_PROPERTY_TYPE_0 in an ELF file. Once that is found, perhaps we can store it somewhere, or call into the arch code as you mentioned below. I will look into that. > > For now there is only one property requested anyway, so this is probably > not too bad. But could we flip things around so that we have some > CONFIG_ARCH_WANTS_ELF_GNU_PROPERTY (say), and have the ELF core code > call into the arch backend for each property found? > > The arch could provide some hook > > int arch_elf_has_gnu_property(const Elf_Gnu_Prophdr *prop, > const void *data); > > to consume the properties as they are found. > > This would effectively replace the arch_setup_property() hook you > currently have. > > Cheers > ---Dave > > [1] https://github.com/hjl-tools/linux-abi/wiki/Linux-Extensions-to-gABI