Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7292965yba; Thu, 2 May 2019 07:32:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfsLKfowPqtt1M25VLqVU8+bNh2Lucl8ucwdkx+6ldJH/yMDVneJ1LTu0zS74jIHuhVPhH X-Received: by 2002:a63:4721:: with SMTP id u33mr4264062pga.199.1556807555149; Thu, 02 May 2019 07:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807555; cv=none; d=google.com; s=arc-20160816; b=aWqESEZwzMIlIAISRYuMz9JbawKr+nt3CMo/2fwuLr6WT1vBc7QFbA9dq0j8ehMMkW eQp7Xtra6T/IlF+qrrnAPDD2f1oHMCu7RQzCmGeG8rM64ni6AFwUFtcmzoL8a7pQqbf4 tSxDtf/8Mrv+f+3jtMlo0WTVUeEAetcm+9pw3JOP9rp/AhXnvE1o67BZzQlS+bRuoiA4 Rya/fUhYWLlO1hN3uAlBWnWcfQ4LIPkm4I2c+h2RtwVkycnf+Am5kCCacBbUsaBOAxTc fnz2BcMgXSDDe6lRsvagkBTBtYUhWJv1GC1uBOHwLwm7kDj322QgiCaSXryahIbjzZwS O/XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=GjZRT6nPoKpuBmsPa1t099v4/OXTxPeMOIlYa6Pu4ts=; b=r9vthpLMlZStsVILhP2BkpMVP017O8MXMQp+mTz/8UsN00FuHlWaL4rZnfkwO3Yo/n wGCE00IebLeL0aZL1bBR15yCEjvOHeFFnvLvmXQYXhwGVtVj/e+xCaFvwpF0btpmC6R6 vayOv4iw1shaYWo4nKsMSGqwl8Tf8oRNlHKBz6IVLvMC/QSvwi8T/V1JF2XQh/Ld3dAN 24Xgd7qyGPgaNDZUayKWJU38p0W8lXMPtbGW68A9qTZN9XudAW0caibTZWEMOq7kmnhs u8Rw+G+5TA0bwHjkLY5D50PGTvmPJFNeAL4rOJHA5n6qPRUUBMGTUPBIIMCTdr8Qftv7 JGsg== 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 u22si16840435pfh.11.2019.05.02.07.32.17; Thu, 02 May 2019 07:32:35 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726394AbfEBOaB (ORCPT + 99 others); Thu, 2 May 2019 10:30:01 -0400 Received: from foss.arm.com ([217.140.101.70]:46854 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726278AbfEBOaA (ORCPT ); Thu, 2 May 2019 10:30:00 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C155F374; Thu, 2 May 2019 07:29:59 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B4FB13F5AF; Thu, 2 May 2019 07:29:54 -0700 (PDT) Date: Thu, 2 May 2019 15:29:52 +0100 From: Dave Martin To: Yu-cheng Yu 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 Subject: Re: [PATCH] binfmt_elf: Extract .note.gnu.property from an ELF file Message-ID: <20190502142951.GP3567@e103592.cambridge.arm.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=us-ascii Content-Disposition: inline In-Reply-To: <20190502111003.GO3567@e103592.cambridge.arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 02, 2019 at 12:10:04PM +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. > > > > This patch was part of the Control-flow Enforcement series; the original > > patch is here: https://lkml.org/lkml/2018/11/20/205. Dave Martin responded > > that ARM recently introduced new features to NT_GNU_PROPERTY_TYPE_0 with > > properties closely modelled on GNU_PROPERTY_X86_FEATURE_1_AND, and it is > > logical to split out the generic part. Here it is. > > > > With this patch, if an arch needs to setup features from ELF properties, > > it needs CONFIG_ARCH_USE_GNU_PROPERTY to be set, and a specific > > arch_setup_property(). > > > > For example, for X86_64: > > > > 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); > > ... > > } [...] > > diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c > > index 7d09d125f148..40aa4a4fd64d 100644 > > --- a/fs/binfmt_elf.c > > +++ b/fs/binfmt_elf.c > > @@ -1076,6 +1076,19 @@ static int load_elf_binary(struct linux_binprm *bprm) > > goto out_free_dentry; > > } > > > > + if (interpreter) { > > + retval = arch_setup_property(&loc->interp_elf_ex, > > + interp_elf_phdata, > > + interpreter, true); > > + } else { > > + retval = arch_setup_property(&loc->elf_ex, > > + elf_phdata, > > + bprm->file, false); > > + } This will be too late for arm64, since we need to twiddle the mmap prot flags for the executable's pages based on the detected properties. Can we instead move this much earlier, letting the arch code stash something in arch_state that can be consumed later on? This also has the advantage that we can report errors to the execve() caller before passing the point of no return (i.e., flush_old_exec()). [...] > > diff --git a/fs/gnu_property.c b/fs/gnu_property.c [...] > > +int get_gnu_property(void *ehdr_p, void *phdr_p, struct file *f, > > + u32 pr_type, u32 *property) > > +{ > > + struct elf64_hdr *ehdr64 = ehdr_p; > > + int err = 0; > > + > > + *property = 0; > > + > > + if (ehdr64->e_ident[EI_CLASS] == ELFCLASS64) { > > + struct elf64_phdr *phdr64 = phdr_p; > > + > > + err = scan_segments_64(f, phdr64, ehdr64->e_phnum, > > + pr_type, property); > > + if (err < 0) > > + goto out; > > + } else { > > +#ifdef CONFIG_COMPAT > > + struct elf32_hdr *ehdr32 = ehdr_p; > > + > > + if (ehdr32->e_ident[EI_CLASS] == ELFCLASS32) { > > + struct elf32_phdr *phdr32 = phdr_p; > > + > > + err = scan_segments_32(f, phdr32, ehdr32->e_phnum, > > + pr_type, property); > > + if (err < 0) > > + goto out; > > + } > > +#else > > + WARN_ONCE(1, "Exec of 32-bit app, but CONFIG_COMPAT is not enabled.\n"); > > + return -ENOTSUPP; > > +#endif > > + } We have already made a ton of assumptions about the ELF class by this point, and we don't seem to check it explicitly elsewhere, so it is a bit weird to police it specifically here. Can we simply pass the assumed ELF class as a parameter instead? [...] Cheers ---DavE