[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALCETrWxw7xALE0kmiYBzomaSMAeXEVq-7rX7xeqPtDPeDQiCA@mail.gmail.com>
Date: Thu, 16 May 2019 17:26:15 -0700
From: Andy Lutomirski <luto@...nel.org>
To: Sean Christopherson <sean.j.christopherson@...el.com>
Cc: Andy Lutomirski <luto@...nel.org>,
James Morris <jmorris@...ei.org>,
"Serge E. Hallyn" <serge@...lyn.com>,
LSM List <linux-security-module@...r.kernel.org>,
Paul Moore <paul@...l-moore.com>,
Stephen Smalley <sds@...ho.nsa.gov>,
Eric Paris <eparis@...isplace.org>, selinux@...r.kernel.org,
Jarkko Sakkinen <jarkko.sakkinen@...ux.intel.com>,
Jethro Beekman <jethro@...tanix.com>,
"Xing, Cedric" <cedric.xing@...el.com>,
"Hansen, Dave" <dave.hansen@...el.com>,
Thomas Gleixner <tglx@...utronix.de>,
"Dr. Greg" <greg@...ellic.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>, X86 ML <x86@...nel.org>,
"linux-sgx@...r.kernel.org" <linux-sgx@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
"nhorman@...hat.com" <nhorman@...hat.com>,
"npmccallum@...hat.com" <npmccallum@...hat.com>,
"Ayoun, Serge" <serge.ayoun@...el.com>,
"Katz-zamir, Shay" <shay.katz-zamir@...el.com>,
"Huang, Haitao" <haitao.huang@...el.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
"Svahn, Kai" <kai.svahn@...el.com>, Borislav Petkov <bp@...en8.de>,
Josh Triplett <josh@...htriplett.org>,
"Huang, Kai" <kai.huang@...el.com>,
David Rientjes <rientjes@...gle.com>
Subject: Re: SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support)
On Thu, May 16, 2019 at 5:03 PM Sean Christopherson
<sean.j.christopherson@...el.com> wrote:
>
> On Wed, May 15, 2019 at 11:27:04AM -0700, Andy Lutomirski wrote:
> > Here's a very vague proposal that's kind of like what I've been
> > thinking over the past few days. The SGX inode could track, for each
> > page, a "safe-to-execute" bit. When you first open /dev/sgx/enclave,
> > you get a blank enclave and all pages are safe-to-execute. When you
> > do the ioctl to load context (which could be code, data, or anything
> > else), the kernel will check whether the *source* VMA is executable
> > and, if not, mark the page of the enclave being loaded as unsafe.
> > Once the enclave is initialized, the driver will clear the
> > safe-to-execute bit for any page that is successfully mapped writably.
> >
> > The intent is that a page of the enclave is safe-to-execute if that
> > page was populated from executable memory and not modified since then.
> > LSMs could then enforce a policy that you can map an enclave page RX
> > if the page is safe-to-execute, you can map any page you want for
> > write if there are no executable mappings, and you can only map a page
> > for write and execute simultaneously if you can EXECMOD permission.
> > This should allow an enclave to be loaded by userspace from a file
> > with EXECUTE rights.
>
> I'm still confused as to why you want to track execute permissions on the
> enclave pages and add SGX-specific LSM hooks. Is there anything that
> prevents userspace from building the enclave like any other DSO and then
> copying it into enclave memory?
It's entirely possible that I'm the one missing something. But here's
why I think this:
> I feel like I'm missing something.
>
> 1. Userspace loads enclave into regular memory, e.g. like a normal DSO.
> All mmap(), mprotect(), etc... calls are subject to all existing
> LSM policies.
>
> 2. Userspace opens /dev/sgx/enclave to instantiate a new enclave.
>
> 3. Userspace uses mmap() to allocate virtual memory for its enclave,
> again subject to all existing LSM policies (sane userspaces map it RO
> since the permissions eventually get tossed anyways).
Is userspace actually requred to mmap() the enclave prior to EADDing things?
>
> 4. SGX subsystem refuses to service page faults for enclaves that have
> not yet been initialized, e.g. signals SIGBUS or SIGSEGV.
>
> 5. Userspace invokes SGX ioctl() to copy enclave from regulary VMA to
> enclave VMA.
>
> 6. SGX ioctl() propagates VMA protection-related flags from source VMA
> to enclave VMA, e.g. invokes mprotect_fixup(). Enclave VMA(s) may
> be split as part of this process.
Does this also call the LSM? If so, what is it expected to do? What
happens if there are different regions with different permissions on
the same page? SGX has 256-byte granularity right?
>
> 7. At all times, mprotect() calls on the enclave VMA are subject to
> existing LSM policies, i.e. it's not special cased for enclaves.
I don't think the normal behavior actually works here. An enclave is
always MAP_SHARED, so (with SELinux) mprotecting() to X or RX requires
EXECUTE and mprotecting() to RWX requires extra permissions. But user
code can also mmap() the enclave again. What is supposed to happen in
that case?
Powered by blists - more mailing lists