Re: [RFC PATCH 4/4] x86/vdso: Add __vdso_sgx_eenter() to wrap SGX enclave transitions
From: Sean Christopherson
Date: Thu Dec 06 2018 - 09:17:22 EST
On Thu, Dec 06, 2018 at 05:55:47AM -0800, Sean Christopherson wrote:
> On Wed, Dec 05, 2018 at 03:40:48PM -0800, Andy Lutomirski wrote:
> > On Wed, Dec 5, 2018 at 3:20 PM Sean Christopherson
> > <sean.j.christopherson@xxxxxxxxx> wrote:
> > > +notrace long __vdso_sgx_eenter(void *tcs, void *priv,
> > > + struct sgx_eenter_fault_info *fault_info)
> > > +{
> > > + u32 trapnr, error_code;
> > > + long leaf;
> > > + u64 addr;
> > > +
> > > + /*
> > > + * %eax = EENTER
> > > + * %rbx = tcs
> > > + * %rcx = do_eresume
> > > + * %rdi = priv
> > > + * do_eenter:
> > > + * enclu
> > > + * jmp out
> > > + *
> > > + * do_eresume:
> > > + * enclu
> > > + * ud2
> >
> > Is the only reason for do_eresume to be different from do_eenter so
> > that you can do the ud2?
>
> No, it was a holdover from doing fixup via a magic prefix in user code.
> The fixup could only skip the ENCLU and so a second ENCLU was needed to
> differentiate between EENTER and ERESUME. The need for two ENCLUs got
> ingrained in my head. I can't think of anything that will break if we
> use a single ENCLU.
>
> > > + *
> > > + * out:
> > > + * <return to C code>
> > > + *
> > > + * fault_fixup:
> > > + * <extable loads RDI, DSI and RDX with fault info>
> > > + * jmp out
> > > + */
> >
> > This has the IMO excellent property that it's extremely awkward to use
> > it for a model where the enclave is reentrant. I think it's excellent
> > because reentrancy on the same enclave thread is just asking for
> > severe bugs. Of course, I fully expect the SDK to emulate reentrancy,
> > but then it's 100% their problem :) On the fiip side, it means that
> > you can't really recover from a reported fault, even if you want to,
> > because there's no way to ask for ERESUME. So maybe the API should
> > allow that after all.
>
> Doh. The ability to do ERESUME is an explicit requirement from the SDK
> folks. More code that I pulled from my userspace implementation and
> didn't revisit.
Is it ok to add a separate exported function for ERESUME? ERESUME can't
explicitly pass anything to the enclave, i.e. doesn't need a @priv param.
A separate function is a little prettier, e.g.:
static inline
long vdso_enter_enclave(enum sgx_enclu_leaf op, void *tcs, void *priv,
struct sgx_eenter_fault_info *fault_info)
{
...
}
notrace long __vdso_sgx_eenter(void *tcs, void *priv,
struct sgx_eenter_fault_info *fault_info)
{
return vdso_enter_enclave(SGX_EENTER, tcs, priv, fault_info);
}
notrace long __vdso_sgx_eresume(void *tcs,
struct sgx_eenter_fault_info *fault_info)
{
return vdso_enter_enclave(SGX_ERESUME, tcs, NULL, fault_info);
}