Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7382946yba; Thu, 2 May 2019 08:57:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvXwWPbj26RSngrWu46x3jLH7HxkMyUhtRhrQ+eYEh3WFKgoazQER+mPP2Qmzmm7LDPYw0 X-Received: by 2002:a63:f754:: with SMTP id f20mr3872840pgk.162.1556812656312; Thu, 02 May 2019 08:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556812656; cv=none; d=google.com; s=arc-20160816; b=MVBoRfWTLbidJHZgIwmLVncrZdBy2dPO1gBBZqTv8pCmtIRzkwBiCeYpB4Aqg2IdlK +OH+w0WMqb2r3lO76whkdbvOsu80XswnwfegeGobeZrw+pEENPsBsuFO1hyErKSfAWiq Rmnjo6Ng3DOHzPq5jS//kIYDFpD+ztCbB3mLbiiOuHoEnJkKO+0G74PALQzPEP2HHdru qHWEEGLN+ryKbYPHkSe6Vo0eOET7mF8/yKVipjDOafbfrKrKSarHdK5jyY3lR5sI93fL 7bfZBo/VYYlfTLHPU1khdNA7ZCUXhmjfPDishrL9AZQSFKCfHgQy464Fjjme3AEZFQwm 7jzw== 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=DV8tNnvAzhdosXEajSqQ9L2SxnFCpg190lOLJjhQj08=; b=bR1A9Nj3l5aD2NTb4MyRgRTkVtENZl6pbsw4sOVzZHCU6mPE2PP4Ms6UKvsKDRrsaA 2szFEK3fDUoitlvJN7j8Mpp7VWkyMLTaPsNSIk1Q+J9z92QeXw3tFugygP0dMoL5hHcN pft5fa0gEUja6UQCprQDZxtxJk7H/5Lj/tzVSE6pY2HZ0Ulh/fE5zuDeQHlS0JvQDRmO 32SILux+HhyEBl4Q1nm2dasRfYQrsuU8OZQDwG0xLh7O3+ggyx1jNmX85mU9jxOCtvck e/ttBZEcgPzvd77+F4jkZ3VEt+eV+RWOkcFAXTFWARWQ+qPeZlQz1T2GR0JkLQ7p3asZ SLfA== 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 r9si3762253pgn.446.2019.05.02.08.57.20; Thu, 02 May 2019 08:57:36 -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 S1726404AbfEBP4M (ORCPT + 99 others); Thu, 2 May 2019 11:56:12 -0400 Received: from mga06.intel.com ([134.134.136.31]:8954 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbfEBP4M (ORCPT ); Thu, 2 May 2019 11:56:12 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 May 2019 08:56:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,422,1549958400"; d="scan'208";a="147702137" Received: from yyu32-desk1.sc.intel.com ([143.183.136.147]) by fmsmga007.fm.intel.com with ESMTP; 02 May 2019 08:56:09 -0700 Message-ID: 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 08:48:42 -0700 In-Reply-To: <20190502142951.GP3567@e103592.cambridge.arm.com> References: <20190501211217.5039-1-yu-cheng.yu@intel.com> <20190502111003.GO3567@e103592.cambridge.arm.com> <20190502142951.GP3567@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 15:29 +0100, Dave Martin wrote: > 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: > > [...] > > > > 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()). I will look into that. > > [...] > > > > 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? Yes. Yu-cheng