Re: RFC: userspace exception fixups

2018-11-26 Thread Jarkko Sakkinen
On Mon, Nov 26, 2018 at 06:35:34AM -0800, Sean Christopherson wrote: > And how would you determine the #UD is related to SGX? Hardware doesn't > provide any indication that a #UD (or any other fault) is related to SGX > or occurred in an enclave. The only fault that is special-cased in a > non-vi

Re: RFC: userspace exception fixups

2018-11-26 Thread Sean Christopherson
On Wed, Nov 21, 2018 at 05:17:34PM +0200, Jarkko Sakkinen wrote: > On Wed, Nov 21, 2018 at 05:17:32AM +, Jethro Beekman wrote: > > Jarkko, can you please explain you solution in detail? The CPU receives an > > exception. This will be handled by the kernel exception handler. What > > information

Re: RFC: userspace exception fixups

2018-11-24 Thread Jarkko Sakkinen
On Wed, Nov 21, 2018 at 05:17:34PM +0200, Jarkko Sakkinen wrote: > On Wed, Nov 21, 2018 at 05:17:32AM +, Jethro Beekman wrote: > > Jarkko, can you please explain you solution in detail? The CPU receives an > > exception. This will be handled by the kernel exception handler. What > > information

Re: RFC: userspace exception fixups

2018-11-21 Thread Jarkko Sakkinen
On Wed, Nov 21, 2018 at 05:17:32AM +, Jethro Beekman wrote: > Jarkko, can you please explain you solution in detail? The CPU receives an > exception. This will be handled by the kernel exception handler. What > information does the kernel exception handler use to determine whether to > deliver

Re: RFC: userspace exception fixups

2018-11-20 Thread Jethro Beekman
On 2018-11-21 04:25, Jarkko Sakkinen wrote: On Tue, Nov 20, 2018 at 07:19:37AM -0800, Andy Lutomirski wrote: general by mucking with some regs and retrying -- that will infinite loop and confuse everyone. I'm not even 100% convinced that decoding the insn stream is useful -- AEP can point to so

Re: RFC: userspace exception fixups

2018-11-20 Thread Jarkko Sakkinen
On Tue, Nov 20, 2018 at 07:19:37AM -0800, Andy Lutomirski wrote: > What is "#GP with EPCM"? We certainly don't want to react to #UD in A typo. Meant #PF with PF_SGX set i.e. EPCM conflict. > general by mucking with some regs and retrying -- that will infinite > loop and confuse everyone. I'm no

Re: RFC: userspace exception fixups

2018-11-20 Thread Jarkko Sakkinen
On Tue, Nov 20, 2018 at 12:11:33PM +0200, Jarkko Sakkinen wrote: > On Mon, Nov 19, 2018 at 09:00:08AM -0800, Andy Lutomirski wrote: > > On Mon, Nov 19, 2018 at 8:02 AM Jarkko Sakkinen > > wrote: > > > > > > On Mon, Nov 19, 2018 at 07:29:36AM -0800, Andy Lutomirski wrote: > > > > 1. The kernel need

Re: RFC: userspace exception fixups

2018-11-20 Thread Sean Christopherson
On Tue, Nov 20, 2018 at 12:11:33PM +0200, Jarkko Sakkinen wrote: > On Mon, Nov 19, 2018 at 09:00:08AM -0800, Andy Lutomirski wrote: > > On Mon, Nov 19, 2018 at 8:02 AM Jarkko Sakkinen > > wrote: > > > > > > On Mon, Nov 19, 2018 at 07:29:36AM -0800, Andy Lutomirski wrote: > > > > 1. The kernel need

Re: RFC: userspace exception fixups

2018-11-20 Thread Andy Lutomirski
On Tue, Nov 20, 2018 at 2:11 AM Jarkko Sakkinen wrote: > > On Mon, Nov 19, 2018 at 09:00:08AM -0800, Andy Lutomirski wrote: > > On Mon, Nov 19, 2018 at 8:02 AM Jarkko Sakkinen > > wrote: > > > > > > On Mon, Nov 19, 2018 at 07:29:36AM -0800, Andy Lutomirski wrote: > > > > 1. The kernel needs some

Re: RFC: userspace exception fixups

2018-11-20 Thread Jarkko Sakkinen
On Mon, Nov 19, 2018 at 09:00:08AM -0800, Andy Lutomirski wrote: > On Mon, Nov 19, 2018 at 8:02 AM Jarkko Sakkinen > wrote: > > > > On Mon, Nov 19, 2018 at 07:29:36AM -0800, Andy Lutomirski wrote: > > > 1. The kernel needs some way to know *when* to apply this fixup. > > > Decoding the instruction

Re: RFC: userspace exception fixups

2018-11-19 Thread Andy Lutomirski
On Mon, Nov 19, 2018 at 8:02 AM Jarkko Sakkinen wrote: > > On Mon, Nov 19, 2018 at 07:29:36AM -0800, Andy Lutomirski wrote: > > 1. The kernel needs some way to know *when* to apply this fixup. > > Decoding the instruction stream and doing it to all exceptions that > > hit an ENCLU instruction seem

