qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Riku Voipio <riku.voipio@iki.fi>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option
Date: Mon, 12 Jan 2009 16:18:22 +0200	[thread overview]
Message-ID: <20090112141822.GA29074@kos.to> (raw)
In-Reply-To: <1228303789-25653-1-git-send-email-kirill@shutemov.name>

On Wed, Dec 03, 2008 at 01:29:36PM +0200, Kirill A. Shutemov wrote:
> 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"

Whitespace changes mixed with code changes :-/

> +#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 I read this correctly, it means this patch means that linux-user
doesn't work from command line if configured with --enable-binfmt-misc.

I think it would be better to add a wrapper (as recommended by
binfmt-misc docs in kernel) that sets these binfmt options to new qemu
command line arguments ( --argv0, --open-fd). Assuming the binfmt_misc
passed FD survives exec, the wrapper should work fine. This wrapper
could well be shipped with qemu.

  parent reply	other threads:[~2009-01-12 14:18 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Riku Voipio [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-10-13 10:10 [Qemu-devel] [PATCH] Add readahead syscall Kirill A. Shutemov
2008-10-13 10:10 ` [Qemu-devel] [PATCH] Fix getdents* syscalls Kirill A. Shutemov
2008-10-13 10:10   ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_msg* ipc calls handling Kirill A. Shutemov
2008-10-13 10:10     ` [Qemu-devel] [PATCH] Implement msg* syscalls Kirill A. Shutemov
2008-10-13 10:10       ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_sem* ipc calls handling Kirill A. Shutemov
2008-10-13 10:10         ` [Qemu-devel] [PATCH] Implement sem* syscalls Kirill A. Shutemov
2008-10-13 10:10           ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_shm* ipc calls handling Kirill A. Shutemov
2008-10-13 10:10             ` [Qemu-devel] [PATCH] Implement shm* syscalls Kirill A. Shutemov
2008-10-13 10:10               ` [Qemu-devel] [PATCH] Fix fstatat64()/newfstatat() syscall implementation Kirill A. Shutemov
2008-10-13 10:10                 ` [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option Kirill A. Shutemov
2008-10-08 18:54 [Qemu-devel] [PATCH] Add readahead syscall Kirill A. Shutemov
2008-10-08 18:54 ` [Qemu-devel] [PATCH] Fix getdents* syscalls Kirill A. Shutemov
2008-10-08 18:54   ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_msg* ipc calls handling Kirill A. Shutemov
2008-10-08 18:54     ` [Qemu-devel] [PATCH] Implement msg* syscalls Kirill A. Shutemov
2008-10-08 18:54       ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_sem* ipc calls handling Kirill A. Shutemov
2008-10-08 18:54         ` [Qemu-devel] [PATCH] Implement sem* syscalls Kirill A. Shutemov
2008-10-08 18:54           ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_shm* ipc calls handling Kirill A. Shutemov
2008-10-08 18:54             ` [Qemu-devel] [PATCH] Implement shm* syscalls Kirill A. Shutemov
2008-10-08 18:54               ` [Qemu-devel] [PATCH] Fix fstatat64()/newfstatat() syscall implementation Kirill A. Shutemov
2008-10-08 18:54                 ` [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option Kirill A. Shutemov

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=20090112141822.GA29074@kos.to \
    --to=riku.voipio@iki.fi \
    --cc=kirill@shutemov.name \
    --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).