All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: Michael Tokarev <mjt@tls.msk.ru>, qemu-devel@nongnu.org
Cc: Helge Deller <deller@gmx.de>,
	John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Subject: Re: [PATCH] linux-user: manage binfmt-misc preserve-arg[0] flag
Date: Mon, 22 Feb 2021 18:09:02 +0100	[thread overview]
Message-ID: <995d4f7d-3afc-f0f6-0a86-c1eb0488bfa1@vivier.eu> (raw)
In-Reply-To: <3b5b0aa0-6fde-3e71-0e69-6bf127e9c627@msgid.tls.msk.ru>

Le 22/02/2021 à 15:45, Michael Tokarev a écrit :
> 22.02.2021 13:50, Laurent Vivier wrote:
>> Add --preserve-argv0 in qemu-binfmt-conf.sh to configure the preserve-argv0
>> flag.
>>
>> This patch allows to use new flag in AT_FLAGS to detect if
>> preserve-argv0 is configured for this interpreter:
>> argv[0] (the full pathname provided by binfmt-misc) is removed and
>> replaced by argv[1] (the original argv[0] provided by binfmt-misc when
>> 'P'/preserve-arg[0] is set)
> 
> A few days ago I sent an RFC patch which fixes this issue without kernel
> patch, by registering special binary name in binfmt (note: that patch had
> argv[1] & argv[2] swapped by mistake).
> 
> Here it is: https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg04639.html
>
In this case, we don't want to modify QEMU to manage special case based on the binary name but
instead use a wrapper:

- add a proper parameter to manage the argv0 case
  [like this one https://patchew.org/QEMU/20191024153847.31815-1-laurent@vivier.eu/
   but I think now it would be better to use a new flag rather than using -0 ""]

- write a wrapper and name it "/usr/libexec/qemu-binfmt/foo-binfmt-P"

- the wrapper will call qemu-foo with the new parameter:

something like (with the example patch above):

#include <stdio.h>
#include <unistd.h>
#include <string.h>

static const char *baseargv[] = {
        "-0",
        "",
};

int main(int argc, char **argv, char **envp) {
        char *newargv[argc + sizeof(baseargv) / sizeof(char *) + 1];
        int current = 0;

        newargv[current] = argv[0];
        current++;

        memcpy(&newargv[current], baseargv, sizeof(baseargv));
        current += sizeof(baseargv) / sizeof(char *);

        memcpy(&newargv[current], &argv[1], sizeof(*argv) * (argc - 1));
        current += argc - 1;

        newargv[current] = NULL;

        return execve("/qemu-foo", newargv, envp);
}

Thanks,
Laurent


  reply	other threads:[~2021-02-22 17:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22 10:50 [PATCH] linux-user: manage binfmt-misc preserve-arg[0] flag Laurent Vivier
2021-02-22 10:57 ` no-reply
2021-02-22 10:58 ` John Paul Adrian Glaubitz
2021-02-22 12:21   ` Laurent Vivier
2021-02-22 14:38   ` Michael Tokarev
2021-02-22 14:43     ` John Paul Adrian Glaubitz
2021-02-22 14:46       ` Michael Tokarev
2021-02-22 14:54         ` John Paul Adrian Glaubitz
2021-02-22 14:58           ` Michael Tokarev
2021-02-22 15:02             ` Helge Deller
2021-02-22 15:11               ` Michael Tokarev
2021-02-22 15:09             ` John Paul Adrian Glaubitz
2021-02-22 15:15               ` Michael Tokarev
2021-03-01 10:35             ` John Paul Adrian Glaubitz
2021-03-01 10:40               ` Michael Tokarev
2021-03-01 11:07                 ` John Paul Adrian Glaubitz
2021-03-01 11:16                   ` Michael Tokarev
2021-03-01 11:35                     ` John Paul Adrian Glaubitz
2021-02-22 14:45 ` Michael Tokarev
2021-02-22 17:09   ` Laurent Vivier [this message]
2021-02-22 20:07     ` Michael Tokarev
2021-03-09 20:15 ` Laurent Vivier
2021-09-06 18:00 ` Michael Tokarev

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=995d4f7d-3afc-f0f6-0a86-c1eb0488bfa1@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=deller@gmx.de \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=mjt@tls.msk.ru \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.