Re: [RFC PATCH v3 0/4] x86: Add exception fixup for SGX ENCLU

From: Sean Christopherson
Date: Tue Dec 11 2018 - 17:23:17 EST

On Tue, Dec 11, 2018 at 09:58:19AM -0800, Andy Lutomirski wrote:
> > On Dec 11, 2018, at 8:52 AM, Sean Christopherson <sean.j.christopherson@xxxxxxxxx> wrote:
> >
> >> On Tue, Dec 11, 2018 at 07:41:27AM -0800, Andy Lutomirski wrote:
> >>
> >>
> >>>> On Dec 10, 2018, at 3:24 PM, Josh Triplett <josh@xxxxxxxxxxxxxxxx> wrote:
> >>>>
> >>>> On Mon, Dec 10, 2018 at 03:21:37PM -0800, Sean Christopherson wrote:
> >>>> At that point I realized it's a hell of a lot easier to simply provide
> >>>> an IOCTL via /dev/sgx that allows userspace to register a per-process
> >>>> ENCLU exception handler. At a high level, the basic idea is the same
> >>>> as the vDSO approach: provide a hardcoded fixup handler for ENCLU and
> >>>> attempt to fixup select unhandled exceptions that occurred in user code.
> >>>
> >>> So, on the one hand, this is *absolutely* much cleaner than the VDSO
> >>> approach. On the other hand, this is global process state and has some
> >>> of the same problems as a signal handler as a result.
> >>
> >> I liked the old version better for this reason
> >
> > This isn't fundamentally different than forcing all EENTER calls through
> > the vDSO, which is also per-process. Technically this is more flexible
> > in that regard since userspace gets to choose where their one ENCLU gets
> > to reside. Userspace can have per-enclave entry flows so long as the
> > actual ENLU[EENTER] is common, same as vDSO.
> Right. The problem is that user libraries have a remarkably hard time
> agreeing on where their one copy of anything lives.

Are you concerned about userspace shooting themselves in the foot, e.g.
unknowingly overwriting their handler? Requiring unregister->register
to change the handler would mitigate that issue for the most part. Or
we could even say it's a write-once property.

That obviously doesn't solve the issue of a userspace application
deliberately using two different libraries to run enclaves in a single
process, but I have a hard time envisioning a scenario where someone
would want to use two different *SGX* libraries in a single process.
Don't most of the signal issue arise due to loading multiple libraries
that provide *different* services needing to handle signals?