From: "Xing, Cedric" <cedric.xing@intel.com>
To: Andy Lutomirski <luto@kernel.org>,
Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Borislav Petkov <bp@alien8.de>,
Jethro Beekman <jethro@fortanix.com>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Dave Hansen <dave.hansen@intel.com>,
LKML <linux-kernel@vger.kernel.org>,
Nathaniel McCallum <npmccallum@redhat.com>,
linux-sgx@vger.kernel.org
Subject: Re: Can we credibly make vdso_sgx_enter_enclave() pleasant to use?
Date: Sat, 26 Sep 2020 16:55:54 -0700 [thread overview]
Message-ID: <5d0f1809-bbfa-1ab9-a533-fb99419884c9@intel.com> (raw)
In-Reply-To: <CALCETrUV-cx6dii2cOcav01GSdo9qx6+GYeoPH9nHMXwg-geQQ@mail.gmail.com>
On 9/26/2020 12:05 PM, Andy Lutomirski wrote:
> On Fri, Sep 25, 2020 at 3:29 PM Sean Christopherson
> <sean.j.christopherson@intel.com> wrote:
>>
>> On Fri, Sep 25, 2020 at 01:20:03PM -0700, Andy Lutomirski wrote:
>>> On Fri, Sep 25, 2020 at 12:09 PM Sean Christopherson
>>> <sean.j.christopherson@intel.com> wrote:
>>>> But where would the vDSO get memory for that little data structure? It can't
>>>> be percpu because the current task can get preempted. It can't be per instance
>>>> of the vDSO because a single mm/process can have multiple tasks entering an
>>>> enclave. Per task might work, but how would the vDSO get that info? E.g.
>>>> via a syscall, which seems like complete overkill?
>>>
>>> The stack.
>>
>> Duh.
>>
>>> The vDSO could, logically, do:
>>>
>>> struct sgx_entry_state {
>>> unsigned long real_rbp;
>>> unsigned long real_rsp;
>>> unsigned long orig_fsbase;
>>> };
>>>
>>> ...
>>>
>>> struct sgx_entry_state state;
>>> state.rbp = rbp; [ hey, this is pseudocode. the real code would be in asm.]
>>> state.rsp = rsp;
>>> state.fsbase = __rdfsbase();
>>> rbp = arg->rbp;
>>>
>>> /* set up all other regs */
>>> wrfsbase %rsp
>>> movq enclave_rsp(%rsp), %rsp
>>
>> I think this is where there's a disconnect with what is being requested by the
>> folks writing run times. IIUC, they want to use the untrusted runtime's stack
>> to pass params because it doesn't require additional memory allocations and
>> automagically grows as necessary (obviously to a certain limit). I.e. forcing
>> the caller to provide an alternative "stack" defeats the purpose of using the
>> untrusted stack.
>
> I personally find this concept rather distasteful. Sure, it might
> save a couple cycles, but it means that the enclave has hardcoded some
> kind of assumption about the outside-the-enclave stack.
>
It's more than just a couple of cycles. It's convenience. Yes, an
enclave may overflow the caller's stack with big allocations but those
are rare. In more common cases less than the red zone size (128 bytes)
are required. And we should optimize for the more common cases.
And yes again, the enclave has to assume something about the stack. But
please note that the vDSO has to save its "context" somewhere so that it
can switch back to it. The "context" currently is anchored at RBP so the
enclave has to preserve it. If not RBP, the "context" has to anchor
"something else", and we have to assume the enclave preserve that
"something else". That said, we can't get rid of assumptions. RBP is a
reasonable choice because it is simple without obvious side effects,
i.e. most compilers/ABIs preserve RBP so developers don't have to pay
extra attention to it generally.
If I were asked to opine on the API, I'd say I like the most the initial
version with callback support. The stack parameters were easier to
set/retrieve than struct members (requiring hand-crafted offset macros)
in asm, and didn't need any padding. The callback was easy to use
(non-NULL pointer) or skip (NULL pointer). Standard/unified error codes
were easier to handle than separate error/exit_reason. Additional data
for callback could be captured in a structure enclosing
sgx_enclave_exception so no need to be explicitly passed (languages that
don't support offsetof/container_of can always employ an asm wrapper).
The current API looks confusing and overly complicated to me, even
though it still works.
> Given that RBP seems reasonably likely to be stable across enclave
> executions, I suppose we could add a flag and an RSP value in the
> sgx_enclave_run structure. If set, the vDSO would swap out RSP (but
> not RBP) with the provided value on entry and record the new RSP on
> exit. I don't know if this would be useful to people.
>
I would say, if one wants to use a different untrusted stack for calling
the enclave, he/she could switch stack before calling vDSO. Given this
isn't commonly required, I vote NO here.
> I do think we need to add at least minimal CFI annotations no matter what we do.
>
Can't agree more.
next prev parent reply other threads:[~2020-09-26 23:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CALCETrUhQjQQa-BqNHPgdDfD9GDJZXJWSQ_M0tDF_ri5RfyTsw@mail.gmail.com>
2020-09-25 19:09 ` Can we credibly make vdso_sgx_enter_enclave() pleasant to use? Sean Christopherson
2020-09-25 20:20 ` Andy Lutomirski
2020-09-25 22:29 ` Sean Christopherson
2020-09-26 19:05 ` Andy Lutomirski
2020-09-26 23:55 ` Xing, Cedric [this message]
2020-09-26 9:27 ` Jethro Beekman
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=5d0f1809-bbfa-1ab9-a533-fb99419884c9@intel.com \
--to=cedric.xing@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=jethro@fortanix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=luto@kernel.org \
--cc=npmccallum@redhat.com \
--cc=sean.j.christopherson@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox