selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>,
	Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	LSM List <linux-security-module@vger.kernel.org>,
	Paul Moore <paul@paul-moore.com>,
	Eric Paris <eparis@parisplace.org>,
	selinux@vger.kernel.org, Jethro Beekman <jethro@fortanix.com>,
	"Xing, Cedric" <cedric.xing@intel.com>,
	"Hansen, Dave" <dave.hansen@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Dr. Greg" <greg@enjellic.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>, X86 ML <x86@kernel.org>,
	"linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"nhorman@redhat.com" <nhorman@redhat.com>,
	"npmccallum@redhat.com" <npmccallum@redhat.com>,
	"Ayoun, Serge" <serge.ayoun@intel.com>,
	"Katz-zamir, Shay" <shay.katz-zamir@intel.com>,
	"Huang, Haitao" <haitao.huang@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"Svahn, Kai" <kai.svahn@intel.com>,
	Borislav Petkov <bp@alien8.de>,
	Josh Triplett <josh@joshtriplett.org>,
	"Huang, Kai" <kai.huang@intel.com>,
	David Rientjes <rientjes@google.com>
Subject: Re: SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support)
Date: Wed, 22 May 2019 15:42:45 -0700	[thread overview]
Message-ID: <CALCETrUS8xyF1JJmQs18BGTDhPRXf+s81BkMZCZwmY73r7M+zg@mail.gmail.com> (raw)
In-Reply-To: <20190522153836.GA24833@linux.intel.com>

On Wed, May 22, 2019 at 8:38 AM Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
>
> On Wed, May 22, 2019 at 09:56:30AM -0400, Stephen Smalley wrote:
> > On 5/22/19 9:22 AM, Jarkko Sakkinen wrote:
> > >On Wed, May 22, 2019 at 04:20:22PM +0300, Jarkko Sakkinen wrote:
> > >>On Tue, May 21, 2019 at 08:51:40AM -0700, Sean Christopherson wrote:
> > >>>Except that mmap() is more or less required to guarantee that ELRANGE
> > >>>established by ECREATE is available.  And we want to disallow mmap() as
> > >>>soon as the first EADD is done so that userspace can't remap the enclave's
> > >>>VMAs via munmap()->mmap() and gain execute permissions to pages that were
> > >>>EADD'd as NX.
> > >>
> > >>We don't want to guarantee such thing and it is not guaranteed. It does
> > >>not fit at all to the multi process work done. Enclaves are detached
> > >>from any particular process addresse spaces. It is responsibility of
> > >>process to open windows to them.
> > >>
> > >>That would be completely against work that we've done lately.
> > >
> > >Example use case: you have a process that just constructs an enclave
> > >and sends it to another process or processes for use. The constructor
> > >process could have basically anything on that range. This was the key
> > >goal of the fd based enclave work.
> >
> > What exactly happens in the constructor versus the recipient processes?
> > Which process performs each of the necessary open(), mmap(), and ioctl()
> > calls for setting up the enclave?  Can you provide a high level overview of
> > the sequence of userspace calls by the constructor and by the recipient
> > similar to what Sean showed earlier for just a single process?
>
> Hmm, what we had talked about was allowing the SGX ioctls to work without
> an associated VMA, with the end goal of letting userspace restrict access
> to /dev/sgx/enclave.   Very roughly...
>
> Enclave Owner:
>
>   connect(builder, ...);
>   send(builder, "/home/sean/path/to/my/enclave");
>
>   recv(builder, &enclave_fd);
>
>   for_each_chunk {
>           mmap(enclave_addr + offset, size, ..., MAP_SHARED, enclave_fd, 0);
>   }
>
>
> Enclave Builder:
>
>   recv(sock, &enclave_path);
>
>   source_fd = open(enclave_path, O_RDONLY);
>   for_each_chunk {
>           <hand waving - mmap()/mprotect() the enclave file into regular memory>
>   }
>
>   enclave_fd = open("/dev/sgx/enclave", O_RDWR);
>
>   ioctl(enclave_fd, ENCLAVE_CREATE, ...);
>   for_each_chunk {
>       struct sgx_enclave_add ioctlargs = {
>           .offset = chunk.offset,
>           .source = chunk.addr,
>           .size   = chunk.size,
>           .type   = chunk.type, /* SGX specific metadata */
>       }
>       ioctl(fd, ENCLAVE_ADD, &ioctlargs); /* modifies enclave's VMAs */
>   }
>   ioctl(enclave_fd, ENCLAVE_INIT, ...);
>
>   write(sock, enclave_fd);
>
>
> But the above flow is flawed because there'a catch-22: ENCLAVE_ECREATE
> takes the virtual address of the enclave, but in the above flow that's
> not established until "mmap(..., enclave_fd)".  And because an enclave's
> virtual range needs to be naturally aligned (hardware requirements), the
> enclave owner would need to do something like:
>
>   source_fd = open("/home/sean/path/to/my/enclave", O_RDONLY);
>   size = <parse size from source_fd>
>
>   enclave_range = mmap(NULL, size*2, PROT_READ, ???, NULL, 0);
>   enclave_addr = (enclave_range + (size - 1)) & ~(size - 1);
>
>   connect(builder, ...);
>   send(builder, {"/home/sean/path/to/my/enclave", enclave_addr});
>
>   recv(builder, &enclave_fd);
>
>   munmap(enclave_range);
>
>   for_each_chunk {
>       addr = mmap(enclave_addr + c.offset, c.size, ..., MAP_SHARED, enclave_fd, 0);
>       if (addr != enclave_addr + c.offset)
>            exit(1);
>   }
>
> And that straight up doesn't work with the v20 driver because mmap() with
> the enclave_fd will run through sgx_get_unmapped_area(), which also does
> the natural alignment adjustments (the idea being that mmap() is mapping
> the entire enclave).  E.g. mmap() will map the wrong address if the offset
> of a chunk is less than its size due to the driver adjusting the address.

