From patchwork Fri May 24 10:25:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 165099 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3384422ili; Fri, 24 May 2019 03:26:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyotECtRplg+TJfjGBq3020u/0FtI3inGAlu95bpfkWAdK7uOjz7IB1K0uPoL8Zbz9Ha2Lb X-Received: by 2002:a65:44c8:: with SMTP id g8mr105129626pgs.443.1558693598380; Fri, 24 May 2019 03:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558693598; cv=none; d=google.com; s=arc-20160816; b=eXwP3P8OIm3qzCe5xhaMSOb8ve9nM0jlpA2PuZRSfoGbdE9UcdmKr/0QvtFPeXUnTB SKK26MF0MUSUUEhQGBvsGEcmQSNNrKvrbldFRmsg4cehVRfSi4qLYGkyl7pTeu0EeRza oQHQg3eUOzGcUikCnqa2vOf2jcDgbejGeUBbmQm0jmSyM7GQIooGpLl/xrZbFLyQ3jTO 38HiVF+8ij5a9PJRxu/OtG7vniQzVd1CeRbwF2ZDX9qugdpssU60Zru9ix1atCOnLoPH j1BC+wuag/qHXgoppEsidtj5D855B4HsVo5GDpowlGvOn6epaUExxuB0amQfFeW8UaQm 8Lww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=BlycG0574qiXJdoumfo+t//Focf5kb7xLLxTSPGtB34=; b=HwsidPLO40dr6bCVB0Vj5M4qNn7eApQbgYES9EjhFDjqbIzGH2Uep5b7f+isaQmELO wrO8R4VqbwYQaA8RXMAe0j3Z0eOB20IqJM+E6Q0SjWsyT2k5mL60R2bDe4OcF6reKsFn 5+PC1BeRcsanD8oI89yXF9n5RaI7ln/zwoPow3XNNHQhj7ZdIpGDqShLmslu75917BFc mNbMAlNh8c2OI3L1m6Axy9+EcM4I1FsnypWHGwkTSRseETSvcjo7qHtJCHhwPG3jIhyA M90wE05P+ybBuCZHcVt7lxDr2yOHQ5dnhXWlr2r1o49daHaUJi26Aa3nPPbSZe9L61LQ E4kw== 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 j9si1555748pfr.277.2019.05.24.03.26.38; Fri, 24 May 2019 03:26:38 -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 S2390651AbfEXK0h (ORCPT + 30 others); Fri, 24 May 2019 06:26:37 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39254 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390631AbfEXK0e (ORCPT ); Fri, 24 May 2019 06:26:34 -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 0E3541682; Fri, 24 May 2019 03:26:34 -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 ESMTPA id C9DF43F703; Fri, 24 May 2019 03:26:31 -0700 (PDT) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Yu-cheng Yu , "H.J. Lu" , Arnd Bergmann , Richard Henderson , Andrew Jones , Will Deacon , Catalin Marinas , =?utf-8?q?Kristina_Mart=C5=A1enko?= , Szabolcs Nagy , Sudakshina Das , Paul Elliott Subject: [PATCH 5/8] elf: Parse program properties before destroying the old process Date: Fri, 24 May 2019 11:25:30 +0100 Message-Id: <1558693533-13465-6-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1558693533-13465-1-git-send-email-Dave.Martin@arm.com> References: <1558693533-13465-1-git-send-email-Dave.Martin@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we try to read program properties from NT_GNU_PROPERTY_TYPE_0 ELF notes. However, we do this too late to either report failures cleanly or influence certain aspects of process setup such as the default mmap permissions for the new executable's pages (which will matter for arm64 for example). So, split parsing of the notes from use: rename arch_setup_property() to arch_parse_property() to make the intent clear, and hoist it before flush_old_exec() so that we can still bail out gracefully if needed. Also propagate arch_state into the call so that the arch backend has somewhere to stash information for later use. Signed-off-by: Dave Martin --- fs/binfmt_elf.c | 26 +++++++++++++------------- include/linux/elf.h | 15 +++++++++++---- 2 files changed, 24 insertions(+), 17 deletions(-) -- 2.1.4 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 18015fc..32c9c13 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -851,6 +851,19 @@ static int load_elf_binary(struct linux_binprm *bprm) } } + if (interpreter) { + retval = arch_parse_property(&loc->interp_elf_ex, + interp_elf_phdata, + interpreter, true, &arch_state); + } else { + retval = arch_parse_property(&loc->elf_ex, + elf_phdata, + bprm->file, false, &arch_state); + } + + if (retval < 0) + goto out_free_dentry; + /* * Allow arch code to reject the ELF at this point, whilst it's * still possible to return an error to the code that invoked @@ -1080,19 +1093,6 @@ static int load_elf_binary(struct linux_binprm *bprm) } 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); - } - - if (retval < 0) - goto out_free_dentry; - - if (interpreter) { unsigned long interp_map_addr = 0; elf_entry = load_elf_interp(&loc->interp_elf_ex, diff --git a/include/linux/elf.h b/include/linux/elf.h index c15febe..cfcf154 100644 --- a/include/linux/elf.h +++ b/include/linux/elf.h @@ -57,14 +57,21 @@ extern int elf_coredump_extra_notes_size(void); extern int elf_coredump_extra_notes_write(struct coredump_params *cprm); #endif +struct arch_elf_state; + #ifdef CONFIG_ARCH_USE_GNU_PROPERTY -extern int arch_setup_property(void *ehdr, void *phdr, struct file *f, - bool interp); +extern int arch_parse_property(void *ehdr, void *phdr, struct file *f, + bool interp, struct arch_elf_state *arch_state); extern int get_gnu_property(void *ehdr_p, void *phdr_p, struct file *f, u32 pr_type, u32 *feature); #else -static inline int arch_setup_property(void *ehdr, void *phdr, struct file *f, - bool interp) { return 0; } +static inline int arch_parse_property(void *ehdr, void *phdr, struct file *f, + bool interp, + struct arch_elf_state *arch_state) +{ + return 0; +} + static inline int get_gnu_property(void *ehdr_p, void *phdr_p, struct file *f, u32 pr_type, u32 *feature) { return 0; } #endif