qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option
@ 2008-12-03 11:29 Kirill A. Shutemov
  2008-12-03 11:29 ` [Qemu-devel] [PATCH] Fix fstatat64()/newfstatat() syscall implementation Kirill A. Shutemov
  2009-01-12 14:18 ` [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option Riku Voipio
  0 siblings, 2 replies; 47+ messages in thread
From: Kirill A. Shutemov @ 2008-12-03 11:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A. Shutemov

It makes qemu compatible with binfmt_misc's flags 'P' and 'O'.

'P' - preserve-argv[0].  Legacy behavior of binfmt_misc is to overwrite the
      original argv[0] with the full path to the binary.  When this flag is
      included, binfmt_misc will add an argument to the argument vector for
      this purpose, thus preserving the original argv[0].

'O' - open-binary. Legacy behavior of binfmt_misc is to pass the full path
      of the binary to the interpreter as an argument. When this flag is
      included, binfmt_misc will open the file for reading and pass its
      descriptor as an argument, instead of the full path, thus allowing
      the interpreter to execute non-readable binaries.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 configure              |   90 ++++++++++++++++++++++++++----------------------
 linux-user/linuxload.c |    7 +---
 linux-user/main.c      |   39 ++++++++++++++++++++-
 linux-user/qemu.h      |    2 +-
 4 files changed, 89 insertions(+), 49 deletions(-)

diff --git a/configure b/configure
index 57b3b5a..aeeae72 100755
--- a/configure
+++ b/configure
@@ -122,6 +122,7 @@ kvm="yes"
 kerneldir=""
 aix="no"
 blobs="yes"
+binfmt_misc="no"
 
 # OS specific
 targetos=`uname -s`
@@ -380,6 +381,8 @@ for opt do
   ;;
   --kerneldir=*) kerneldir="$optarg"
   ;;
+  --enable-binfmt-misc) binfmt_misc="yes"
+  ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"
   ;;
   esac
@@ -491,6 +494,7 @@ echo "  --disable-vde            disable support for vde network"
 echo "  --disable-aio            disable AIO support"
 echo "  --disable-blobs          disable installing provided firmware blobs"
 echo "  --kerneldir=PATH         look for kernel includes in PATH"
+echo "  --enable-binfmt-misc     makes usermode compatible with binfmt_misc's flags 'P' and 'O'"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -1041,57 +1045,58 @@ else
   binsuffix="/bin"
 fi
 
-echo "Install prefix    $prefix"
-echo "BIOS directory    $prefix$datasuffix"
-echo "binary directory  $prefix$binsuffix"
+echo "Install prefix      $prefix"
+echo "BIOS directory      $prefix$datasuffix"
+echo "binary directory    $prefix$binsuffix"
 if test "$mingw32" = "no" ; then
-echo "Manual directory  $prefix$mansuffix"
-echo "ELF interp prefix $interp_prefix"
-fi
-echo "Source path       $source_path"
-echo "C compiler        $cc"
-echo "Host C compiler   $host_cc"
-echo "ARCH_CFLAGS       $ARCH_CFLAGS"
-echo "make              $make"
-echo "install           $install"
-echo "host CPU          $cpu"
-echo "host big endian   $bigendian"
-echo "target list       $target_list"
-echo "gprof enabled     $gprof"
-echo "sparse enabled    $sparse"
-echo "profiler          $profiler"
-echo "static build      $static"
-echo "-Werror enabled   $werror"
+echo "Manual directory    $prefix$mansuffix"
+echo "ELF interp prefix   $interp_prefix"
+fi
+echo "Source path         $source_path"
+echo "C compiler          $cc"
+echo "Host C compiler     $host_cc"
+echo "ARCH_CFLAGS         $ARCH_CFLAGS"
+echo "make                $make"
+echo "install             $install"
+echo "host CPU            $cpu"
+echo "host big endian     $bigendian"
+echo "target list         $target_list"
+echo "gprof enabled       $gprof"
+echo "sparse enabled      $sparse"
+echo "profiler            $profiler"
+echo "static build        $static"
+echo "-Werror enabled     $werror"
 if test "$darwin" = "yes" ; then
