[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/7] semihosting: Allow optional use of semihosting from user

From: Philippe Mathieu-Daudé
Subject: Re: [PATCH 1/7] semihosting: Allow optional use of semihosting from userspace
Date: Tue, 16 Aug 2022 02:27:55 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.12.0

On 15/8/22 21:02, Peter Maydell wrote:
Currently our semihosting implementations generally prohibit use of
semihosting calls in system emulation from the guest userspace.  This
is a very long standing behaviour justified originally "to provide
some semblance of security" (since code with access to the
semihosting ABI can do things like read and write arbitrary files on
the host system).  However, it is sometimes useful to be able to run
trusted guest code which performs semihosting calls from guest
userspace, notably for test code.  Add a command line suboption to
the existing semihosting-config option group so that you can
explicitly opt in to semihosting from guest userspace with
  -semihosting-config userspace=on

(There is no equivalent option for the user-mode emulator, because
there by definition all code runs in userspace and has access to
semihosting already.)

This commit adds the infrastructure for the command line option and
adds a bool 'is_user' parameter to the function
semihosting_userspace_enabled() that target code can use to check
whether it should be permitting the semihosting call for userspace.
It mechanically makes all the callsites pass 'false', so they
continue checking "is semihosting enabled in general".  Subsequent
commits will make each target that implements semihosting honour the
userspace=on option by passing the correct value and removing
whatever "don't do this for userspace" checking they were doing by

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  include/semihosting/semihost.h | 10 ++++++++--
  semihosting/config.c           | 10 ++++++++--
  softmmu/vl.c                   |  2 +-
  stubs/semihost.c               |  2 +-
  target/arm/translate-a64.c     |  2 +-
  target/arm/translate.c         |  6 +++---
  target/m68k/op_helper.c        |  2 +-
  target/nios2/translate.c       |  2 +-
  target/xtensa/translate.c      |  6 +++---
  qemu-options.hx                | 11 +++++++++--
  10 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h
index 93a3c21b44d..efd2efa25ae 100644
--- a/include/semihosting/semihost.h
+++ b/include/semihosting/semihost.h
@@ -27,7 +27,7 @@ typedef enum SemihostingTarget {
  } SemihostingTarget;
-static inline bool semihosting_enabled(void)
+static inline bool semihosting_enabled(bool is_user)
      return true;
@@ -52,7 +52,13 @@ static inline const char *semihosting_get_cmdline(void)
      return NULL;
  #else /* !CONFIG_USER_ONLY */
-bool semihosting_enabled(void);
+ * semihosting_enabled:
+ * @is_user: true if guest code is in usermode (i.e. not privileged)
+ *
+ * Return true if guest code is allowed to make semihosting calls.
+ */
+bool semihosting_enabled(bool is_user);

Per the description, possibly rename as semihosting_allowed().

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]