All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Laurent Vivier <laurent@vivier.eu>, qemu-devel@nongnu.org
Subject: Re: [PATCH] linux-user: manage binfmt-misc preserve-arg[0] flag
Date: Mon, 06 Sep 2021 21:00:15 +0300	[thread overview]
Message-ID: <1630951215.539408.2031188.nullmailer@msgid.tls.msk.ru> (raw)
In-Reply-To: <20210222105004.1642234-1-laurent@vivier.eu>

> Add --preserve-argv0 in qemu-binfmt-conf.sh to configure the preserve-argv0
> flag.
...
> diff --git a/linux-user/main.c b/linux-user/main.c
> @@ -697,6 +707,20 @@ int main(int argc, char **argv, char **envp)
>          }
>      }
>  
> +    /*
> +     * get binfmt_misc flags
> +     */
> +    preserve_argv0 = !!(qemu_getauxval(AT_FLAGS) & AT_FLAGS_PRESERVE_ARGV0);
> +
> +    /*
> +     * Manage binfmt-misc preserve-arg[0] flag
> +     *    argv[optind]     full path to the binary
> +     *    argv[optind + 1] original argv[0]
> +     */
> +    if (optind + 1 < argc && preserve_argv0) {
> +        optind++;
> +    }

Please note: this code is executed after parse_args() which is called
way up. And parse_args were able to mess up with the options & optind.

This is sort of a corner case really, but we rely on argv[1][0] being
!= '-'.  I think it is better to explicitly omit a call to parse_args()
for the AT_FLAGS_PRESERVE_ARGV0 case.  But parse_args() apparently is
a misnomer, since it also parses $ENVironment variables - this part
apparently should be run either way.

I noticed this because this interferes with my change in this area that
enables similar functionality (detecting the binfmt usage) but without
requiring any kernel changes and working with any version of kernel (it
has been discussed previously) - with both my code and this code in place
and the patched kernel, we update optind TWICE, one in parse_args() and
second here.  This caused someone filesystem to be wiped out already due
to wrong options being used.

Thanks,

/mjt


      parent reply	other threads:[~2021-09-06 18:04 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
2021-02-22 20:07     ` Michael Tokarev
2021-03-09 20:15 ` Laurent Vivier
2021-09-06 18:00 ` Michael Tokarev [this message]

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=1630951215.539408.2031188.nullmailer@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --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 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.