Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-10-27 Thread Borislav Petkov
On Tue, Oct 27, 2020 at 08:20:00AM -0700, Dave Hansen wrote: > I can't think of a *lot* of spots where we have sanity checks like this > for memory. We have cgroups and the overcommit limits. But, in > general, folks can allocate as much memory as they want until > allocations start to fail. > >

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-10-27 Thread Dave Hansen
On 10/27/20 3:05 AM, Borislav Petkov wrote: > On Mon, Oct 26, 2020 at 02:26:13PM -0700, Dave Hansen wrote: >> What were you concerned about here? Was it how long the syscall could >> take, or that one user could exhaust all the enclave memory in one call? > More the latter. And generally, to have

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-10-27 Thread Borislav Petkov
On Mon, Oct 26, 2020 at 02:26:13PM -0700, Dave Hansen wrote: > What were you concerned about here? Was it how long the syscall could > take, or that one user could exhaust all the enclave memory in one call? More the latter. And generally, to have a sanity-check on all requests coming from lusers

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-10-26 Thread Jarkko Sakkinen
On Mon, Oct 26, 2020 at 02:26:13PM -0700, Dave Hansen wrote: > On 6/26/20 8:34 AM, Borislav Petkov wrote: > >> + if (!(atomic_read(&encl->flags) & SGX_ENCL_CREATED)) > >> + return -EINVAL; > >> + > >> + if (copy_from_user(&addp, arg, sizeof(addp))) > >> + return -EFAULT; > >> +

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-10-26 Thread Dave Hansen
On 6/26/20 8:34 AM, Borislav Petkov wrote: >> +if (!(atomic_read(&encl->flags) & SGX_ENCL_CREATED)) >> +return -EINVAL; >> + >> +if (copy_from_user(&addp, arg, sizeof(addp))) >> +return -EFAULT; >> + >> +if (!IS_ALIGNED(addp.offset, PAGE_SIZE) || >> +!IS_

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-09-04 Thread Jarkko Sakkinen
On Tue, Sep 01, 2020 at 10:06:32PM -0500, Haitao Huang wrote: > On Fri, 03 Jul 2020 22:31:10 -0500, Jarkko Sakkinen > wrote: > > > On Wed, Jul 01, 2020 at 08:59:02PM -0700, Sean Christopherson wrote: > > > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > > > +static int sgx_va

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-09-02 Thread Haitao Huang
On Wed, 02 Sep 2020 11:10:12 -0500, Sean Christopherson wrote: On Tue, Sep 01, 2020 at 10:06:32PM -0500, Haitao Huang wrote: On Fri, 03 Jul 2020 22:31:10 -0500, Jarkko Sakkinen wrote: > On Wed, Jul 01, 2020 at 08:59:02PM -0700, Sean Christopherson wrote: > > On Thu, Jun 18, 2020 at 01:08:3

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-09-02 Thread Sean Christopherson
On Tue, Sep 01, 2020 at 10:06:32PM -0500, Haitao Huang wrote: > On Fri, 03 Jul 2020 22:31:10 -0500, Jarkko Sakkinen > wrote: > > > On Wed, Jul 01, 2020 at 08:59:02PM -0700, Sean Christopherson wrote: > > > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > > > +static int sgx_va

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-09-01 Thread Haitao Huang
On Fri, 03 Jul 2020 22:31:10 -0500, Jarkko Sakkinen wrote: On Wed, Jul 01, 2020 at 08:59:02PM -0700, Sean Christopherson wrote: On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > +static int sgx_validate_secs(const struct sgx_secs *secs, > + unsigned lon

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-06 Thread Jarkko Sakkinen
On Mon, Jul 06, 2020 at 06:38:47PM -0700, Sean Christopherson wrote: > On Sat, Jul 04, 2020 at 04:43:49AM +0300, Jarkko Sakkinen wrote: > > On Mon, Jun 29, 2020 at 08:27:19AM -0700, Sean Christopherson wrote: > > > On Sat, Jun 27, 2020 at 07:43:35PM +0200, Borislav Petkov wrote: > > > > And you cou

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-06 Thread Sean Christopherson
On Sat, Jul 04, 2020 at 04:43:49AM +0300, Jarkko Sakkinen wrote: > On Mon, Jun 29, 2020 at 08:27:19AM -0700, Sean Christopherson wrote: > > On Sat, Jun 27, 2020 at 07:43:35PM +0200, Borislav Petkov wrote: > > > And you could do similar sanity checks in the other ioctl functions. > > > > Ya, as abo

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-03 Thread Jarkko Sakkinen
On Wed, Jul 01, 2020 at 08:59:02PM -0700, Sean Christopherson wrote: > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > +static int sgx_validate_secs(const struct sgx_secs *secs, > > +unsigned long ssaframesize) > > +{ > > + if (secs->size < (2 * PAGE_S

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-03 Thread Jarkko Sakkinen
On Mon, Jun 29, 2020 at 08:27:19AM -0700, Sean Christopherson wrote: > On Sat, Jun 27, 2020 at 07:43:35PM +0200, Borislav Petkov wrote: > > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > > +static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct > > > *sigstruct,

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-03 Thread Jarkko Sakkinen
On Sat, Jun 27, 2020 at 07:43:35PM +0200, Borislav Petkov wrote: > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > +static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct > > *sigstruct, > > +void *token) > > +{ > > + u64 mrsigner[4]; > > +

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-03 Thread Jarkko Sakkinen
On Fri, Jun 26, 2020 at 05:34:00PM +0200, Borislav Petkov wrote: > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > ... > > This could use some commenting along the lines of: > > "— If the enclave developer requires measurement of the page as a > proof for the content, use EE

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-03 Thread Jarkko Sakkinen
On Fri, Jun 26, 2020 at 04:20:19PM +0200, Borislav Petkov wrote: > On Fri, Jun 26, 2020 at 07:16:27AM -0700, Sean Christopherson wrote: > > That being said, I agree that it would be safer to move > > sgx_calc_ssaframesize() > > inside sgx_validate_secs() and only compute encl_size after the secs i

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-02 Thread Jarkko Sakkinen
On Fri, Jun 26, 2020 at 11:14:19AM +0200, Borislav Petkov wrote: > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst > > b/Documentation/userspace-api/ioctl/ioctl-number.rst > > index 59472cd6a11d..35f713e3a267 1006

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-07-01 Thread Sean Christopherson
On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > +static int sgx_validate_secs(const struct sgx_secs *secs, > + unsigned long ssaframesize) > +{ > + if (secs->size < (2 * PAGE_SIZE) || !is_power_of_2(secs->size)) > + return -EINVAL; > + > +

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-29 Thread Borislav Petkov
On Mon, Jun 29, 2020 at 08:27:19AM -0700, Sean Christopherson wrote: > Hmm, I was going to say that SGX_ENCL_INITIALIZED can't be checked until > encl->lock is held, but that's not true for this path as mutual exclusion > is provided by the SGX_ENCL_IOCTL flag. So yeah, this can be checked at > th

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-29 Thread Sean Christopherson
On Sat, Jun 27, 2020 at 07:43:35PM +0200, Borislav Petkov wrote: > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > +static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct > > *sigstruct, > > +void *token) > > +{ > > + u64 mrsigner[4]; > > +

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-27 Thread Borislav Petkov
On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > +static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct > *sigstruct, > + void *token) > +{ > + u64 mrsigner[4]; > + int ret; > + int i; > + int j; > + > + /* Check that the re

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-26 Thread Borislav Petkov
On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: ... This could use some commenting along the lines of: "— If the enclave developer requires measurement of the page as a proof for the content, use EEXTEND to add a measurement for 256 bytes of the page. Repeat this operation until

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-26 Thread Borislav Petkov
On Fri, Jun 26, 2020 at 07:16:27AM -0700, Sean Christopherson wrote: > That being said, I agree that it would be safer to move > sgx_calc_ssaframesize() > inside sgx_validate_secs() and only compute encl_size after the secs is > validated. Yap, that would be the right thing to do. -- Regards/Gr

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-26 Thread Jarkko Sakkinen
On Thu, Jun 25, 2020 at 11:34:48AM -0700, Sean Christopherson wrote: > On Thu, Jun 25, 2020 at 07:23:19PM +0200, Borislav Petkov wrote: > > Also, you had all patches until now split nice and logically doing one > > thing only. > > > > But this one is huge. Why? > > > > Why can't you split out the

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-26 Thread Jarkko Sakkinen
On Thu, Jun 25, 2020 at 08:53:34PM +0200, Borislav Petkov wrote: > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > > Subject: Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver >^ >

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-26 Thread Sean Christopherson
On Fri, Jun 26, 2020 at 11:14:19AM +0200, Borislav Petkov wrote: > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > +static int sgx_encl_create(struct sgx_encl *encl, struct sgx_secs *secs) > > +{ > > + unsigned long encl_size = secs->size + PAGE_SIZE; > > Wait, you just copi

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-26 Thread Jarkko Sakkinen
On Thu, Jun 25, 2020 at 10:25:39PM +0200, Borislav Petkov wrote: > On Thu, Jun 25, 2020 at 11:21:48PM +0300, Jarkko Sakkinen wrote: > > Would be probably easier to review also this way because the commit kind > > of rationalizes why things exist. > > > > What do you think? > > Sounds like a plan

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-26 Thread Borislav Petkov
On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst > b/Documentation/userspace-api/ioctl/ioctl-number.rst > index 59472cd6a11d..35f713e3a267 100644 > --- a/Documentation/userspace-api/ioctl/ioctl-number.rst > +++ b/Doc

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-25 Thread Borislav Petkov
On Thu, Jun 25, 2020 at 11:21:48PM +0300, Jarkko Sakkinen wrote: > Would be probably easier to review also this way because the commit kind > of rationalizes why things exist. > > What do you think? Sounds like a plan but you can do this for the next version - no need to do it now. I'll try to re

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-25 Thread Jarkko Sakkinen
On Thu, Jun 25, 2020 at 07:23:19PM +0200, Borislav Petkov wrote: > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > > Intel Software Guard eXtensions (SGX) is a set of CPU instructions that > > can be used by applications to set aside private regions of code and > > data. The code

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-25 Thread Borislav Petkov
On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > Subject: Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver ^ Add > Intel Software Guard eXtensions (SGX) is a set of CPU instructions that

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-25 Thread Borislav Petkov
On Thu, Jun 25, 2020 at 11:34:48AM -0700, Sean Christopherson wrote: > Hmm, I think the most reasonable way to break up this beast would be to > incrementally introduce functionality. E.g. four or so patches, one for > each ioctl() of ENCLAVE_CREATE, ENCLAVE_ADD_PAGES, ENCLAVE_INIT and > ENCLAVE_S

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-25 Thread Sean Christopherson
On Thu, Jun 25, 2020 at 07:23:19PM +0200, Borislav Petkov wrote: > Also, you had all patches until now split nice and logically doing one > thing only. > > But this one is huge. Why? > > Why can't you split out the facilities which the driver uses: encl.[ch] > into a patch, then ioctl.c into a se

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-25 Thread Borislav Petkov
On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > Intel Software Guard eXtensions (SGX) is a set of CPU instructions that > can be used by applications to set aside private regions of code and > data. The code outside the SGX hosted software entity is disallowed to > access the mem

[PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-06-17 Thread Jarkko Sakkinen
Intel Software Guard eXtensions (SGX) is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the SGX hosted software entity is disallowed to access the memory inside the enclave enforced by the CPU. We call these entities as enc