That presumably needs to change.

Are we entirely missing an API to allocate a naturally aligned VA
range?  That's kind of annoying.

>
> Eliminating sgx_get_unmapped_area() means userspace is once again on the
> hook for naturally aligning the enclave, which is less than desirable.
>
> Looking back at the original API discussions around a builder process[1],
> we never fleshed out the end-to-end flow.  While having a builder process
> *sounds* reasonable, in practice it adds a lot of complexity without
> providing much in the way of added security.  E.g. in addition to the
> above mmap() issues, since the order of EADDs affects the enclave
> measurement, the enclave owner would need to communicate the exact steps
> to build the enclave, or the builder would need a priori knowledge of the
> enclave format.
>
> Userspace can still restrict access to /dev/sgx/enclave, e.g. by having a
> daemon that requires additional credentials to obtain a new enclave_fd.
> So AFAICT, the only benefit to having a dedicated builder is that it can
> do its own whitelisting of enclaves, but since we're trending towards
> supporting whitelisting enclaves in the kernel, e.g. via sigstruct,
> whitelisting in userspace purely in userspace also provides marginal value.
>
> TL;DR: Requiring VMA backing to build an enclave seems reasonable and sane.

This isn't necessarily a problem, but we pretty much have to use
mprotect() then.

Maybe the semantics could just be that mmap() on the SGX device gives
natural alignment, but that there is no actual constraint enforced by
the driver as to whether mmap() happens before or after ECREATE.
After all, it's *ugly* for user code to reserve its address range with
an awkward giant mmap(), there's nothing fundamentally wrong with it.

As far as I know from this whole discussion, we still haven't come up
with any credible way to avoid tracking, per enclave page, whether
that page came from unmodified PROT_EXEC memory.

  reply	other threads:[~2019-05-22 22:43 UTC|newest]

Thread overview: 127+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8fe520bb-30bd-f246-a3d8-c5443e47a014@intel.com>
     [not found] ` <358e9b36-230f-eb18-efdb-b472be8438b4@fortanix.com>
     [not found]   ` <960B34DE67B9E140824F1DCDEC400C0F4E886094@ORSMSX116.amr.corp.intel.com>
     [not found]     ` <6da269d8-7ebb-4177-b6a7-50cc5b435cf4@fortanix.com>
     [not found]       ` <CALCETrWCZQwg-TUCm58DVG43=xCKRsMe1tVHrR8vdt06hf4fWA@mail.gmail.com>
     [not found]         ` <20190513102926.GD8743@linux.intel.com>
     [not found]           ` <20190514104323.GA7591@linux.intel.com>
     [not found]             ` <CALCETrVbgTCnPo=PAq0-KoaRwt--urrPzn==quAJ8wodCpkBkw@mail.gmail.com>
     [not found]               ` <20190514204527.GC1977@linux.intel.com>
     [not found]                 ` <CALCETrX6aL367mMJh5+Y1Seznfu-AvhPV6P7GkWF4Dhu0GV8cw@mail.gmail.com>
     [not found]                   ` <20190515013031.GF1977@linux.intel.com>
