From: Dave Martin <Dave.Martin@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
"Yu-cheng Yu" <yu-cheng.yu@intel.com>,
"H.J. Lu" <hjl.tools@gmail.com>, "Arnd Bergmann" <arnd@arndb.de>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Andrew Jones" <drjones@redhat.com>,
"Will Deacon" <will.deacon@arm.com>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Kristina Martšenko" <kristina.martsenko@arm.com>,
"Szabolcs Nagy" <szabolcs.nagy@arm.com>,
"Sudakshina Das" <sudi.das@arm.com>,
"Paul Elliott" <paul.elliott@arm.com>
Subject: [PATCH 5/8] elf: Parse program properties before destroying the old process
Date: Fri, 24 May 2019 11:25:30 +0100 [thread overview]
Message-ID: <1558693533-13465-6-git-send-email-Dave.Martin@arm.com> (raw)
In-Reply-To: <1558693533-13465-1-git-send-email-Dave.Martin@arm.com>
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 <Dave.Martin@arm.com>
---
fs/binfmt_elf.c | 26 +++++++++++++-------------
include/linux/elf.h | 15 +++++++++++----
2 files changed, 24 insertions(+), 17 deletions(-)
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
--
2.1.4
next prev parent reply other threads:[~2019-05-24 10:25 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-24 10:25 [PATCH 0/8] arm64: ARMv8.5-A: Branch Target Identification support Dave Martin
2019-05-24 10:25 ` Dave Martin
2019-05-24 10:25 ` [PATCH 1/8] binfmt_elf: Extract .note.gnu.property from an ELF file Dave Martin
2019-05-24 10:25 ` Dave Martin
2019-05-24 10:25 ` [PATCH 2/8] mm: Reserve asm-generic prot flag 0x10 for arch use Dave Martin
2019-05-24 10:25 ` Dave Martin
2019-05-24 10:25 ` [PATCH 3/8] arm64: docs: cpu-feature-registers: Document ID_AA64PFR1_EL1 Dave Martin
2019-05-24 10:25 ` Dave Martin
2019-05-24 10:25 ` [PATCH 4/8] arm64: Basic Branch Target Identification support Dave Martin
2019-05-24 10:25 ` Dave Martin
2019-05-24 13:02 ` Mark Rutland
2019-05-24 13:02 ` Mark Rutland
2019-05-24 14:53 ` Dave Martin
2019-05-24 14:53 ` Dave Martin
2019-05-24 15:38 ` Mark Rutland
2019-05-24 15:38 ` Mark Rutland
2019-05-24 16:12 ` Dave Martin
2019-05-24 16:12 ` Dave Martin
2019-05-24 17:19 ` Mark Rutland
2019-05-24 17:19 ` Mark Rutland
2019-05-28 10:52 ` Dave P Martin
2019-05-28 10:52 ` Dave P Martin
2019-06-06 17:11 ` Catalin Marinas
2019-06-06 17:11 ` Catalin Marinas
2019-06-06 17:23 ` Dave Martin
2019-06-06 17:23 ` Dave Martin
2019-06-06 17:34 ` Yu-cheng Yu
2019-06-06 17:34 ` Yu-cheng Yu
2019-06-06 17:56 ` Dave Martin
2019-06-06 17:56 ` Dave Martin
2019-05-24 10:25 ` Dave Martin [this message]
2019-05-24 10:25 ` [PATCH 5/8] elf: Parse program properties before destroying the old process Dave Martin
2019-05-24 10:25 ` [PATCH 6/8] elf: Allow arch to tweak initial mmap prot flags Dave Martin
2019-05-24 10:25 ` Dave Martin
2019-05-24 10:25 ` [PATCH 7/8] arm64: elf: Enable BTI at exec based on ELF program properties Dave Martin
2019-05-24 10:25 ` Dave Martin
2019-05-24 10:25 ` [PATCH 8/8] arm64: BTI: Decode BYTPE bits when printing PSTATE Dave Martin
2019-05-24 10:25 ` Dave Martin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1558693533-13465-6-git-send-email-Dave.Martin@arm.com \
--to=dave.martin@arm.com \
--cc=arnd@arndb.de \
--cc=catalin.marinas@arm.com \
--cc=drjones@redhat.com \
--cc=hjl.tools@gmail.com \
--cc=kristina.martsenko@arm.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paul.elliott@arm.com \
--cc=richard.henderson@linaro.org \
--cc=sudi.das@arm.com \
--cc=szabolcs.nagy@arm.com \
--cc=will.deacon@arm.com \
--cc=yu-cheng.yu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).