linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: Re: [PATCH v3 2/5] x86/sgx: Reject concurrent ioctls on single enclave
Date: Fri, 30 Aug 2019 18:40:48 +0300	[thread overview]
Message-ID: <20190830154048.ky3rvirzm5pth2pb@linux.intel.com> (raw)
In-Reply-To: <20190830001706.29309-3-sean.j.christopherson@intel.com>

On Thu, Aug 29, 2019 at 05:17:03PM -0700, Sean Christopherson wrote:
> Except for ENCLAVE_SET_ATTRIBUTE, all SGX ioctls() must be executed
> serially to successfully initialize an enclave, e.g. the kernel already
> strictly requires ECREATE->EADD->EINIT, and concurrent EADDs will result
> in an unstable MRENCLAVE.  Explicitly enforce serialization by returning
> EINVAL if userspace attempts an ioctl while a different ioctl for the
> same enclave is in progress.
> 
> The primary beneficiary of explicit serialization is sgx_encl_grow() as
> it no longer has to deal with dropping and reacquiring encl->lock when
> a new VA page needs to be allocated.  Eliminating the lock juggling in
> sgx_encl_grow() paves the way for fixing a lock ordering bug in
> ENCLAVE_ADD_PAGE without having to also juggle mm->mmap_sem.
> 
> Serializing ioctls also fixes a race between ENCLAVE_CREATE and
> ENCLAVE_SET_ATTRIBUTE, as the latter does not take encl->lock, e.g.
> concurrent updates to allowed_attributes could result in a stale
> value.  The race could also be fixed by taking encl->lock or making
> allowed_attributes atomic, but both add unnecessary overhead with this
> change applied.
> 
> Note, manipulating the list of VA pages (encl->va_pages) during EADD
> must be done while holding encl->lock, the list of VA pages is visible
> to the reclaimer after the first EADD completes.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Took a few rounds but I think it is now right :-)

Was tricky to squash between three patches but I think I got that one
right too.

Can you check driver, provisioning and reclaimer patches and see if
you see anything weird?

/Jarkko

  reply	other threads:[~2019-08-30 15:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-30  0:17 [PATCH v3 0/5] x86/sgx: Fix lock ordering bug w/ EADD Sean Christopherson
2019-08-30  0:17 ` [PATCH v3 1/5] x86/sgx: Convert encl->flags from an unsigned int to an atomic Sean Christopherson
2019-08-30  0:17 ` [PATCH v3 2/5] x86/sgx: Reject concurrent ioctls on single enclave Sean Christopherson
2019-08-30 15:40   ` Jarkko Sakkinen [this message]
2019-08-30  0:17 ` [PATCH v3 3/5] x86/sgx: Take encl->lock inside of mm->mmap_sem for EADD Sean Christopherson
2019-08-30  0:17 ` [PATCH v3 4/5] x86/sgx: Reject all ioctls on dead enclaves Sean Christopherson
2019-08-30  0:17 ` [PATCH v3 5/5] x86/sgx: Destroy the enclave if EEXTEND fails Sean Christopherson
2019-08-30 16:16 ` [PATCH v3 0/5] x86/sgx: Fix lock ordering bug w/ EADD Jarkko Sakkinen

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=20190830154048.ky3rvirzm5pth2pb@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).