All of lore.kernel.org
 help / color / mirror / Atom feed
From: Erik Skultety <eskultet@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Singh, Brijesh" <brijesh.singh@amd.com>,
	"libvir-list@redhat.com" <libvir-list@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"dinechin@redhat.com" <dinechin@redhat.com>,
	"mkletzan@redhat.com" <mkletzan@redhat.com>
Subject: Re: [Qemu-devel] AMD SEV's /dev/sev permissions and probing QEMU for capabilities
Date: Wed, 23 Jan 2019 14:33:01 +0100	[thread overview]
Message-ID: <20190123133301.GB20002@beluga.usersys.redhat.com> (raw)
In-Reply-To: <20190123132413.GG27270@redhat.com>

On Wed, Jan 23, 2019 at 01:24:13PM +0000, Daniel P. Berrangé wrote:
> On Wed, Jan 23, 2019 at 02:22:12PM +0100, Erik Skultety wrote:
> > On Wed, Jan 23, 2019 at 01:10:42PM +0000, Daniel P. Berrangé wrote:
> > > On Wed, Jan 23, 2019 at 01:55:06PM +0100, Erik Skultety wrote:
> > > > On Fri, Jan 18, 2019 at 12:51:50PM +0000, Singh, Brijesh wrote:
> > > > >
> > > > > On 1/18/19 3:39 AM, Erik Skultety wrote:
> > > > > > Hi,
> > > > > > this is a summary of a private discussion I've had with guys CC'd on this email
> > > > > > about finding a solution to [1] - basically, the default permissions on
> > > > > > /dev/sev (below) make it impossible to query for SEV platform capabilities,
> > > > > > since by default we run QEMU as qemu:qemu when probing for capabilities. It's
> > > > > > worth noting is that this is only relevant to probing, since for a proper QEMU
> > > > > > VM we create a mount namespace for the process and chown all the nodes (needs a
> > > > > > SEV fix though).
> > > > > >
> > > > > > # ll /dev/sev
> > > > > > crw-------. 1 root root
> > > > > >
> > > > > > I suggested either force running QEMU as root for probing (despite the obvious
> > > > > > security implications) or using namespaces for probing too. Dan argued that
> > > > > > this would have a significant perf impact and suggested we ask systemd to add a
> > > > > > global udev rule.
> > > > > >
> > > > > > I proceeded with cloning [1] to systemd and creating an udev rule that I planned
> > > > > > on submitting to systemd upstream - the initial idea was to mimic /dev/kvm and
> > > > > > make it world accessible to which Brijesh from AMD expressed a concern that
> > > > > > regular users might deplete the resources (limit on the number of guests
> > > > > > allowed by the platform).
> > > > >
> > > > >
> > > > > During private discussion I didn't realized that we are discussing a
> > > > > probe issue hence things I have said earlier may not be applicable
> > > > > during the probe. The /dev/sev is managed by the CCP (aka PSP) driver.
> > > > > The /dev/sev is used for communicating with the SEV FW running inside
> > > > > the PSP. The SEV FW offers platform and guest specific services. The
> > > > > guest specific services are used during the guest launch, these services
> > > > > are available through KVM driver only. Whereas the platform services can
> > > > > be invoked at anytime. A typical platform specific services are:
> > > > >
> > > > > - importing certificates
> > > > >
> > > > > - exporting certificates
> > > > >
> > > > > - querying the SEV FW version etc etc
> > > > >
> > > > > In case of the probe we are not launch SEV guest hence we should not be
> > > > > worried about depleting the SEV ASID resources.
> > > > >
> > > > > IIRC, libvirt uses QEMP query-sev-capabilities to probe the SEV support.
> > > > > QEMU executes the below sequence to complete the request:
> > > > >
> > > > > 1. Exports the platform certificates  (this is when /dev/sev is accessed).
> > > > >
> > > > > 2. Read the host MSR to determine the C-bit and reduced phys-bit position
> > > > >
> > > > > I don't see any reason why we can't give world a 'read' permission to
> > > > > /dev/sev. Anyone should be able to export the certificates and query
> > > >
> > > > Okay, makes sense to me. The problem I see is the sev_platform_ioctl function
> > > > in QEMU which makes an _IOWR request, therefore the file descriptor being
> > > > opened in sev_get_capabilities is O_RDWR. Now, I only understand ioctl from
> > > > what I've read in the man page, so I don't quite understand the need for IOWR
> > > > here - but my honest guess would be that it's because the commands like
> > > > SEV_PDH_CERT_EXPORT or SEV_PLATFORM_STATUS need to be copied from userspace to
> > > > kernel to instruct kernel which services we want, ergo _IOWR, is that right?
> > >
> > > I'm not seeing any permissions checks in the sev_ioctl() function in the
> > > kernel, so IIUC, that means any permissions are entirely based on whether
> > > you can open the /dev/sev, once open you can run any ioctl.  What, if anything,
> > > enforces which ioctls you can run when the device is only O_RDONLY vs O_RDWR ?
> >
> > I don't know, that's why I'm asking, because the manual didn't make it any
> > clear for me whether there's a connection between the device permissions and
> > ioctls that you're allowed to run.
> >
> > >
> > > > In any case, a fix of some sort needs to land in QEMU first, because no udev
> > > > rule would fix the current situation. Afterwards, I expect that having a rule
> > > > like this:
> > > >
> > > > KERNEL=="sev", GROUP="kvm", MODE="0644"
> > > >
> > > > and a selinux policy rule adding the kvm_device_t label, we should be fine, do
> > > > we agree on that?
> > >
> > > Based on what I think I see above, this looks like a bad idea.
> > >
> > > It still looks like we can solve this entirely in libvirt by just giving
> > > the libvirt capabilities probing code CAP_DAC_OVERRIDE. This would make
> > > libvirt work for all currently released SEV support in kernel/qemu.
> >
> > Sure we can, but that would make libvirt the only legitimate user of /dev/sev
> > and everything else would require the admin to change the permissions
> > explicitly so that other apps could at least retrieve the platform info, if
> > it was intended to be for public use?
> > Additionally, we'll still get shot down by SELinux because svirt_t wouldn't be
> > able to access /dev/sev by default.
>
> That's separate form probing and just needs SELinux policy to define
> a new  sev_device_t type and grant svirt_t access to it.