Re: RFC: userspace exception fixups

2018-11-19 Thread Jarkko Sakkinen
On Mon, Nov 19, 2018 at 07:29:36AM -0800, Andy Lutomirski wrote: > 1. The kernel needs some way to know *when* to apply this fixup. > Decoding the instruction stream and doing it to all exceptions that > hit an ENCLU instruction seems like a poor design. I'm not sure why you would ever need to do

Re: RFC: userspace exception fixups

2018-11-19 Thread Andy Lutomirski
On Sat, Nov 17, 2018 at 11:16 PM Jarkko Sakkinen wrote: > > On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: > > Hi all- > > > > The people working on SGX enablement are grappling with a somewhat > > annoying issue: the x86 EENTER instruction is used from user code and > > can, as

Re: RFC: userspace exception fixups

2018-11-19 Thread Jarkko Sakkinen
On Mon, Nov 19, 2018 at 04:05:43PM +0200, Jarkko Sakkinen wrote: > On Mon, Nov 19, 2018 at 05:17:26AM +, Jethro Beekman wrote: > > On 2018-11-18 18:32, Jarkko Sakkinen wrote: > > > On Sun, Nov 18, 2018 at 09:15:48AM +0200, Jarkko Sakkinen wrote: > > > > On Thu, Nov 01, 2018 at 10:53:40AM -0700,

Re: RFC: userspace exception fixups

2018-11-19 Thread Jarkko Sakkinen
On Mon, Nov 19, 2018 at 05:17:26AM +, Jethro Beekman wrote: > On 2018-11-18 18:32, Jarkko Sakkinen wrote: > > On Sun, Nov 18, 2018 at 09:15:48AM +0200, Jarkko Sakkinen wrote: > > > On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: > > > > Hi all- > > > > > > > > The people worki

Re: RFC: userspace exception fixups

2018-11-18 Thread Jethro Beekman
On 2018-11-18 18:32, Jarkko Sakkinen wrote: On Sun, Nov 18, 2018 at 09:15:48AM +0200, Jarkko Sakkinen wrote: On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: Hi all- The people working on SGX enablement are grappling with a somewhat annoying issue: the x86 EENTER instruction is

Re: RFC: userspace exception fixups

2018-11-18 Thread Jarkko Sakkinen
On Sun, Nov 18, 2018 at 09:15:48AM +0200, Jarkko Sakkinen wrote: > On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: > > Hi all- > > > > The people working on SGX enablement are grappling with a somewhat > > annoying issue: the x86 EENTER instruction is used from user code and > > c

Re: RFC: userspace exception fixups

2018-11-17 Thread Jarkko Sakkinen
On Sun, Nov 18, 2018 at 09:15:48AM +0200, Jarkko Sakkinen wrote: > On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: > > Hi all- > > > > The people working on SGX enablement are grappling with a somewhat > > annoying issue: the x86 EENTER instruction is used from user code and > > c

Re: RFC: userspace exception fixups

2018-11-17 Thread Jarkko Sakkinen
On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: > Hi all- > > The people working on SGX enablement are grappling with a somewhat > annoying issue: the x86 EENTER instruction is used from user code and > can, as part of its normal-ish operation, raise an exception. It is > also hi

Re: RFC: userspace exception fixups

2018-11-08 Thread Christoph Hellwig
On Thu, Nov 08, 2018 at 12:05:42PM -0800, Andy Lutomirski wrote: > This whole thing is a mess. I'm starting to think that the cleanest > solution would be to provide a way to just tell the kernel that > certain RIP values have exception fixups. The bay far cleanest solution would be to say that S

Re: RFC: userspace exception fixups

2018-11-08 Thread Sean Christopherson
On Thu, Nov 08, 2018 at 01:50:31PM -0800, Dave Hansen wrote: > On 11/8/18 1:16 PM, Sean Christopherson wrote: > > On Thu, Nov 08, 2018 at 12:10:30PM -0800, Dave Hansen wrote: > >> On 11/8/18 12:05 PM, Andy Lutomirski wrote: > >>> Hmm. The idea being that the SDK preserves RBP but not RSP. That's

Re: RFC: userspace exception fixups

2018-11-08 Thread Dave Hansen
On 11/8/18 1:16 PM, Sean Christopherson wrote: > On Thu, Nov 08, 2018 at 12:10:30PM -0800, Dave Hansen wrote: >> On 11/8/18 12:05 PM, Andy Lutomirski wrote: >>> Hmm. The idea being that the SDK preserves RBP but not RSP. That's >>> not the most terrible thing in the world. But could the SDK live

Re: RFC: userspace exception fixups

2018-11-08 Thread Sean Christopherson
On Thu, Nov 08, 2018 at 12:10:30PM -0800, Dave Hansen wrote: > On 11/8/18 12:05 PM, Andy Lutomirski wrote: > > Hmm. The idea being that the SDK preserves RBP but not RSP. That's > > not the most terrible thing in the world. But could the SDK live with > > something more like my suggestion where

