From: Patrick Ohly <patrick.ohly@intel.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, Amarnath Valluri <amarnath.valluri@intel.com>
Subject: Re: [Qemu-devel] RFC: connecting chardev to a command forked by qemu
Date: Mon, 06 Nov 2017 22:02:05 +0100 [thread overview]
Message-ID: <1510002125.22094.10.camel@intel.com> (raw)
In-Reply-To: <20171106172646.GO23361@redhat.com>
On Mon, 2017-11-06 at 17:26 +0000, Daniel P. Berrange wrote:
> I can see the argument about it making QEMU easier to use, and those
> who care about security aren't forced to use this new feature. It
> none the less has a cost on maintainers and existance of these
> features does reflect on QEMU's security reputation even if many
> don't use it.
With Yocto we really don't have much choice: we need a patch like this
because the alternative (introducing support for spawning and stopping
swtpm and then passing the right parameters to QEMU) is way more
complex. So if this patch isn't acceptable to QEMU upstream, then I
will keep it as simple as possible and propose it as a local patch in
Yocto.
But that then won't help others who might be using QEMU in a similar
situation.
> > +static void chardev_open_socket_cmd(Chardev *chr,
> > + const char *cmd,
> > + Error **errp)
> > +{
> > + int fds[2] = { -1, -1 };
> > + QIOChannelSocket *sioc = NULL;
> > + pid_t pid = -1;
> > + const char *argv[] = { "/bin/sh", "-c", cmd, NULL };
> > +
> > + if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds)) {
> > + error_setg_errno(errp, errno, "Error creating
> > socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC)");
> > + goto error;
> > + }
> > +
> > + pid = qemu_fork(errp);
> > + if (pid < 0) {
> > + goto error;
> > + }
> > +
> > + if (!pid) {
> > + /* child */
> > + dup2(fds[1], STDIN_FILENO);
> > + execv(argv[0], (char * const *)argv);
> > + _exit(1);
> > + }
> > +
> > + /*
> > + * Hand over our end of the socket pair to the qio channel.
> > + * TODO: We don't reap the child at the moment.
> > + */
> > + sioc = qio_channel_socket_new_fd(fds[0], errp);
>
> NB, you've mostly re-invented qio_channel_command_new_spawn() here,
> though you're using a socketpair instead of pipe, which has the
> slight benefit of meaning we can do FD passing across the external
> command.
Yes, that's exactly the reason. swtpm depends on a bidirectional stream
with support for FD passing. I should have added that an option for a
new "-charset cmd" might be to choose two uni-direction pipes connected
to stdin/stdout of the command. That would be useful for some other
commands.
> If the latter is why you chose socketpair, then it would
> be nice to improve QIOChannelCommand
Yes, that would be better. But before touching too many different files
and thus increasing the risk of merge conflicts (which is an issue when
maintaining the patch downstream) I'd like to get a feeling for whether
it's worth enhancing the patch to make it suitable for upstream or
whether there are strong reasons to never include anything like it.
--
Best Regards, Patrick Ohly
The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.
next prev parent reply other threads:[~2017-11-06 21:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-06 17:11 [Qemu-devel] RFC: connecting chardev to a command forked by qemu Patrick Ohly
2017-11-06 17:26 ` Daniel P. Berrange
2017-11-06 21:02 ` Patrick Ohly [this message]
2017-11-07 9:23 ` Daniel P. Berrange
2017-11-07 9:38 ` Patrick Ohly
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=1510002125.22094.10.camel@intel.com \
--to=patrick.ohly@intel.com \
--cc=amarnath.valluri@intel.com \
--cc=berrange@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 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).