Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7424429yba; Thu, 2 May 2019 09:34:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxq6RR93anrZHKKkU1MnOIlc2KJFWrGEnl+ReL+VEuaG/qWNV1VTGzzsOPpgvoAg6TNQTQj X-Received: by 2002:a63:f817:: with SMTP id n23mr5027764pgh.302.1556814879800; Thu, 02 May 2019 09:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556814879; cv=none; d=google.com; s=arc-20160816; b=isgSuLtBx9V2C+EnpPtTQdi0WrmrscSA1mjtrYfQigIhcvsZp+gK0JZRWHGszThtqS kvRPMTzOyKUfVnR+awIWvoHjibXCDG0MkhYRXCwnPr3liyURzgrBBoP1tojDLisfD8Fv Gm0jb2aCeSHsuX1qPDrYmT6/Jiszv4uP3+kNOhdF+dE/0Q5YVZZcdp5HfgYjapk8uM7V RcjsszHviGBY9DDnQcJZTxKVPAF+PP9eqbaNcSQRQKG3DTzlDm7AwXwO4TkzW+OHTrRg s0RwPzACM2yNduYbSqrTsQ37Yaf+e8cD5JMgJfLDY2RdZffihm4n6toiO3nTLXUDUz0W m1XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=vajMcs4PWAXHtSOiyQ0yTUvNz0gHpMKHR6CyxPytvwM=; b=vPbxVlCS/SVyo/yl7USQ3pWmPHAwNJoPhyWoy3sTV21+0+KriSfiP1W3cNtbPgSgmi RW5gx6XYnAPbCyDftcJNA8q0q77w787GYEZwSrro8hXZ+wzmDUQTJv5R8FowGDEy2Hdl h6MBy9c1sXyree6dpMHmVxMNzN4CDQPSYrjb21t9PYYumMoDyx1H0dbJVMnaEKnGkygN sP6MAdIruRRS59hupjZaSojHBuw/ore0571bkGnlEiimQAeaN6aC4pzTlM9kLBAhhoKW lf1JOvmKJ+easikp55+R/q+xLAo1+N64xjeII57K5F/aePY+tkFziixAJKJfDadjX6Al yEhQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q127si32694344pgq.91.2019.05.02.09.34.24; Thu, 02 May 2019 09:34:39 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbfEBQd0 (ORCPT + 99 others); Thu, 2 May 2019 12:33:26 -0400 Received: from mga12.intel.com ([192.55.52.136]:6989 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbfEBQd0 (ORCPT ); Thu, 2 May 2019 12:33:26 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 May 2019 09:33:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,422,1549958400"; d="scan'208";a="296427717" Received: from yyu32-desk1.sc.intel.com ([143.183.136.147]) by orsmga004.jf.intel.com with ESMTP; 02 May 2019 09:33:23 -0700 Message-ID: <91611b9e159799bbf603b65cf7bb6b37dd81b075.camel@intel.com> Subject: Re: [PATCH] binfmt_elf: Extract .note.gnu.property from an ELF file From: Yu-cheng Yu 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 Date: Thu, 02 May 2019 09:25:56 -0700 In-Reply-To: <20190502161424.GQ3567@e103592.cambridge.arm.com> References: <20190501211217.5039-1-yu-cheng.yu@intel.com> <20190502111003.GO3567@e103592.cambridge.arm.com> <5b2c6cee345e00182e97842ae90c02cdcd830135.camel@intel.com> <20190502161424.GQ3567@e103592.cambridge.arm.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-05-02 at 17:14 +0100, Dave Martin wrote: > On Thu, May 02, 2019 at 08:47:06AM -0700, Yu-cheng Yu wrote: > > 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. > > I'm concerned that in the arm64 case we would waste some effort by > scanning multiple notes. > > Could we do something like iterating over the phdrs, and if we find > exactly one PT_GNU_PROPERTY then use that, else fall back to scanning > all PT_NOTEs? That makes sense to me, but the concern is that we don't know the PT_GNU_PROPERTY the only one. This probably needs to be discussed with more people. > > > 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. > > Just to get something working on arm64, I'm working on some hacks that > move things around a bit -- I'll post when I have something. > > Did you have any view on my other point, below? That should work. I will also make some changes for that. > > Cheers > ---Dave > > > > 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