Re: [RFC PATCH 03/23] x86/sgx: Introduce virtual EPC for use by KVM guests

Dave Hansen
2021-01-15T15:40:46Z

On 1/15/21 6:07 AM, Kai Huang wrote:
>>From virtual EPC's perspective, if we don't force this in kernel, then
> *theoretically*, userspace can use fork() to make multiple VMs map to the
> same physical EPC, which will potentially cause enclaves in all VMs to behave
> abnormally. So to me, from this perspective, it's better to enforce in kernel
> so that only first VM can use this virtual EPC instance, because EPC by
> architectural design cannot be shared.
>
> But as Sean said, KVM doesn't support VM across multiple mm structs. And if I
> read code correctly, KVM doesn't support userspace to use fork() to create new
> VM. For instance, when creating VM, KVM grabs current->mm and keeps it in
> 'struct kvm' for bookkeeping, and kvm_vcpu_ioctl() and kvm_device_ioctl() will
> refuse to work if kvm->mm doesn't equal to current->mm. So in practice, I
> believe w/o enforcing this in kernel, we should also have no problem here.
>
> Sean, please correct me if I am wrong.
>
> Dave, if above stands, do you think it is reasonable to keep current->mm in
> epc->mm and enforce in sgx_virt_epc_mmap()?

Everything you wrote above tells me the kernel should not be enforcing
the behavior. You basically said that it's only a theoretical problem,
and old if someone goes and does something with KVM that's nobody can do
today.

You've 100% convinced me that having the kernel enforce this is
*un*reasonable.