Re: RFC: userspace exception fixups

2018-11-08 Thread Dave Hansen
On 11/8/18 12:05 PM, Andy Lutomirski wrote: > Hmm. The idea being that the SDK preserves RBP but not RSP. That's > not the most terrible thing in the world. But could the SDK live with > something more like my suggestion where the vDSO supplies a normal > function that takes a struct containing

Re: RFC: userspace exception fixups

2018-11-08 Thread Andy Lutomirski
On Thu, Nov 8, 2018 at 11:54 AM Sean Christopherson wrote: > > On Tue, Nov 06, 2018 at 01:07:54PM -0800, Andy Lutomirski wrote: > > > > > > > On Nov 6, 2018, at 1:00 PM, Dave Hansen wrote: > > > > > >> On 11/6/18 12:12 PM, Andy Lutomirski wrote: > > >> True, but what if we have a nasty enclave th

Re: RFC: userspace exception fixups

2018-11-08 Thread Sean Christopherson
On Tue, Nov 06, 2018 at 01:07:54PM -0800, Andy Lutomirski wrote: > > > > On Nov 6, 2018, at 1:00 PM, Dave Hansen wrote: > > > >> On 11/6/18 12:12 PM, Andy Lutomirski wrote: > >> True, but what if we have a nasty enclave that writes to memory just > >> below SP *before* decrementing SP? > > > >

Re: RFC: userspace exception fixups

2018-11-08 Thread Jarkko Sakkinen
On Wed, Nov 07, 2018 at 01:40:59PM -0800, Sean Christopherson wrote: > > In that case it seems like the only way to use SGX that's not a gaping > > security hole is to run the SGX enclave in its own fully-seccomp (or > > equivalent) process, with no host application in the same address > > space. S

Re: RFC: userspace exception fixups

2018-11-08 Thread Jarkko Sakkinen
On Wed, Nov 07, 2018 at 12:56:58PM -0800, Dave Hansen wrote: > On 11/7/18 11:01 AM, Sean Christopherson wrote: > > Going off comments in similar code related to UMIP, we'd need to figure > > out how to handle protection keys. > > There are two options: > 1. Don't depend on the userspace mapping.

Re: RFC: userspace exception fixups

2018-11-07 Thread Sean Christopherson
On Wed, Nov 07, 2018 at 04:27:58PM -0500, Rich Felker wrote: > On Tue, Nov 06, 2018 at 03:26:16PM -0800, Sean Christopherson wrote: > > On Tue, Nov 06, 2018 at 06:17:30PM -0500, Rich Felker wrote: > > > On Tue, Nov 06, 2018 at 11:02:11AM -0800, Andy Lutomirski wrote: > > > > On Tue, Nov 6, 2018 at

Re: RFC: userspace exception fixups

2018-11-07 Thread Andy Lutomirski
On Wed, Nov 7, 2018 at 1:28 PM Rich Felker wrote: > > On Tue, Nov 06, 2018 at 03:26:16PM -0800, Sean Christopherson wrote: > > On Tue, Nov 06, 2018 at 06:17:30PM -0500, Rich Felker wrote: > > > On Tue, Nov 06, 2018 at 11:02:11AM -0800, Andy Lutomirski wrote: > > > > On Tue, Nov 6, 2018 at 10:41 AM

Re: RFC: userspace exception fixups

2018-11-07 Thread Rich Felker
On Tue, Nov 06, 2018 at 03:26:16PM -0800, Sean Christopherson wrote: > On Tue, Nov 06, 2018 at 06:17:30PM -0500, Rich Felker wrote: > > On Tue, Nov 06, 2018 at 11:02:11AM -0800, Andy Lutomirski wrote: > > > On Tue, Nov 6, 2018 at 10:41 AM Dave Hansen wrote: > > > > > > > > On 11/6/18 10:20 AM, And

Re: RFC: userspace exception fixups

2018-11-07 Thread Dave Hansen
On 11/7/18 11:01 AM, Sean Christopherson wrote: > Going off comments in similar code related to UMIP, we'd need to figure > out how to handle protection keys. There are two options: 1. Don't depend on the userspace mapping. Do get_user_pages() to find the instruction in the kernel direct map,

Re: RFC: userspace exception fixups

2018-11-07 Thread Sean Christopherson
On Wed, Nov 07, 2018 at 07:34:52AM -0800, Sean Christopherson wrote: > On Tue, Nov 06, 2018 at 05:17:14PM -0800, Andy Lutomirski wrote: > > On Tue, Nov 6, 2018 at 4:02 PM Sean Christopherson > > wrote: > > > > > > On Tue, Nov 06, 2018 at 03:39:48PM -0800, Andy Lutomirski wrote: > > > > On Tue, Nov

Re: RFC: userspace exception fixups