-    echo "Cocoa support     $cocoa"
+    echo "Cocoa support       $cocoa"
 fi
 echo "SDL support       $sdl"
 if test "$sdl" != "no" ; then
-    echo "SDL static link   $sdl_static"
-fi
-echo "curses support    $curses"
-echo "mingw32 support   $mingw32"
-echo "Audio drivers     $audio_drv_list"
-echo "Extra audio cards $audio_card_list"
-echo "Mixer emulation   $mixemu"
-echo "VNC TLS support   $vnc_tls"
+    echo "SDL static link     $sdl_static"
+fi
+echo "curses support      $curses"
+echo "mingw32 support     $mingw32"
+echo "Audio drivers       $audio_drv_list"
+echo "Extra audio cards   $audio_card_list"
+echo "Mixer emulation     $mixemu"
+echo "VNC TLS support     $vnc_tls"
 if test "$vnc_tls" = "yes" ; then
-    echo "    TLS CFLAGS    $vnc_tls_cflags"
-    echo "    TLS LIBS      $vnc_tls_libs"
+    echo "    TLS CFLAGS      $vnc_tls_cflags"
+    echo "    TLS LIBS        $vnc_tls_libs"
 fi
 if test -n "$sparc_cpu"; then
-    echo "Target Sparc Arch $sparc_cpu"
+    echo "Target Sparc Arch   $sparc_cpu"
 fi
-echo "kqemu support     $kqemu"
-echo "brlapi support    $brlapi"
-echo "Documentation     $build_docs"
+echo "kqemu support       $kqemu"
+echo "brlapi support      $brlapi"
+echo "Documentation       $build_docs"
 [ ! -z "$uname_release" ] && \
-echo "uname -r          $uname_release"
-echo "NPTL support      $nptl"
-echo "vde support       $vde"
-echo "AIO support       $aio"
-echo "Install blobs     $blobs"
-echo "KVM support       $kvm"
+echo "uname -r            $uname_release"
+echo "NPTL support        $nptl"
+echo "vde support         $vde"
+echo "AIO support         $aio"
+echo "Install blobs       $blobs"
+echo "KVM support         $kvm"
+echo "binfmt_misc support $binfmt_misc"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -1709,6 +1714,9 @@ if test "$target_bsd_user" = "yes" ; then
   echo "CONFIG_BSD_USER=yes" >> $config_mak
   echo "#define CONFIG_BSD_USER 1" >> $config_h
 fi
+if test "$target_user_only" = "yes" -a "$binfmt_misc" = "yes"; then
+  echo "#define BINFMT_MISC 1" >> $config_h
+fi
 
 test -f ${config_h}~ && cmp -s $config_h ${config_h}~ && mv ${config_h}~ $config_h
 
diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index ada7c69..cbd90f7 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -154,7 +154,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
     return sp;
 }
 
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fd, const char * filename, char ** argv, char ** envp,
              struct target_pt_regs * regs, struct image_info *infop)
 {
     struct linux_binprm bprm;
@@ -164,10 +164,7 @@ int loader_exec(const char * filename, char ** argv, char ** envp,
     bprm.p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
     for (i=0 ; i<MAX_ARG_PAGES ; i++)       /* clear page-table */
             bprm.page[i] = 0;
-    retval = open(filename, O_RDONLY);
-    if (retval < 0)
-        return retval;
-    bprm.fd = retval;
+    bprm.fd = fd;
     bprm.filename = (char *)filename;
     bprm.argc = count(argv);
     bprm.argv = argv;
diff --git a/linux-user/main.c b/linux-user/main.c
index 66be107..6ed9247 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -27,6 +27,7 @@
 
 #include "qemu.h"
 #include "qemu-common.h"
+#include "elf.h"
 /* For tb_lock */
 #include "exec-all.h"
 
@@ -2214,9 +2215,10 @@ void init_task_state(TaskState *ts)
     ts->sigqueue_table[i].next = NULL;
 }
  
-int main(int argc, char **argv)
+int main(int argc, char **argv, char **envp)
 {
     const char *filename;
+    int fd = -1;
     const char *cpu_model;
     struct target_pt_regs regs1, *regs = &regs1;
     struct image_info info1, *info = &info1;
@@ -2377,7 +2379,40 @@ int main(int argc, char **argv)
     }
     *dst = NULL; /* NULL terminate target_environ */
 
-    if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
+#ifdef BINFMT_MISC
+#if HOST_LONG_BITS == 32
+#define Elf_Dyn Elf32_Dyn
+#else
+#define Elf_Dyn Elf64_Dyn
+#endif
+    {
+        Elf_Dyn *auxv;
+
+        optind++; /* Handle binfmt_misc's option 'P' */
+
+        /* Handle binfmt_misc's option 'O' */
+        while(*envp++ != NULL); /* skip envp. we are on auxv now */
+        for(auxv = (Elf_Dyn *)envp; auxv->d_tag != AT_NULL; auxv++) {
+            if( auxv->d_tag == AT_EXECFD) {
+                fd = auxv->d_un.d_val;
+                break;
+            }
+        }
+
+        if (fd < 0) {
+            printf("Cannot find binary file descriptor\n");
+            _exit(1);
+        }
+    }
+#else
+    fd = open(filename, O_RDONLY);
+    if (fd < 0) {
+        printf("Cannot open file %s: %s\n", filename, strerror(errno));
+        _exit(1);
+    }
+#endif
+
+    if (loader_exec(fd, filename, argv+optind, target_environ, regs, info) != 0) {
         printf("Error loading %s\n", filename);
         _exit(1);
     }
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index a2abe51..52835ec 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -168,7 +168,7 @@ struct linux_binprm {
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
                               abi_ulong stringp, int push_ptr);
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fd, const char * filename, char ** argv, char ** envp,
              struct target_pt_regs * regs, struct image_info *infop);
 
 int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
-- 
1.6.0.2.GIT

^ permalink raw reply related	[flat|nested] 47+ messages in thread
* [Qemu-devel] [PATCH] linux-user: Safety belt for h2g
@ 2008-07-13 20:27 Jan Kiszka
  0 siblings, 0 replies; 47+ messages in thread
From: Jan Kiszka @ 2008-07-13 20:27 UTC (permalink / raw)
  To: qemu-devel

h2g can only work on 64-bit hosts if the provided address is mappable to
the guest range. Neglecting this was already the source for several
bugs. Instrument the macro so that it will trigger earlier in the
future (at least as long as we have this kind of mapping mechanism).

Signed-off-by: Jan Kiszka <jan.kiszka@web.de>
---
 cpu-all.h |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Index: b/cpu-all.h
===================================================================
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -659,6 +659,8 @@ static inline void stfq_be_p(void *ptr,
 /* MMU memory access macros */
 
 #if defined(CONFIG_USER_ONLY)
+#include <assert.h>
+
 /* On some host systems the guest address space is reserved on the host.
  * This allows the guest address space to be offset to a convenient location.
  */
@@ -667,7 +669,11 @@ static inline void stfq_be_p(void *ptr,
 
 /* All direct uses of g2h and h2g need to go away for usermode softmmu.  */
 #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
-#define h2g(x) ((target_ulong)((unsigned long)(x) - GUEST_BASE))
+#define h2g(x) ({ \
+    unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \
+    assert(__ret == (target_ulong)__ret); \
+    __ret; \
+})
 
 #define saddr(x) g2h(x)
 #define laddr(x) g2h(x)