I know, I misread "we can solve this entirely in libvirt" then, I thought you
the SELinux part was included in the statement, my bad then. Still, back to the
original issue, we could technically do both, libvirt would have run qemu with
CAP_DAC_OVERRIDE and we keep working with everything's been released for
SEV in kernel/qemu and for everyone else, systemd might add 0644 for /dev/sev,
that way, everyone's happy, not that I'd be a fan of libvirt often having
to work around something because projects underneath wouldn't backport fixes to
all the distros we support, thus leaving the dirty work to us.

Erik

  reply	other threads:[~2019-01-23 13:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-18  9:39 [Qemu-devel] AMD SEV's /dev/sev permissions and probing QEMU for capabilities Erik Skultety
2019-01-18 10:16 ` Daniel P. Berrangé
2019-01-18 10:56   ` [Qemu-devel] [libvirt] " Erik Skultety
2019-01-18 11:11   ` [Qemu-devel] " Martin Kletzander
2019-01-18 11:17     ` Daniel P. Berrangé
2019-01-18 11:31       ` Martin Kletzander
2019-01-18 12:51 ` Singh, Brijesh
2019-01-23 12:55   ` Erik Skultety
2019-01-23 13:10     ` Daniel P. Berrangé
2019-01-23 13:22       ` Erik Skultety
2019-01-23 13:24         ` Daniel P. Berrangé
2019-01-23 13:33           ` Erik Skultety [this message]
2019-01-23 13:36             ` Daniel P. Berrangé
2019-01-23 15:02               ` Singh, Brijesh
2019-01-23 15:29                 ` Erik Skultety
2019-01-29 16:15                 ` Erik Skultety
2019-01-29 18:40                   ` Daniel P. Berrangé
2019-01-30  8:06                     ` Erik Skultety
2019-01-30 10:37                       ` Daniel P. Berrangé
2019-01-30 13:39                         ` Erik Skultety
2019-01-30 17:47                           ` Singh, Brijesh
2019-01-30 18:18                           ` Daniel P. Berrangé
2019-01-31 15:28                             ` Erik Skultety

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=20190123133301.GB20002@beluga.usersys.redhat.com \
    --to=eskultet@redhat.com \
    --cc=berrange@redhat.com \
    --cc=brijesh.singh@amd.com \
    --cc=dinechin@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=mkletzan@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.