2018-11-07 Thread Sean Christopherson
On Tue, Nov 06, 2018 at 05:17:14PM -0800, Andy Lutomirski wrote: > On Tue, Nov 6, 2018 at 4:02 PM Sean Christopherson > wrote: > > > > On Tue, Nov 06, 2018 at 03:39:48PM -0800, Andy Lutomirski wrote: > > > On Tue, Nov 6, 2018 at 3:35 PM Sean Christopherson > > > wrote: > > > > > > > > On Tue, Nov

Re: RFC: userspace exception fixups

2018-11-06 Thread Jethro Beekman
On 2018-11-07 02:17, Andy Lutomirski wrote: On Tue, Nov 6, 2018 at 4:02 PM Sean Christopherson wrote: /* * EEXIT or EENTER faulted. In the latter case, %RAX already holds some * fault indicator, e.g. -EFAULT. */ eexit_or_eenter_fault: ret But userspace wants to know whether it wa

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
On Tue, Nov 6, 2018 at 4:02 PM Sean Christopherson wrote: > > On Tue, Nov 06, 2018 at 03:39:48PM -0800, Andy Lutomirski wrote: > > On Tue, Nov 6, 2018 at 3:35 PM Sean Christopherson > > wrote: > > > > > > On Tue, Nov 06, 2018 at 03:00:56PM -0800, Andy Lutomirski wrote: > > > > > > > > > > > > >>

Re: RFC: userspace exception fixups

2018-11-06 Thread Sean Christopherson
On Tue, Nov 06, 2018 at 03:39:48PM -0800, Andy Lutomirski wrote: > On Tue, Nov 6, 2018 at 3:35 PM Sean Christopherson > wrote: > > > > On Tue, Nov 06, 2018 at 03:00:56PM -0800, Andy Lutomirski wrote: > > > > > > > > > >> On Nov 6, 2018, at 1:59 PM, Sean Christopherson > > > >> wrote: > > > >> >

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
On Tue, Nov 6, 2018 at 3:35 PM Sean Christopherson wrote: > > On Tue, Nov 06, 2018 at 03:00:56PM -0800, Andy Lutomirski wrote: > > > > > > >> On Nov 6, 2018, at 1:59 PM, Sean Christopherson > > >> wrote: > > >> > > >>> On Tue, 2018-11-06 at 13:41 -0800, Andy Lutomirski wrote: > > >> Sean, how do

Re: RFC: userspace exception fixups

2018-11-06 Thread Sean Christopherson
On Tue, Nov 06, 2018 at 03:00:56PM -0800, Andy Lutomirski wrote: > > > >> On Nov 6, 2018, at 1:59 PM, Sean Christopherson > >> wrote: > >> > >>> On Tue, 2018-11-06 at 13:41 -0800, Andy Lutomirski wrote: > >> Sean, how does the current SDK AEX handler decide whether to do > >> EENTER, ERESUME,

Re: RFC: userspace exception fixups

2018-11-06 Thread Sean Christopherson
On Tue, Nov 06, 2018 at 06:17:30PM -0500, Rich Felker wrote: > On Tue, Nov 06, 2018 at 11:02:11AM -0800, Andy Lutomirski wrote: > > On Tue, Nov 6, 2018 at 10:41 AM Dave Hansen wrote: > > > > > > On 11/6/18 10:20 AM, Andy Lutomirski wrote: > > > > I almost feel like the right solution is to call in

Re: RFC: userspace exception fixups

2018-11-06 Thread Rich Felker
On Tue, Nov 06, 2018 at 11:02:11AM -0800, Andy Lutomirski wrote: > On Tue, Nov 6, 2018 at 10:41 AM Dave Hansen wrote: > > > > On 11/6/18 10:20 AM, Andy Lutomirski wrote: > > > I almost feel like the right solution is to call into SGX on its own > > > private stack or maybe even its own private add

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
>> On Nov 6, 2018, at 1:59 PM, Sean Christopherson >> wrote: >> >>> On Tue, 2018-11-06 at 13:41 -0800, Andy Lutomirski wrote: On Tue, Nov 6, 2018 at 1:07 PM Andy Lutomirski wrote: > On Nov 6, 2018, at 1:00 PM, Dave Hansen wrote: > > > On 11/6/18 12:12 PM,

Re: RFC: userspace exception fixups

2018-11-06 Thread Sean Christopherson
On Tue, 2018-11-06 at 13:41 -0800, Andy Lutomirski wrote: > On Tue, Nov 6, 2018 at 1:07 PM Andy Lutomirski wrote: > > > > > > > > On Nov 6, 2018, at 1:00 PM, Dave Hansen wrote: > > > > > > > > > > > On 11/6/18 12:12 PM, Andy Lutomirski wrote: > > > > True, but what if we have a nasty enclave

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
On Tue, Nov 6, 2018 at 1:07 PM Andy Lutomirski wrote: > > > > > On Nov 6, 2018, at 1:00 PM, Dave Hansen wrote: > > > >> On 11/6/18 12:12 PM, Andy Lutomirski wrote: > >> True, but what if we have a nasty enclave that writes to memory just > >> below SP *before* decrementing SP? > > > > Yeah, that

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
> On Nov 6, 2018, at 1:00 PM, Dave Hansen wrote: > >> On 11/6/18 12:12 PM, Andy Lutomirski wrote: >> True, but what if we have a nasty enclave that writes to memory just >> below SP *before* decrementing SP? > > Yeah, that would be unfortunate. If an enclave did this (roughly): > >1. EE