^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2009-01-12 14:18 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-03 11:29 [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option Kirill A. Shutemov
2008-12-03 11:29 ` [Qemu-devel] [PATCH] Fix fstatat64()/newfstatat() syscall implementation Kirill A. Shutemov
2008-12-03 11:29   ` [Qemu-devel] [PATCH] Move abi_* typedefs into qemu-types.h Kirill A. Shutemov
2008-12-03 11:29     ` [Qemu-devel] [PATCH] linux-user: Safety belt for h2g Kirill A. Shutemov
2008-12-03 11:29       ` [Qemu-devel] [PATCH] linux-user: Introduce h2g_valid Kirill A. Shutemov
2008-12-03 11:29         ` [Qemu-devel] [PATCH] linux-user: Fix h2g usage in page_find_alloc Kirill A. Shutemov
2008-12-03 11:29           ` [Qemu-devel] [PATCH] Rewrite mmap_find_vma() to work fine on 64-bit hosts with 32-bit targets Kirill A. Shutemov
2008-12-03 11:29             ` [Qemu-devel] [PATCH] mmap: add check if requested memory area fits target address space Kirill A. Shutemov
2008-12-03 11:29               ` [Qemu-devel] [PATCH] mremap(): handle MREMAP_FIXED and MREMAP_MAYMOVE correctly Kirill A. Shutemov
2008-12-03 11:29                 ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_sem* ipc calls handling Kirill A. Shutemov
2008-12-03 11:29                   ` [Qemu-devel] [PATCH] Implement sem* syscalls Kirill A. Shutemov
2008-12-03 11:29                     ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_shm* ipc calls handling Kirill A. Shutemov
2008-12-03 11:29                       ` [Qemu-devel] [PATCH] Implement shm* syscalls Kirill A. Shutemov
2008-12-03 11:29                         ` [Qemu-devel] [PATCH] shmat(): use mmap_find_vma to find free memory area Kirill A. Shutemov
2008-12-06 19:51                 ` [Qemu-devel] [PATCH] mremap(): handle MREMAP_FIXED and MREMAP_MAYMOVE correctly Edgar E. Iglesias
2008-12-06 20:03                   ` Kirill A. Shutemov
2008-12-08 18:17                 ` Aurelien Jarno
2008-12-06 19:46               ` [Qemu-devel] [PATCH] mmap: add check if requested memory area fits target address space Edgar E. Iglesias
2008-12-06 20:00                 ` Kirill A. Shutemov
2008-12-08 18:16               ` Aurelien Jarno
2008-12-03 12:34             ` [Qemu-devel] [PATCH] Rewrite mmap_find_vma() to work fine on 64-bit hosts with 32-bit targets Paul Brook
2008-12-03 12:43               ` Christoph Egger
2008-12-03 12:48                 ` Paul Brook
2008-12-03 12:50               ` Kirill A. Shutemov
2008-12-08 20:48                 ` Kirill A. Shutemov
2008-12-08 20:54                   ` Martin Mohring
2008-12-08 20:59                   ` Martin Mohring
2008-12-08 21:57                     ` Kirill A. Shutemov
2008-12-08 21:02                   ` Martin Mohring
2008-12-08 22:14                     ` [Qemu-devel] qemu and glibc version Kirill A. Shutemov
2008-12-09 12:25                     ` [Qemu-devel] [PATCH] Rewrite mmap_find_vma() to work fine on 64-bit hosts with 32-bit targets Robert Reif
2008-12-09 13:26                       ` Kirill A. Shutemov
2008-12-08 23:42                   ` Paul Brook
2008-12-09  6:20                     ` Kirill A. Shutemov
2008-12-06 20:08           ` [Qemu-devel] [PATCH] linux-user: Fix h2g usage in page_find_alloc Edgar E. Iglesias
2008-12-06 20:13             ` Kirill A. Shutemov
2008-12-08 18:16           ` Aurelien Jarno
2008-12-08 18:15         ` [Qemu-devel] [PATCH] linux-user: Introduce h2g_valid Aurelien Jarno
2008-12-06 20:04       ` [Qemu-devel] [PATCH] linux-user: Safety belt for h2g Edgar E. Iglesias
2008-12-08 18:15       ` Aurelien Jarno
2008-12-08 19:25         ` Andreas Färber
2008-12-09  7:34         ` Jan Kiszka
2008-12-07 21:56     ` [Qemu-devel] [PATCH] Move abi_* typedefs into qemu-types.h Aurelien Jarno
2008-12-08  6:09       ` Kirill A. Shutemov
2008-12-08 18:13     ` Aurelien Jarno
2009-01-12 14:18 ` [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option Riku Voipio
  -- strict thread matches above, loose matches on Subject: below --
2008-07-13 20:27 [Qemu-devel] [PATCH] linux-user: Safety belt for h2g Jan Kiszka

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).