From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: Re: [PATCH 4/5] x86/sgx: Validate TCS permssions in sgx_validate_secinfo()
Date: Thu, 22 Aug 2019 19:05:22 -0700 [thread overview]
Message-ID: <20190823020522.GK25467@linux.intel.com> (raw)
In-Reply-To: <ef15d08e54d62cea3f659e17f0a1b4a881aeb96f.camel@linux.intel.com>
On Fri, Aug 23, 2019 at 03:57:36AM +0300, Jarkko Sakkinen wrote:
> On Fri, 2019-08-23 at 03:39 +0300, Jarkko Sakkinen wrote:
> > On Thu, 2019-08-22 at 09:34 -0700, Sean Christopherson wrote:
> > > On Thu, Aug 22, 2019 at 07:31:39PM +0300, Jarkko Sakkinen wrote:
> > > > On Wed, 2019-08-21 at 20:55 -0700, Sean Christopherson wrote:
> > > > > Why are we validating the TCS protection bits? Hardware ignores them, so
> > > > > why do we care? sgx_ioc_enclave_add_page() sets the internal protection
> > > > > bits so there's no danger of putting the wrong thing in the page tables.
> > > >
> > > > I think that in this commit I got it wrong but I think this is awkward:
> > > >
> > > > /*
> > > > * TCS pages must always RW set for CPU access while the SECINFO
> > > > * permissions are *always* zero - the CPU ignores the user provided
> > > > * values and silently overwrites with zero permissions.
> > > > */
> > > > if ((secinfo.flags & SGX_SECINFO_PAGE_TYPE_MASK) == SGX_SECINFO_TCS)
> > > > prot |= PROT_READ | PROT_WRITE;
> > > >
> > > > In my opinion the right thing to do would be check that SECINFO has *at
> > > > minimum* RW and return -EINVAL if not.
> > >
> > > Based on Serge's comment, hardware updates MRENCLAVE with SECINFO *after*
> > > it overwrites the flags for TCS pages. I.e. requiring RW for the TCS
> > > would result in every enclave failing EINIT due to an invalid measurement.
> > > It'd be fairly easy to verify this if we want to triple check that that is
> > > indeed hardware behavior.
> >
> > This is from the signing tool that I wrote back in 2016 used in the
> > selftest:
> >
> > struct mreadd {
> > uint64_t tag;
> > uint64_t offset;
> > uint64_t flags; /* SECINFO flags */
> > uint8_t reserved[40];
> > } __attribute__((__packed__));
> >
> > static bool mrenclave_eadd(EVP_MD_CTX *ctx, uint64_t offset, uint64_t flags)
> > {
> > struct mreadd mreadd;
> >
> > memset(&mreadd, 0, sizeof(mreadd));
> > mreadd.tag = MREADD;
> > mreadd.offset = offset;
> > mreadd.flags = flags;
> >
> > return mrenclave_update(ctx, &mreadd);
> > }
> >
> > If MRENCLAVE was updated after the overwrite, this would not work.
> >
> > The least confusing semantics would be to require RW, no more or less.
>
> OK, it is how Serge said.
>
> This can we verified from the SDM easily (SCRATCH_SECINFO gets zeros
> is extended after that).
>
> And also from my signing tool :-)
>
> for (offset = 0; offset < sb.st_size; offset += 0x1000) {
> if (!offset)
> flags = SGX_SECINFO_TCS;
> else
> flags = SGX_SECINFO_REG | SGX_SECINFO_R |
> SGX_SECINFO_W | SGX_SECINFO_X;
>
> OK, so this looks like that my patch does exactly the right thing,
> right?
That's my understanding as well. Definitely worthy of a comment
explaining all of the above.
next prev parent reply other threads:[~2019-08-23 2:05 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-19 15:25 [PATCH 0/5] x86/sgx: Improve permission handing Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 1/5] x86/sgx: Document permission handling better Jarkko Sakkinen
2019-08-22 3:43 ` Sean Christopherson
2019-08-22 16:04 ` Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 2/5] x86/sgx: Use memchr_inv() in sgx_validate_secinfo() Jarkko Sakkinen
2019-08-22 3:47 ` Sean Christopherson
2019-08-22 16:20 ` Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 3/5] x86/sgx: Make sgx_validate_secinfo() more readable Jarkko Sakkinen
2019-08-22 3:48 ` Sean Christopherson
2019-08-22 16:26 ` Jarkko Sakkinen
2019-08-22 10:39 ` Ayoun, Serge
2019-08-22 16:45 ` Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 4/5] x86/sgx: Validate TCS permssions in sgx_validate_secinfo() Jarkko Sakkinen
2019-08-21 18:45 ` Jarkko Sakkinen
2019-08-22 11:33 ` Ayoun, Serge
2019-08-22 14:27 ` Sean Christopherson
2019-08-22 16:46 ` Jarkko Sakkinen
2019-08-22 16:59 ` Jarkko Sakkinen
2019-08-22 3:55 ` Sean Christopherson
2019-08-22 16:31 ` Jarkko Sakkinen
2019-08-22 16:34 ` Sean Christopherson
2019-08-23 0:39 ` Jarkko Sakkinen
2019-08-23 0:57 ` Jarkko Sakkinen
2019-08-23 2:05 ` Sean Christopherson [this message]
2019-08-23 13:41 ` Jarkko Sakkinen
2019-08-22 16:38 ` Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 5/5] x86/sgx: Rename vm_prot_bits as max_vm_flags Jarkko Sakkinen
2019-08-22 4:00 ` Sean Christopherson
2019-08-22 16:43 ` 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=20190823020522.GK25467@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=linux-sgx@vger.kernel.org \
/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).