Re: RFC: userspace exception fixups

2018-11-06 Thread Dave Hansen
On 11/6/18 12:12 PM, Andy Lutomirski wrote: > True, but what if we have a nasty enclave that writes to memory just > below SP *before* decrementing SP? Yeah, that would be unfortunate. If an enclave did this (roughly): 1. EENTER 2. Hardware sets eenter_hwframe->sp = %sp 3

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
> On Nov 6, 2018, at 11:22 AM, Dave Hansen wrote: > >> On 11/6/18 11:02 AM, Andy Lutomirski wrote: >>> On Tue, Nov 6, 2018 at 10:41 AM Dave Hansen wrote: >>> On 11/6/18 10:20 AM, Andy Lutomirski wrote: I almost feel like the right solution is to call into SGX on its own privat

Re: RFC: userspace exception fixups

2018-11-06 Thread Dave Hansen
On 11/6/18 11:02 AM, Andy Lutomirski wrote: > On Tue, Nov 6, 2018 at 10:41 AM Dave Hansen wrote: >> >> On 11/6/18 10:20 AM, Andy Lutomirski wrote: >>> I almost feel like the right solution is to call into SGX on its own >>> private stack or maybe even its own private address space. >> >> Yeah, I h

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
On Tue, Nov 6, 2018 at 10:41 AM Dave Hansen wrote: > > On 11/6/18 10:20 AM, Andy Lutomirski wrote: > > I almost feel like the right solution is to call into SGX on its own > > private stack or maybe even its own private address space. > > Yeah, I had the same gut feeling. Couldn't the debugger ev

Re: RFC: userspace exception fixups

2018-11-06 Thread Dave Hansen
On 11/6/18 10:20 AM, Andy Lutomirski wrote: > I almost feel like the right solution is to call into SGX on its own > private stack or maybe even its own private address space. Yeah, I had the same gut feeling. Couldn't the debugger even treat the enclave like its own "thread" with its own stack a

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
> On Nov 6, 2018, at 9:19 AM, Sean Christopherson > wrote: > >> On Tue, 2018-11-06 at 08:57 -0800, Andy Lutomirski wrote: >> >> So I guess the non-enclave code basically can’t trust its stack pointer >> because of these shenanigans. And the AEP code has to live with the fact >> that its RSP

Re: RFC: userspace exception fixups

2018-11-06 Thread Sean Christopherson
On Tue, 2018-11-06 at 08:57 -0800, Andy Lutomirski wrote: > > So I guess the non-enclave code basically can’t trust its stack pointer > because of these shenanigans. And the AEP code has to live with the fact > that its RSP is basically arbitrary and probably can’t even be unwound > by a debugger?

Re: RFC: userspace exception fixups

2018-11-06 Thread Dave Hansen
On 11/6/18 8:57 AM, Andy Lutomirski wrote: > I’m assuming it’s way too late for the SGX SDK to be changed to use a > normal RPC mechanism? I’m a bit disappointed that enclaves can even > manipulate outside state like this. I assume Intel had some reason > for making it possible, but still. Just be

Re: RFC: userspace exception fixups

