qemu-devel.nongnu.org archive mirror
 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, Dave.Martin@arm.com
Subject: [Qemu-devel] [PATCH v6 1/6] linux-user/aarch64: Reset btype for syscalls and signals
Date: Wed,  5 Jun 2019 15:57:01 -0500	[thread overview]
Message-ID: <20190605205706.569-2-richard.henderson@linaro.org> (raw)
In-Reply-To: <20190605205706.569-1-richard.henderson@linaro.org>

The value of btype for syscalls is CONSTRAINED UNPREDICTABLE,
so we need to make sure that the value is 0 before clone,
fork, or syscall return.

The kernel sets btype for the signal handler as if for a call.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/cpu_loop.c |  7 +++++++
 linux-user/aarch64/signal.c   | 10 ++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
index 2f2f63e3e8..1f68b13168 100644
--- a/linux-user/aarch64/cpu_loop.c
+++ b/linux-user/aarch64/cpu_loop.c
@@ -86,6 +86,13 @@ void cpu_loop(CPUARMState *env)
 
         switch (trapnr) {
         case EXCP_SWI:
+            /*
+             * The state of BTYPE on syscall entry is CONSTRAINED
+             * UNPREDICTABLE.  The real kernel will need to tidy this up
+             * as well.  Do this before syscalls so that the value is
+             * correct on return from syscall (especially clone & fork).
+             */
+            env->btype = 0;
             ret = do_syscall(env,
                              env->xregs[8],
                              env->xregs[0],
diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
index f84a9cf28a..5605d404b3 100644
--- a/linux-user/aarch64/signal.c
+++ b/linux-user/aarch64/signal.c
@@ -506,10 +506,16 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
             + offsetof(struct target_rt_frame_record, tramp);
     }
     env->xregs[0] = usig;
-    env->xregs[31] = frame_addr;
     env->xregs[29] = frame_addr + fr_ofs;
-    env->pc = ka->_sa_handler;
     env->xregs[30] = return_addr;
+    env->xregs[31] = frame_addr;
+    env->pc = ka->_sa_handler;
+
+    /* Invoke the signal handler as if by indirect call.  */
+    if (cpu_isar_feature(aa64_bti, arm_env_get_cpu(env))) {
+        env->btype = 2;
+    }
+
     if (info) {
         tswap_siginfo(&frame->info, info);
         env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info);
-- 
2.17.1



  reply	other threads:[~2019-06-05 21:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-05 20:57 [Qemu-devel] [PATCH v6 0/6] linux-user/aarch64: Support PROT_BTI Richard Henderson
2019-06-05 20:57 ` Richard Henderson [this message]
2019-06-06  9:53   ` [Qemu-devel] [PATCH v6 1/6] linux-user/aarch64: Reset btype for syscalls and signalsy Dave Martin
2019-06-05 20:57 ` [Qemu-devel] [PATCH v6 2/6] linux-user: Validate mmap/mprotect prot value Richard Henderson
2019-06-06 11:24   ` Aleksandar Markovic
2019-06-05 20:57 ` [Qemu-devel] [PATCH v6 3/6] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Richard Henderson
2019-06-05 20:57 ` [Qemu-devel] [PATCH v6 4/6] include/elf: Add defines related to notes for GNU systems Richard Henderson
2019-06-05 21:17   ` Aleksandar Markovic
2019-06-06  5:45   ` Aleksandar Markovic
2019-06-06  8:42     ` Markus Armbruster
2019-06-05 20:57 ` [Qemu-devel] [PATCH v6 5/6] linux-user: Parse NT_GNU_PROPERTY_TYPE_0 notes Richard Henderson
2019-06-06 10:12   ` Dave Martin
2019-06-05 20:57 ` [Qemu-devel] [PATCH v6 6/6] tests/tcg/aarch64: Add bti smoke test Richard Henderson
2019-06-06 10:21   ` Dave Martin
2019-06-06 14:24     ` Richard Henderson
2019-06-05 22:15 ` [Qemu-devel] [PATCH v6 0/6] linux-user/aarch64: Support PROT_BTI no-reply

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=20190605205706.569-2-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=Dave.Martin@arm.com \
    --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 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).