Re: x86/sgx: uapi change proposal
From: Sean Christopherson
Date: Thu Jan 10 2019 - 20:32:11 EST
On Thu, Jan 10, 2019 at 04:30:06PM -0800, Andy Lutomirski wrote:
> On Thu, Jan 10, 2019 at 3:54 PM Sean Christopherson
> <sean.j.christopherson@xxxxxxxxx> wrote:
> >
> > Sort of. A guest that is running under KVM (i.e. VMX) is much more
> > contained than a random userspace program. A rogue enclave in a VMX
> > guest can attack the guest kernel/OS, but barring a bug (or more likely,
> > several major bugs) elsewhere in the virtualization stack the enclave
> > can't do anything nasty to the host. An enclave would let someone hide
> > code, but enclaves are even more restricted than cpl3, i.e. there's not
> > a lot it can do without coordinating with unencrypted code in the guest.
> >
> > And if someone has sufficient permissions to run a KVM guest, they're
> > much more likely to do something malcious in the guest kernel, not an
> > enclave.
>
> Are you sure? On my laptop, /dev/kvm is 0666, and that's the distro
> default. I don't think this is at all unusual.
Wow, that's suprising. A quick search suggests that this may be Debian
specific[1], e.g. my Ubuntu systems have:
crw-rw---- 1 root kvm 10, 232 Jan 9 09:30 /dev/kvm
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1431876
> I'm not particularly
> concerned about a guest attacking itself, but it's conceptually
> straightforward to bypass whatever restrictions the host has by simply
> opening /dev/kvm and sticking your enclave in a VM.
VMs by nature allow a user to bypass all sorts of restrictions, e.g. the
kernel doesn't let userspace run arbitrary cpl0 code, but launch a VM
and voila. It's what you can do with the new privileges that matters.
> > All that aside, I don't see any justification for singling out SGX for
> > extra scrutiny, there are other ways for a user with KVM permissions to
> > hide malicious code in guest (and at cpl0!), e.g. AMD's SEV{-ES}.
>
> I'm not singling out SGX. I'm just saying that the KVM should not
> magically bypass host policy. If you want to assign a virtual
> function on your NIC to a KVM guest, you need to give your QEMU
> process that privilege. Similarly, if someone has a MAC policy that
> controls which processes can launch which enclaves and they want to
> run Windows with full SGX support in a VM guest, then they should
> authorize that in their MAC policy by giving QEMU unrestricted launch
> privileges.
MAC systems exist to protect assets, and IMO an enclave isn't an asset.
E.g. AppArmor (via LSM) isn't protecting files, it's protecting the
contents of the file or what can be done with the file. And the MAC
is only part of the overall protection scheme, e.g. userspace is also
relying on the kernel to not screw up the page tables.
In SGX terms, a LSM hook might use enclave signatures to protect some
asset 'X', e.g. access to persistent identifier. But that doesn't mean
that whitelisting enclave signatures is the only way to protect 'X'.
> Similarly, if access to a persistent provisioning identifier is
> restricted, access to /dev/kvm shouldn't magically bypass it. Just
> give the QEMU process the relevant privileges.
Agreed, but that's not same as applying a host's whitelist against a
guest's enclaves.