All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: QEMU <qemu-devel@nongnu.org>, Gerd Hoffmann <kraxel@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [RFC v2 04/12] Add vhost-user-backend
Date: Tue, 12 Jun 2018 16:53:54 +0200	[thread overview]
Message-ID: <CAJ+F1CLFJGhWVzPWGjQX78qSOQK8BZ7W0rkO6s-SsGpLqc-ObA@mail.gmail.com> (raw)
In-Reply-To: <20180608084325.GE18233@redhat.com>

Hi

On Fri, Jun 8, 2018 at 10:43 AM, Daniel P. Berrangé <berrange@redhat.com> wrote:
> On Fri, Jun 08, 2018 at 12:34:15AM +0200, Marc-André Lureau wrote:
>> Hi
>>
>> On Mon, Jun 4, 2018 at 11:36 AM, Daniel P. Berrangé <berrange@redhat.com> wrote:
>> > On Fri, Jun 01, 2018 at 06:27:41PM +0200, Marc-André Lureau wrote:
>> >> Create a vhost-user-backend object that holds a connection to a
>> >> vhost-user backend and can be referenced from virtio devices that
>> >> support it. See later patches for input & gpu usage.
>> >>
>> >> A chardev can be specified to communicate with the vhost-user backend,
>> >> ex: -chardev socket,id=char0,path=/tmp/foo.sock -object
>> >> vhost-user-backend,id=vuid,chardev=char0.
>> >>
>> >> Alternatively, an executable with its arguments may be given as 'cmd'
>> >> property, ex: -object
>> >> vhost-user-backend,id=vui,cmd="./vhost-user-input /dev/input..". The
>> >> executable is then spawn and, by convention, the vhost-user socket is
>> >> passed as fd=3. It may be considered a security breach to allow
>> >> creating processes that may execute arbitrary executables, so this may
>> >> be restricted to some known executables (via signature etc) or
>> >> directory.
>> >
>> > Passing a binary and args as a string blob.....
>> >
>> >> +static int
>> >> +vhost_user_backend_spawn_cmd(VhostUserBackend *b, int vhostfd, Error **errp)
>> >> +{
>> >> +    int devnull = open("/dev/null", O_RDWR);
>> >> +    pid_t pid;
>> >> +
>> >> +    assert(!b->child);
>> >> +
>> >> +    if (!b->cmd) {
>> >> +        error_setg_errno(errp, errno, "Missing cmd property");
>> >> +        return -1;
>> >> +    }
>> >> +    if (devnull < 0) {
>> >> +        error_setg_errno(errp, errno, "Unable to open /dev/null");
>> >> +        return -1;
>> >> +    }
>> >> +
>> >> +    pid = qemu_fork(errp);
>> >> +    if (pid < 0) {
>> >> +        close(devnull);
>> >> +        return -1;
>> >> +    }
>> >> +
>> >> +    if (pid == 0) { /* child */
>> >> +        int fd, maxfd = sysconf(_SC_OPEN_MAX);
>> >> +
>> >> +        dup2(devnull, STDIN_FILENO);
>> >> +        dup2(devnull, STDOUT_FILENO);
>> >> +        dup2(vhostfd, 3);
>> >> +
>> >> +        signal(SIGINT, SIG_IGN);
>> >
>> > Why ignore SIGINT ?  Surely we want this extra process to be killed
>> > someone ctrl-c's the parent QEMU.
>>
>> leftover, removed
>>
>> >
>> >> +
>> >> +        for (fd = 4; fd < maxfd; fd++) {
>> >> +            close(fd);
>> >> +        }
>> >> +
>> >> +        execlp("/bin/sh", "sh", "-c", b->cmd, NULL);
>> >
>> > ...which is then interpreted by the shell is a recipe for security
>> > flaws. There needs to be a way to pass the command + arguments
>> > to QEMU as an argv[] we can directly exec without involving the
>> > shell.
>> >
>>
>> For now, I use g_shell_parse_argv(). Do you have a better idea?
>
> Accept individual args at the cli level is far preferrable - we don't
> want anything to be parsing shell strings:
>
>  vhost-user-backend,id=vui,binary=/sbin/vhost-user-input,arg=/dev/input,arg=foo,arg=bar

Object arguments are populated in a dictionary. Only the last value
specified is used.

g_shell_parse_argv() isn't that scary imho. But if there is a
blacklist of functions, it would be worth to have them listed
somewhere.

  reply	other threads:[~2018-06-12 14:53 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01 16:27 [Qemu-devel] [RFC v2 00/12] vhost-user for input & GPU Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 01/12] chardev: avoid crash if no associated address Marc-André Lureau
2018-06-08 14:52   ` Philippe Mathieu-Daudé
2018-06-11  8:59     ` Daniel P. Berrangé
2018-06-11  9:04   ` Daniel P. Berrangé
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 02/12] libvhost-user: exit by default on VHOST_USER_NONE Marc-André Lureau
2018-06-08 14:48   ` Philippe Mathieu-Daudé
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 03/12] vhost-user: wrap some read/write with retry handling Marc-André Lureau
2018-06-08 14:53   ` Philippe Mathieu-Daudé
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 04/12] Add vhost-user-backend Marc-André Lureau
2018-06-04  9:36   ` Daniel P. Berrangé
2018-06-07 22:34     ` Marc-André Lureau
2018-06-08  8:43       ` Daniel P. Berrangé
2018-06-12 14:53         ` Marc-André Lureau [this message]
2018-06-12 15:08           ` Daniel P. Berrangé
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 05/12] vhost-user: split vhost_user_read() Marc-André Lureau
2018-06-08 14:57   ` Philippe Mathieu-Daudé
2018-06-12 14:58     ` Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 06/12] vhost-user: add vhost_user_input_get_config() Marc-André Lureau
2018-06-04  9:07   ` Dr. David Alan Gilbert
2018-06-04  9:18     ` Marc-André Lureau
2018-06-04  9:59       ` Dr. David Alan Gilbert
2018-06-12 12:46         ` Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 07/12] libvhost-user: export vug_source_new Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 08/12] contrib: add vhost-user-input Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 09/12] Add vhost-input-pci Marc-André Lureau
2018-06-04  8:58   ` Gerd Hoffmann
2018-06-07 22:22     ` Marc-André Lureau
2018-06-08  5:41       ` Gerd Hoffmann
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 10/12] vhost-user: add vhost_user_gpu_set_socket() Marc-André Lureau
2018-06-04  9:28   ` Gerd Hoffmann
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 11/12] Add virtio-gpu vhost-user backend Marc-André Lureau
2018-06-04  9:37   ` Gerd Hoffmann
2018-06-08 17:25     ` Marc-André Lureau
2018-06-09  1:02       ` Marc-André Lureau
2018-06-11  6:49       ` Gerd Hoffmann
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 12/12] contrib: add vhost-user-gpu Marc-André Lureau
2018-06-01 17:28 ` [Qemu-devel] [RFC v2 00/12] vhost-user for input & GPU 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=CAJ+F1CLFJGhWVzPWGjQX78qSOQK8BZ7W0rkO6s-SsGpLqc-ObA@mail.gmail.com \
    --to=marcandre.lureau@gmail.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=kraxel@redhat.com \
    --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.