From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LMNcf-0003hT-3U for qemu-devel@nongnu.org; Mon, 12 Jan 2009 09:18:33 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LMNcd-0003h9-7S for qemu-devel@nongnu.org; Mon, 12 Jan 2009 09:18:32 -0500 Received: from [199.232.76.173] (port=43459 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LMNcd-0003h6-0c for qemu-devel@nongnu.org; Mon, 12 Jan 2009 09:18:31 -0500 Received: from [84.20.150.76] (port=35000 helo=narury.org) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LMNcc-00012g-Ga for qemu-devel@nongnu.org; Mon, 12 Jan 2009 09:18:30 -0500 Date: Mon, 12 Jan 2009 16:18:22 +0200 From: Riku Voipio Subject: Re: [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option Message-ID: <20090112141822.GA29074@kos.to> References: <1228303789-25653-1-git-send-email-kirill@shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1228303789-25653-1-git-send-email-kirill@shutemov.name> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Kirill A. Shutemov" Cc: qemu-devel@nongnu.org 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 > --- > 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 = ®s1; > 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.