From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Ján Tomko" <jtomko@redhat.com>
Cc: libvir-list@redhat.com, virtio-fs@redhat.com
Subject: Re: [Virtio-fs] [libvirt PATCHv3 10/12] qemu: add code for handling virtiofsd
Date: Mon, 3 Feb 2020 19:03:16 +0000 [thread overview]
Message-ID: <20200203190316.GC1922177@redhat.com> (raw)
In-Reply-To: <20200203183609.GX18565@lpt>
On Mon, Feb 03, 2020 at 07:36:09PM +0100, Ján Tomko wrote:
> [adding virtiofs list]
>
> On Mon, Feb 03, 2020 at 04:43:51PM +0000, Daniel P. Berrangé wrote:
> > On Thu, Jan 30, 2020 at 06:06:26PM +0100, Ján Tomko wrote:
> > > Start virtiofsd for each <filesystem> device using it.
> > >
> > > Pre-create the socket for communication with QEMU and pass it
> > > to virtiofsd.
> > >
> > > Note that virtiofsd needs to run as root.
> >
> > So we're not able to use virtiofsd with the session libvirtd
> > which runs completely unprivileged ?
> >
>
> Not with the version of virtiofsd currently merged in the QEMU tree.
>
> > I can understand the need to run as root if we want to support
> > chown() of files, or DAC_OVERRIDE, but I'm surprised it isn't
> > possible to run virtiofsd unprivileged & simply have a reduced
> > featureset where it can only create files as that one user.
> >
>
> Apart from the possibly missing features (I don't know how well
> virtiofsd internals are ready for those), current version of the
> daemon sets up namespaces and the seccomp sandbox.
>
> >
> > > +int
> > > +qemuVirtioFSStart(virLogManagerPtr logManager,
> > > + virQEMUDriverPtr driver,
> > > + virDomainObjPtr vm,
> > > + virDomainFSDefPtr fs)
> > > +{
> > > + g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
> > > + g_autoptr(virCommand) cmd = NULL;
> > > + g_autofree char *socket_path = NULL;
> > > + g_autofree char *pidfile = NULL;
> > > + g_autofree char *logpath = NULL;
> > > + pid_t pid = (pid_t) -1;
> > > + VIR_AUTOCLOSE fd = -1;
> > > + VIR_AUTOCLOSE logfd = -1;
> > > + int ret = -1;
> > > + int rc;
> >
> > > +
> > > + if (!(pidfile = qemuVirtioFSCreatePidFilename(cfg, vm->def, fs->info.alias)))
> > > + goto cleanup;
> > > +
> > > + if (!(socket_path = qemuVirtioFSCreateSocketFilename(vm, fs->info.alias)))
> > > + goto cleanup;
> > > +
> > > + if ((fd = qemuVirtioFSOpenChardev(driver, vm, socket_path)) < 0)
> > > + goto cleanup;
> > > +
> > > + logpath = qemuVirtioFSCreateLogFilename(cfg, vm->def, fs->info.alias);
> > > +
> > > + if (cfg->stdioLogD) {
> > > + if ((logfd = virLogManagerDomainOpenLogFile(logManager,
> > > + "qemu",
> > > + vm->def->uuid,
> > > + vm->def->name,
> > > + logpath,
> > > + 0,
> > > + NULL, NULL)) < 0)
> > > + goto cleanup;
> > > + } else {
> > > + if ((logfd = open(logpath, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) < 0) {
> > > + virReportSystemError(errno, _("failed to create logfile %s"),
> > > + logpath);
> > > + goto cleanup;
> > > + }
> > > + if (virSetCloseExec(logfd) < 0) {
> > > + virReportSystemError(errno, _("failed to set close-on-exec flag on %s"),
> > > + logpath);
> > > + goto error;
> > > + }
> > > + }
> > > +
> > > + if (!(cmd = qemuVirtioFSBuildCommandLine(cfg, fs, &fd)))
> > > + goto cleanup;
> > > +
> > > + virCommandSetPidFile(cmd, pidfile);
> > > + virCommandSetOutputFD(cmd, &logfd);
> > > + virCommandSetErrorFD(cmd, &logfd);
> > > + virCommandNonblockingFDs(cmd);
> > > + virCommandDaemonize(cmd);
> >
> > We're not mandating "root" here, it is just inheriting the user that
> > libvirtd runs as. So IIUC ,this will run virtofsd as non-root when
> > used with session libvirtd, unless there's a check somewhere else
> > that prevents this scenario ?
>
> I'll add a check.
>
> >
> > I'm also wondering about cgroups placement in this method, and
> > any use of SELinux
> >
>
> Placing it into a cgroup should be easy, AFAIK it does not need to
> access any devices.
>
> As for SELinux, I don't think there's anything to be done other than
> updating the selinux-policy. Recursively relabeling the whole directory
> feels intrusive.
Even if we don't do relabelling, we'll still need more than just
policy work I believe.
If we assume a new "virtiofsd_t" SELinux type.
Ff QEMU is launched svirt_t:s0:c123,c532, we will need to
explicitly spawn virtiofsd with the matching MCS category
eg virtiofsd_t:s0:c123,c532. The policy should be written such
that the UNIX domain socket used for comms between QEMU and
virtiofsd requires this matching MCS category label.
This ensures that QEMU Guest-A can't connect to a virtiofsd used
by QEMU Guest-B and vica-verca.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2020-02-03 19:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1580403751.git.jtomko@redhat.com>
[not found] ` <484b10cf2a837ba7bc13400321978aa2076f0967.1580403751.git.jtomko@redhat.com>
[not found] ` <20200203164351.GV1922177@redhat.com>
2020-02-03 18:36 ` [Virtio-fs] [libvirt PATCHv3 10/12] qemu: add code for handling virtiofsd Ján Tomko
2020-02-03 19:03 ` Daniel P. Berrangé [this message]
2020-02-06 13:46 ` Stefan Hajnoczi
2020-02-06 13:56 ` Daniel P. Berrangé
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=20200203190316.GC1922177@redhat.com \
--to=berrange@redhat.com \
--cc=jtomko@redhat.com \
--cc=libvir-list@redhat.com \
--cc=virtio-fs@redhat.com \
/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.