2019-05-15 18:27                     ` SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support) Andy Lutomirski
2019-05-15 19:58                       ` James Morris
2019-05-15 20:35                         ` Andy Lutomirski
2019-05-15 22:46                           ` James Morris
2019-05-15 23:13                             ` Andy Lutomirski
2019-05-16  3:03                               ` Xing, Cedric
2019-05-16  4:40                                 ` Andy Lutomirski
2019-05-16 22:23                                   ` Xing, Cedric
2019-05-17  0:35                                     ` Andy Lutomirski
2019-05-17  1:06                                       ` Xing, Cedric
2019-05-17  1:21                                         ` Andy Lutomirski
2019-05-17 16:05                                       ` Sean Christopherson
2019-05-17 13:53                                     ` Stephen Smalley
2019-05-17 15:09                                       ` Sean Christopherson
2019-05-17 16:20                                         ` Stephen Smalley
2019-05-17 16:24                                           ` Andy Lutomirski
2019-05-17 16:37                                           ` Stephen Smalley
2019-05-17 17:12                                             ` Andy Lutomirski
2019-05-17 18:05                                               ` Stephen Smalley
2019-05-17 19:20                                                 ` Stephen Smalley
2019-05-17 19:28                                                 ` Sean Christopherson
2019-05-17 20:09                                                   ` Stephen Smalley
2019-05-17 20:14                                                     ` Andy Lutomirski
2019-05-17 20:34                                                       ` Stephen Smalley
2019-05-17 21:36                                                     ` Sean Christopherson
2019-05-17 17:29                                             ` Sean Christopherson
2019-05-17 17:42                                               ` Stephen Smalley
2019-05-17 17:50                                                 ` Sean Christopherson
2019-05-17 18:16                                                   ` Stephen Smalley
2019-05-17 17:43                                               ` Andy Lutomirski
2019-05-17 17:55                                                 ` Sean Christopherson
2019-05-17 18:04                                                   ` Linus Torvalds
2019-05-17 18:21                                                     ` Sean Christopherson
2019-05-17 18:33                                                       ` Linus Torvalds
2019-05-17 18:52                                                         ` Sean Christopherson
2019-05-17 18:53                                                       ` Andy Lutomirski
2019-05-16  7:24                               ` James Morris
2019-05-16 21:00                                 ` Andy Lutomirski
2019-05-20  9:38                                 ` Dr. Greg
2019-05-15 21:38                       ` Sean Christopherson
2019-05-16  1:19                         ` Haitao Huang
2019-05-16  5:16                       ` Jarkko Sakkinen
2019-05-16 21:02                         ` Andy Lutomirski
2019-05-16 22:45                           ` Sean Christopherson
2019-05-16 23:29                             ` Xing, Cedric
2019-05-20 11:29                             ` Jarkko Sakkinen
2019-05-20 11:33                           ` Jarkko Sakkinen
2019-05-17  0:03                       ` Sean Christopherson
2019-05-17  0:26                         ` Andy Lutomirski
2019-05-17 15:41                           ` Sean Christopherson
2019-05-20 11:42                             ` Jarkko Sakkinen
2019-05-20 11:41                           ` Jarkko Sakkinen
2019-05-21 15:19                             ` Jarkko Sakkinen
2019-05-21 15:24                               ` Jethro Beekman
2019-05-22 13:10                                 ` Jarkko Sakkinen
2019-05-21 15:51                               ` Sean Christopherson
2019-05-22 13:20                                 ` Jarkko Sakkinen
2019-05-22 13:22                                   ` Jarkko Sakkinen
2019-05-22 13:56                                     ` Stephen Smalley
2019-05-22 15:38                                       ` Sean Christopherson
2019-05-22 22:42                                         ` Andy Lutomirski [this message]
2019-05-23  2:35                                           ` Sean Christopherson
2019-05-23 10:26                                             ` Jarkko Sakkinen
2019-05-23 14:17                                               ` Sean Christopherson
2019-05-23 15:38                                                 ` Andy Lutomirski
2019-05-23 23:40                                                   ` Sean Christopherson
2019-05-24  1:17                                                     ` Andy Lutomirski
2019-05-24  7:24                                                       ` Xing, Cedric
2019-05-24 15:41                                                         ` Stephen Smalley
2019-05-24 16:57                                                           ` Xing, Cedric
2019-05-24 17:42                                                           ` Sean Christopherson
2019-05-24 17:54                                                             ` Andy Lutomirski
2019-05-24 17:56                                                               ` Sean Christopherson
2019-05-24 17:54                                                             ` Sean Christopherson
2019-05-24 18:34                                                               ` Xing, Cedric
2019-05-24 19:13                                                                 ` Sean Christopherson
2019-05-24 19:30                                                                   ` Andy Lutomirski
2019-05-24 20:42                                                                   ` Xing, Cedric
2019-05-24 21:11                                                                     ` Sean Christopherson
2019-05-24 19:37                                                                 ` Andy Lutomirski
2019-05-24 20:03                                                                   ` Sean Christopherson
2019-05-24 20:58                                                                     ` Xing, Cedric
2019-05-24 21:27                                                                     ` Andy Lutomirski
2019-05-24 22:41                                                                       ` Sean Christopherson
2019-05-24 23:42                                                                         ` Andy Lutomirski
2019-05-25 22:40                                                                           ` Xing, Cedric
2019-05-26  0:57                                                                             ` Andy Lutomirski
2019-05-26  6:09                                                                               ` Xing, Cedric
2019-05-28 20:24                                                                                 ` Sean Christopherson
2019-05-28 20:48                                                                                   ` Andy Lutomirski
2019-05-28 21:41                                                                                     ` Sean Christopherson
2019-05-30  5:38                                                                                       ` Xing, Cedric
2019-05-30 17:21                                                                                         ` Sean Christopherson
2019-05-29 14:08                                                                                   ` Stephen Smalley
2019-05-30  6:12                                                                                     ` Xing, Cedric
2019-05-30 14:22                                                                                       ` Stephen Smalley
2019-05-30 14:31                                                                                         ` Andy Lutomirski
2019-05-30 15:04                                                                                           ` Stephen Smalley
2019-05-30 16:14                                                                                             ` Andy Lutomirski
2019-05-30 18:01                                                                                               ` Sean Christopherson
2019-05-30 19:20                                                                                                 ` Andy Lutomirski
2019-05-30 21:16                                                                                                   ` Sean Christopherson
2019-05-30 21:23                                                                                                     ` Andy Lutomirski
2019-05-30 21:36                                                                                                       ` Sean Christopherson
2019-06-03  9:12                                                                                                         ` Dr. Greg
2019-06-03 21:08                                                                                                         ` Jarkko Sakkinen
2019-05-30 21:48                                                                                                   ` Xing, Cedric
2019-05-30 22:24                                                                                                     ` Sean Christopherson
2019-06-03 21:05                                                                                                 ` Jarkko Sakkinen
2019-06-03 20:54                                                                                               ` Jarkko Sakkinen
2019-06-03 21:23                                                                                                 ` Sean Christopherson
2019-06-04 11:39                                                                                                   ` Jarkko Sakkinen
2019-06-03 21:37                                                                                                 ` Andy Lutomirski
2019-06-03 20:47                                                                                             ` Jarkko Sakkinen
2019-06-03 20:43                                                                                           ` Jarkko Sakkinen
2019-05-25 17:31                                                                     ` Dr. Greg
2019-05-24 16:43                                                         ` Andy Lutomirski
2019-05-24 17:07                                                           ` Sean Christopherson
2019-05-24 17:51                                                             ` Andy Lutomirski
2019-05-24 14:44                                                   ` Stephen Smalley
2019-05-27 13:48                                                   ` Jarkko Sakkinen
2019-05-23 19:58                                                 ` Sean Christopherson
2019-05-27 13:34                                                 ` Jarkko Sakkinen
2019-05-27 13:38                                                   ` Jarkko Sakkinen
2019-05-23  8:10                                           ` Jarkko Sakkinen
2019-05-23  8:23                                             ` Jarkko Sakkinen
2019-05-20 11:36                         ` 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=CALCETrUS8xyF1JJmQs18BGTDhPRXf+s81BkMZCZwmY73r7M+zg@mail.gmail.com \
    --to=luto@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=cedric.xing@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=eparis@parisplace.org \
    --cc=greg@enjellic.com \
    --cc=haitao.huang@intel.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jethro@fortanix.com \
    --cc=jmorris@namei.org \
    --cc=josh@joshtriplett.org \
    --cc=kai.huang@intel.com \
    --cc=kai.svahn@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=npmccallum@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=rientjes@google.com \
    --cc=sds@tycho.nsa.gov \
    --cc=sean.j.christopherson@intel.com \
    --cc=selinux@vger.kernel.org \
    --cc=serge.ayoun@intel.com \
    --cc=serge@hallyn.com \
    --cc=shay.katz-zamir@intel.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@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).