2018-11-06 Thread Dave Hansen
On 11/6/18 7:37 AM, Sean Christopherson wrote: > > void *sgx_alloc_untrusted_stack(size_t size) > { > struct sgx_encl_tls *tls = get_encl_tls(); > struct sgx_out_call_context *context; > void *tmp; > > /* create a frame on the trusted stack to hold the out-call context */

Re: RFC: userspace exception fixups

2018-11-06 Thread Andy Lutomirski
> On Nov 6, 2018, at 7:37 AM, Sean Christopherson > wrote: > >> On Fri, 2018-11-02 at 16:32 -0700, Andy Lutomirski wrote: >>> On Fri, Nov 2, 2018 at 4:28 PM Jann Horn wrote: >>> >>> >>> On Fri, Nov 2, 2018 at 11:04 PM Sean Christopherson >>> wrote: > On Fri, Nov 02, 2018 at 08:0

Re: RFC: userspace exception fixups

2018-11-06 Thread Sean Christopherson
On Fri, 2018-11-02 at 16:32 -0700, Andy Lutomirski wrote: > On Fri, Nov 2, 2018 at 4:28 PM Jann Horn wrote: > > > > > > On Fri, Nov 2, 2018 at 11:04 PM Sean Christopherson > > wrote: > > > > > > On Fri, Nov 02, 2018 at 08:02:23PM +0100, Jann Horn wrote: > > > > > > > > On Fri, Nov 2, 2018 at

Re: RFC: userspace exception fixups

2018-11-02 Thread Jann Horn
On Sat, Nov 3, 2018 at 12:32 AM Andy Lutomirski wrote: > On Fri, Nov 2, 2018 at 4:28 PM Jann Horn wrote: > > On Fri, Nov 2, 2018 at 11:04 PM Sean Christopherson > > wrote: > > > On Fri, Nov 02, 2018 at 08:02:23PM +0100, Jann Horn wrote: > > > > On Fri, Nov 2, 2018 at 7:27 PM Sean Christopherson

Re: RFC: userspace exception fixups

2018-11-02 Thread Andy Lutomirski
On Fri, Nov 2, 2018 at 4:28 PM Jann Horn wrote: > > On Fri, Nov 2, 2018 at 11:04 PM Sean Christopherson > wrote: > > On Fri, Nov 02, 2018 at 08:02:23PM +0100, Jann Horn wrote: > > > On Fri, Nov 2, 2018 at 7:27 PM Sean Christopherson > > > wrote: > > > > On Fri, Nov 02, 2018 at 10:48:38AM -0700,

Re: RFC: userspace exception fixups

2018-11-02 Thread Jann Horn
On Fri, Nov 2, 2018 at 11:04 PM Sean Christopherson wrote: > On Fri, Nov 02, 2018 at 08:02:23PM +0100, Jann Horn wrote: > > On Fri, Nov 2, 2018 at 7:27 PM Sean Christopherson > > wrote: > > > On Fri, Nov 02, 2018 at 10:48:38AM -0700, Andy Lutomirski wrote: > > > > This whole mechanism seems very

Re: RFC: userspace exception fixups

2018-11-02 Thread Jarkko Sakkinen
On Fri, Nov 02, 2018 at 09:52:04AM -0700, Sean Christopherson wrote: > On Fri, Nov 02, 2018 at 04:37:10PM +, Jethro Beekman wrote: > > On 2018-11-02 09:30, Sean Christopherson wrote: > > >... The intended convention for EENTER is to have an ENCLU at the AEX > > >target ... > > > > > >... to fu

Re: RFC: userspace exception fixups

2018-11-02 Thread Jarkko Sakkinen
On Thu, Nov 01, 2018 at 04:22:55PM -0700, Andy Lutomirski wrote: > On Thu, Nov 1, 2018 at 2:24 PM Linus Torvalds > wrote: > > > > On Thu, Nov 1, 2018 at 12:31 PM Rich Felker wrote: > > > > > > See my other emails in this thread. You would register the *address* > > > (in TLS) of a function pointe

Re: RFC: userspace exception fixups

2018-11-02 Thread Jarkko Sakkinen
On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: > If a handler is registered, then, if a synchronous exception happens > (page fault, etc), the kernel would set up an exception frame as usual > but, rather than checking for signal handlers, it would just call the > registered handl

Re: RFC: userspace exception fixups

2018-11-02 Thread Sean Christopherson
On Fri, Nov 02, 2018 at 08:02:23PM +0100, Jann Horn wrote: > On Fri, Nov 2, 2018 at 7:27 PM Sean Christopherson > wrote: > > On Fri, Nov 02, 2018 at 10:48:38AM -0700, Andy Lutomirski wrote: > > > This whole mechanism seems very complicated, and it's not clear > > > exactly what behavior user code

Re: RFC: userspace exception fixups

2018-11-02 Thread Jann Horn
On Fri, Nov 2, 2018 at 7:27 PM Sean Christopherson wrote: > On Fri, Nov 02, 2018 at 10:48:38AM -0700, Andy Lutomirski wrote: > > This whole mechanism seems very complicated, and it's not clear > > exactly what behavior user code wants. > > No argument there. That's why I like the approach of dump

Re: RFC: userspace exception fixups

2018-11-02 Thread Sean Christopherson
On Fri, Nov 02, 2018 at 10:48:38AM -0700, Andy Lutomirski wrote: > On Fri, Nov 2, 2018 at 10:33 AM Sean Christopherson > wrote: > > > > On Fri, Nov 02, 2018 at 10:13:23AM -0700, Dave Hansen wrote: > > > On 11/2/18 10:06 AM, Sean Christopherson wrote: > > > > On Fri, Nov 02, 2018 at 09:56:44AM -070

Re: RFC: userspace exception fixups

2018-11-02 Thread Andy Lutomirski
On Fri, Nov 2, 2018 at 10:33 AM Sean Christopherson wrote: > > On Fri, Nov 02, 2018 at 10:13:23AM -0700, Dave Hansen wrote: > > On 11/2/18 10:06 AM, Sean Christopherson wrote: > > > On Fri, Nov 02, 2018 at 09:56:44AM -0700, Dave Hansen wrote: > > >> On 11/2/18 9:30 AM, Sean Christopherson wrote: >

Re: RFC: userspace exception fixups

2018-11-02 Thread Rich Felker
On Fri, Nov 02, 2018 at 10:16:02AM -0700, Andy Lutomirski wrote: > On Fri, Nov 2, 2018 at 10:05 AM Jethro Beekman wrote: > > > > On 2018-11-02 10:01, Andy Lutomirski wrote: > > > On Fri, Nov 2, 2018 at 9:56 AM Jethro Beekman wrote: > > >> > > >> On 2018-11-02 09:52, Sean Christopherson wrote: > >

Re: RFC: userspace exception fixups

2018-11-02 Thread Sean Christopherson
On Fri, Nov 02, 2018 at 10:13:23AM -0700, Dave Hansen wrote: > On 11/2/18 10:06 AM, Sean Christopherson wrote: > > On Fri, Nov 02, 2018 at 09:56:44AM -0700, Dave Hansen wrote: > >> On 11/2/18 9:30 AM, Sean Christopherson wrote: > >>> What if rather than having userspace register an address for fixu

Re: RFC: userspace exception fixups

2018-11-02 Thread Andy Lutomirski
On Fri, Nov 2, 2018 at 10:05 AM Jethro Beekman wrote: > > On 2018-11-02 10:01, Andy Lutomirski wrote: > > On Fri, Nov 2, 2018 at 9:56 AM Jethro Beekman wrote: > >> > >> On 2018-11-02 09:52, Sean Christopherson wrote: > >>> On Fri, Nov 02, 2018 at 04:37:10PM +, Jethro Beekman wrote: > On

Re: RFC: userspace exception fixups

2018-11-02 Thread Dave Hansen
On 11/2/18 10:06 AM, Sean Christopherson wrote: > On Fri, Nov 02, 2018 at 09:56:44AM -0700, Dave Hansen wrote: >> On 11/2/18 9:30 AM, Sean Christopherson wrote: >>> What if rather than having userspace register an address for fixup, the >>> kernel instead unconditionally does fixup on the ENCLU opc

Re: RFC: userspace exception fixups

2018-11-02 Thread Sean Christopherson
On Fri, Nov 02, 2018 at 04:56:36PM +, Jethro Beekman wrote: > On 2018-11-02 09:52, Sean Christopherson wrote: > >On Fri, Nov 02, 2018 at 04:37:10PM +, Jethro Beekman wrote: > >>On 2018-11-02 09:30, Sean Christopherson wrote: > >>>... The intended convention for EENTER is to have an ENCLU at

Re: RFC: userspace exception fixups

2018-11-02 Thread Sean Christopherson
On Fri, Nov 02, 2018 at 09:56:44AM -0700, Dave Hansen wrote: > On 11/2/18 9:30 AM, Sean Christopherson wrote: > > What if rather than having userspace register an address for fixup, the > > kernel instead unconditionally does fixup on the ENCLU opcode? > > The problem is knowing what to do for the

Re: RFC: userspace exception fixups

2018-11-02 Thread Jethro Beekman
On 2018-11-02 10:01, Andy Lutomirski wrote: On Fri, Nov 2, 2018 at 9:56 AM Jethro Beekman wrote: On 2018-11-02 09:52, Sean Christopherson wrote: On Fri, Nov 02, 2018 at 04:37:10PM +, Jethro Beekman wrote: On 2018-11-02 09:30, Sean Christopherson wrote: ... The intended convention for EE

Re: RFC: userspace exception fixups

2018-11-02 Thread Andy Lutomirski
On Fri, Nov 2, 2018 at 9:56 AM Jethro Beekman wrote: > > On 2018-11-02 09:52, Sean Christopherson wrote: > > On Fri, Nov 02, 2018 at 04:37:10PM +, Jethro Beekman wrote: > >> On 2018-11-02 09:30, Sean Christopherson wrote: > >>> ... The intended convention for EENTER is to have an ENCLU at the

Re: RFC: userspace exception fixups

2018-11-02 Thread Jethro Beekman
On 2018-11-02 09:52, Sean Christopherson wrote: On Fri, Nov 02, 2018 at 04:37:10PM +, Jethro Beekman wrote: On 2018-11-02 09:30, Sean Christopherson wrote: ... The intended convention for EENTER is to have an ENCLU at the AEX target ... ... to further enforce that the AEX target needs to b

Re: RFC: userspace exception fixups

2018-11-02 Thread Dave Hansen
On 11/2/18 9:30 AM, Sean Christopherson wrote: > What if rather than having userspace register an address for fixup, the > kernel instead unconditionally does fixup on the ENCLU opcode? The problem is knowing what to do for the fixup. If we have a simple action to take that's universal, like back

Re: RFC: userspace exception fixups

2018-11-02 Thread Sean Christopherson
On Fri, Nov 02, 2018 at 04:37:10PM +, Jethro Beekman wrote: > On 2018-11-02 09:30, Sean Christopherson wrote: > >... The intended convention for EENTER is to have an ENCLU at the AEX target > >... > > > >... to further enforce that the AEX target needs to be ENCLU. > > Some SGX runtimes may w

Re: RFC: userspace exception fixups

2018-11-02 Thread Jethro Beekman
On 2018-11-02 09:30, Sean Christopherson wrote: ... The intended convention for EENTER is to have an ENCLU at the AEX target ... ... to further enforce that the AEX target needs to be ENCLU. Some SGX runtimes may want to use a different AEX target. -- Jethro Beekman | Fortanix smime.p7s De

Re: RFC: userspace exception fixups

2018-11-02 Thread Sean Christopherson
On Thu, Nov 01, 2018 at 04:22:55PM -0700, Andy Lutomirski wrote: > On Thu, Nov 1, 2018 at 2:24 PM Linus Torvalds > wrote: > > > > On Thu, Nov 1, 2018 at 12:31 PM Rich Felker wrote: > > > > > > See my other emails in this thread. You would register the *address* > > > (in TLS) of a function pointe

Re: RFC: userspace exception fixups

2018-11-01 Thread Andy Lutomirski
On Thu, Nov 1, 2018 at 2:24 PM Linus Torvalds wrote: > > On Thu, Nov 1, 2018 at 12:31 PM Rich Felker wrote: > > > > See my other emails in this thread. You would register the *address* > > (in TLS) of a function pointer object pointing to the handler, rather > > than the function address of the h

Re: RFC: userspace exception fixups

2018-11-01 Thread Linus Torvalds
On Thu, Nov 1, 2018 at 12:31 PM Rich Felker wrote: > > See my other emails in this thread. You would register the *address* > (in TLS) of a function pointer object pointing to the handler, rather > than the function address of the handler. Then switching handler is > just a single store in userspa

Re: RFC: userspace exception fixups

2018-11-01 Thread Rich Felker
On Thu, Nov 01, 2018 at 12:10:35PM -0700, Linus Torvalds wrote: > On Thu, Nov 1, 2018 at 11:52 AM Rich Felker wrote: > > > > There's no need to chain if the handler is specific to the context > > where the fault happens. You just replace the handler with the one > > relevant to the code you're abo

Re: RFC: userspace exception fixups

2018-11-01 Thread Linus Torvalds
On Thu, Nov 1, 2018 at 11:52 AM Rich Felker wrote: > > There's no need to chain if the handler is specific to the context > where the fault happens. You just replace the handler with the one > relevant to the code you're about to run before you run it. That's much too expensive to do as a system

Re: RFC: userspace exception fixups

2018-11-01 Thread Linus Torvalds
On Thu, Nov 1, 2018 at 10:53 AM Andy Lutomirski wrote: > > There's been some discussion of adding a vDSO entry point to wrap > EENTER and do something sensible with the exceptions, I think that's likely the right thing to do, and would be similar to sysenter. > The basic idea would be to allow l

Re: RFC: userspace exception fixups

2018-11-01 Thread Jarkko Sakkinen
On Thu, 1 Nov 2018, Florian Weimer wrote: * Andy Lutomirski: The basic idea would be to allow libc, or maybe even any library, to register a handler that gets a chance to act on an exception caused by a user instruction before a signal is delivered. As a straw-man example for how this could wo

Re: RFC: userspace exception fixups

2018-11-01 Thread Rich Felker
On Thu, Nov 01, 2018 at 07:33:33PM +0100, Jann Horn wrote: > > but I'm > > wondering if a more general mechanism would be helpful. > > > > The basic idea would be to allow libc, or maybe even any library, to > > register a handler that gets a chance to act on an exception caused by > > a user instr

Re: RFC: userspace exception fixups

2018-11-01 Thread Rich Felker
On Thu, Nov 01, 2018 at 10:53:40AM -0700, Andy Lutomirski wrote: > Hi all- > > The people working on SGX enablement are grappling with a somewhat > annoying issue: the x86 EENTER instruction is used from user code and > can, as part of its normal-ish operation, raise an exception. It is > also hi

Re: RFC: userspace exception fixups

2018-11-01 Thread Rich Felker
On Thu, Nov 01, 2018 at 07:09:17PM +0100, Florian Weimer wrote: > * Andy Lutomirski: > > > The basic idea would be to allow libc, or maybe even any library, to > > register a handler that gets a chance to act on an exception caused by > > a user instruction before a signal is delivered. As a stra

Re: RFC: userspace exception fixups

2018-11-01 Thread Jann Horn
On Thu, Nov 1, 2018 at 6:53 PM Andy Lutomirski wrote: > The people working on SGX enablement are grappling with a somewhat > annoying issue: the x86 EENTER instruction is used from user code and > can, as part of its normal-ish operation, raise an exception. It is > also highly likely to be used

Re: RFC: userspace exception fixups

2018-11-01 Thread Florian Weimer
* Andy Lutomirski: > The basic idea would be to allow libc, or maybe even any library, to > register a handler that gets a chance to act on an exception caused by > a user instruction before a signal is delivered. As a straw-man > example for how this could work, there could be a new syscall: > >