qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Yamamoto <yamamoto@midokura.com>
To: Laurent Vivier <laurent@vivier.eu>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v2 01/11] linux-user: handle /proc/self/exe for execve
Date: Mon, 21 Jun 2021 11:02:59 +0900	[thread overview]
Message-ID: <CAH=wFzS_-q4wRauFPKLrAf6p=oew_Ja+QpEvpyX97sYC39LnmQ@mail.gmail.com> (raw)
In-Reply-To: <5c344989-6b77-5cb7-4e2d-953350fe9834@vivier.eu>

On Sun, Jun 20, 2021 at 11:14 PM Laurent Vivier <laurent@vivier.eu> wrote:
>
> Le 31/05/2021 à 07:50, YAMAMOTO Takashi a écrit :
> > It seems somehow common to execve /proc/self/exe in docker
> > or golang community these days.
> > At least, moby "reexec" and runc "libcontainer" do that.
> >
> > Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
> > ---
> >  linux-user/syscall.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > index c9f812091c..a2b03ecb8b 100644
> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -8470,6 +8470,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
> >  #endif
> >      case TARGET_NR_execve:
> >          {
> > +            const char *path;
> >              char **argp, **envp;
> >              int argc, envc;
> >              abi_ulong gp;
> > @@ -8537,7 +8538,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
> >               * before the execve completes and makes it the other
> >               * program's problem.
> >               */
> > -            ret = get_errno(safe_execve(p, argp, envp));
> > +            path = p;
> > +            if (is_proc_myself(path, "exe")) {
> > +                path = exec_path;
> > +            }
> > +            ret = get_errno(safe_execve(path, argp, envp));
> >              unlock_user(p, arg1, 0);
> >
> >              goto execve_end;
> >
>
> The problem here is QEMU can fail to execute the file directly.

i don't understand this sentence. can you explain a bit?

>
> The binary can be launched with binfmt_misc and the 'O' flag:
>
>      ``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. This feature
>             should be used with care - the interpreter has to be trusted not to
>             emit the contents of the non-readable binary.
>
> You should use do_openat() (that resolves the /proc/self/exe path) and fexecve().

i thought there was an issue with the approach. but i don't remember
what it was.
maybe i will retry it.

>
> Thanks,
> Laurent


  reply	other threads:[~2021-06-21  2:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31  5:50 [PATCH v2 00/11] linux-user changes to run docker YAMAMOTO Takashi
2021-05-31  5:50 ` [PATCH v2 01/11] linux-user: handle /proc/self/exe for execve YAMAMOTO Takashi
2021-06-20 14:14   ` Laurent Vivier
2021-06-21  2:02     ` Takashi Yamamoto [this message]
2021-06-22 13:47       ` Laurent Vivier
2021-05-31  5:50 ` [PATCH v2 02/11] linux-user: Fix the execfd case of /proc/self/exe open YAMAMOTO Takashi
2021-06-20 14:16   ` Laurent Vivier
2021-06-21  1:19     ` Takashi Yamamoto
2021-05-31  5:50 ` [PATCH v2 03/11] linux-user: dup the execfd on start up YAMAMOTO Takashi
2021-05-31  5:50 ` [PATCH v2 04/11] linux-user: make exec_path realpath YAMAMOTO Takashi
2021-05-31  5:50 ` [PATCH v2 05/11] linux-user: Implement pivot_root YAMAMOTO Takashi
2021-06-20 14:02   ` Laurent Vivier
2021-06-20 14:05   ` Laurent Vivier
2021-05-31  5:50 ` [PATCH v2 06/11] linux-user: add get_exe_path YAMAMOTO Takashi
2021-05-31  5:50 ` [PATCH v2 07/11] linux-user: simplify is_proc_myself YAMAMOTO Takashi
2021-05-31  5:50 ` [PATCH v2 08/11] linux-user: Implement exec of /proc/$pid/exe of qemu process YAMAMOTO Takashi
2021-05-31  5:50 ` [PATCH v2 09/11] linux-user: Make the qemu detection for /proc/$pid/exe a bit conservative YAMAMOTO Takashi
2021-05-31  5:50 ` [PATCH v2 10/11] linux-user: a crude hack for libcontainer (CLONE_PARENT) [!MERGE] YAMAMOTO Takashi
2021-05-31  5:50 ` [PATCH v2 11/11] linux-user: always assume preserve_argv0 for now [!MERGE] YAMAMOTO Takashi
2021-05-31  6:07 ` [PATCH v2 00/11] linux-user changes to run docker 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='CAH=wFzS_-q4wRauFPKLrAf6p=oew_Ja+QpEvpyX97sYC39LnmQ@mail.gmail.com' \
    --to=yamamoto@midokura.com \
    --cc=laurent@vivier.eu \
    --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).