All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org,
	alex.bennee@linaro.org, laurent@vivier.eu
Subject: [PATCH v11 11/12] linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_AND
Date: Fri, 16 Oct 2020 11:42:06 -0700	[thread overview]
Message-ID: <20201016184207.786698-12-richard.henderson@linaro.org> (raw)
In-Reply-To: <20201016184207.786698-1-richard.henderson@linaro.org>

Use the new generic support for NT_GNU_PROPERTY_TYPE_0.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
v11: Split out aarch64 bits from generic patch.
---
 linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 428dcaa152..bf8c1bd253 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1522,6 +1522,28 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 
 #include "elf.h"
 
+/* We must delay the following stanzas until after "elf.h". */
+#if defined(TARGET_AARCH64)
+
+static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
+                                    const uint32_t *data,
+                                    struct image_info *info,
+                                    Error **errp)
+{
+    if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
+        if (pr_datasz != sizeof(uint32_t)) {
+            error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND");
+            return false;
+        }
+        /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */
+        info->note_flags = *data;
+    }
+    return true;
+}
+#define ARCH_USE_GNU_PROPERTY 1
+
+#else
+
 static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
                                     const uint32_t *data,
                                     struct image_info *info,
@@ -1531,6 +1553,8 @@ static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
 }
 #define ARCH_USE_GNU_PROPERTY 0
 
+#endif
+
 struct exec
 {
     unsigned int a_info;   /* Use macros N_MAGIC, etc for access */
@@ -2545,7 +2569,7 @@ static void load_elf_image(const char *image_name, int image_fd,
     struct elfhdr *ehdr = (struct elfhdr *)bprm_buf;
     struct elf_phdr *phdr;
     abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
-    int i, retval;
+    int i, retval, prot_exec;
     Error *err = NULL;
 
     /* First of all, some simple consistency checks */
@@ -2712,6 +2736,26 @@ static void load_elf_image(const char *image_name, int image_fd,
     info->brk = 0;
     info->elf_flags = ehdr->e_flags;
 
+    prot_exec = PROT_EXEC;
+#ifdef TARGET_AARCH64
+    /*
+     * If the BTI feature is present, this indicates that the executable
+     * pages of the startup binary should be mapped with PROT_BTI, so that
+     * branch targets are enforced.
+     *
+     * The startup binary is either the interpreter or the static executable.
+     * The interpreter is responsible for all pages of a dynamic executable.
+     *
+     * Elf notes are backward compatible to older cpus.
+     * Do not enable BTI unless it is supported.
+     */
+    if ((info->note_flags & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
+        && (pinterp_name == NULL || *pinterp_name == 0)
+        && cpu_isar_feature(aa64_bti, ARM_CPU(thread_cpu))) {
+        prot_exec |= TARGET_PROT_BTI;
+    }
+#endif
+
     for (i = 0; i < ehdr->e_phnum; i++) {
         struct elf_phdr *eppnt = phdr + i;
         if (eppnt->p_type == PT_LOAD) {
@@ -2725,7 +2769,7 @@ static void load_elf_image(const char *image_name, int image_fd,
                 elf_prot |= PROT_WRITE;
             }
             if (eppnt->p_flags & PF_X) {
-                elf_prot |= PROT_EXEC;
+                elf_prot |= prot_exec;
             }
 
             vaddr = load_bias + eppnt->p_vaddr;
-- 
2.25.1



  parent reply	other threads:[~2020-10-16 18:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16 18:41 [PATCH v11 00/12] linux-user: User support for AArch64 BTI Richard Henderson
2020-10-16 18:41 ` [PATCH v11 01/12] linux-user/aarch64: Reset btype for signals Richard Henderson
2020-10-16 18:41 ` [PATCH v11 02/12] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Richard Henderson
2020-10-16 18:41 ` [PATCH v11 03/12] include/elf: Add defines related to GNU property notes for AArch64 Richard Henderson
2020-10-16 18:41 ` [PATCH v11 04/12] linux-user/elfload: Avoid leaking interp_name using GLib memory API Richard Henderson
2020-10-16 18:42 ` [PATCH v11 05/12] linux-user/elfload: Fix coding style in load_elf_image Richard Henderson
2020-10-17  9:19   ` Philippe Mathieu-Daudé
2020-10-16 18:42 ` [PATCH v11 06/12] linux-user/elfload: Adjust iteration over phdr Richard Henderson
2020-10-17  9:19   ` Philippe Mathieu-Daudé
2020-10-16 18:42 ` [PATCH v11 07/12] linux-user/elfload: Move PT_INTERP detection to first loop Richard Henderson
2020-10-16 18:42 ` [PATCH v11 08/12] linux-user/elfload: Use Error for load_elf_image Richard Henderson
2020-10-17  9:21   ` Philippe Mathieu-Daudé
2020-10-16 18:42 ` [PATCH v11 09/12] linux-user/elfload: Use Error for load_elf_interp Richard Henderson
2020-10-17  9:22   ` Philippe Mathieu-Daudé
2020-10-16 18:42 ` [PATCH v11 10/12] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Richard Henderson
2020-10-16 18:42 ` Richard Henderson [this message]
2020-10-16 18:42 ` [PATCH v11 12/12] tests/tcg/aarch64: Add bti smoke tests Richard Henderson
2020-10-16 19:06 ` [PATCH v11 00/12] linux-user: User support for AArch64 BTI no-reply
2020-10-20 14:59 ` Peter Maydell
2020-10-20 20:09 ` Peter Maydell
2020-10-21 17:04   ` Richard Henderson

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=20201016184207.786698-12-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.