From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47D63C31E54 for ; Sun, 16 Jun 2019 22:16:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F5152084B for ; Sun, 16 Jun 2019 22:16:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560723412; bh=oLx5pniqxG/jELRH2iyGmtPEYVhozT1h6R4yt+A9/zc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=WRzNhqMUhwLS73V0rmAsj5MwTty+E2BfxMVwgNhujIfQpS/2mjWWUrwdMLpE6o/i6 egRb1F2SpYczQb/blK/wOEVMFHa/36T9BKEfJKpLgmv4kR3o60AtlGJxk3OZW2b9PG GdQb8ahWbfpmMvAyUb6FlNdc0OOhT1HnTo2pJmaQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727394AbfFPWQv (ORCPT ); Sun, 16 Jun 2019 18:16:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:41434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727209AbfFPWQr (ORCPT ); Sun, 16 Jun 2019 18:16:47 -0400 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D29B420866 for ; Sun, 16 Jun 2019 22:16:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560723406; bh=oLx5pniqxG/jELRH2iyGmtPEYVhozT1h6R4yt+A9/zc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=T+y0s0KCYKjJALEZNyPoXM5/rZcyVy81hMNXsvjs1JoQof8fTSG2t6O2B7gnYh6KE Ut3jaYPJDUcKaTX1rbCTyjBJQzV6v1GsdVNZFCMI6jwt1PJAwgesmrRBSXBw8W+XGl JQp8pKioMJXgvb/P4BcsGhh4AEUfQXu3hbDQGi98= Received: by mail-wm1-f41.google.com with SMTP id c6so7117902wml.0 for ; Sun, 16 Jun 2019 15:16:45 -0700 (PDT) X-Gm-Message-State: APjAAAVBD4pH0eeU4JIcwHZHp0OP8+DOznw7VsnOWLOZ+nZysnikXmrR HDyHs8UGdBX/s86glxRCx3xSOUouIMOo8+dM7lQwSg== X-Google-Smtp-Source: APXvYqyLNC6Yg329xWtpRh6aEChlgRxAAqzoyltmGU+X5FI8weBu+KOZvAoY8R4ojMAgdUlfKbzzFc86TSOLGIg1qZA= X-Received: by 2002:a1c:9a53:: with SMTP id c80mr15207022wme.173.1560723404414; Sun, 16 Jun 2019 15:16:44 -0700 (PDT) MIME-Version: 1.0 References: <20190611220243.GB3416@linux.intel.com> <8d99d8fb-a921-286a-8cf0-cd522e09b37c@tycho.nsa.gov> <20190614004600.GF18385@linux.intel.com> <960B34DE67B9E140824F1DCDEC400C0F65504665@ORSMSX116.amr.corp.intel.com> In-Reply-To: <960B34DE67B9E140824F1DCDEC400C0F65504665@ORSMSX116.amr.corp.intel.com> From: Andy Lutomirski Date: Sun, 16 Jun 2019 15:16:32 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v1 2/3] LSM/x86/sgx: Implement SGX specific hooks in SELinux To: "Xing, Cedric" Cc: "Christopherson, Sean J" , Stephen Smalley , "linux-security-module@vger.kernel.org" , "selinux@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-sgx@vger.kernel.org" , "jarkko.sakkinen@linux.intel.com" , "luto@kernel.org" , "jmorris@namei.org" , "serge@hallyn.com" , "paul@paul-moore.com" , "eparis@parisplace.org" , "jethro@fortanix.com" , "Hansen, Dave" , "tglx@linutronix.de" , "torvalds@linux-foundation.org" , "akpm@linux-foundation.org" , "nhorman@redhat.com" , "pmccallum@redhat.com" , "Ayoun, Serge" , "Katz-zamir, Shay" , "Huang, Haitao" , "andriy.shevchenko@linux.intel.com" , "Svahn, Kai" , "bp@alien8.de" , "josh@joshtriplett.org" , "Huang, Kai" , "rientjes@google.com" , "Roberts, William C" , "Tricca, Philip B" Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: On Fri, Jun 14, 2019 at 10:16 AM Xing, Cedric wrote: > > > From: Christopherson, Sean J > > Sent: Thursday, June 13, 2019 5:46 PM > > > > On Thu, Jun 13, 2019 at 01:02:17PM -0400, Stephen Smalley wrote: > > > On 6/11/19 6:02 PM, Sean Christopherson wrote: > > > >On Tue, Jun 11, 2019 at 09:40:25AM -0400, Stephen Smalley wrote: > > > >>I haven't looked at this code closely, but it feels like a lot of > > > >>SGX-specific logic embedded into SELinux that will have to be > > > >>repeated or reused for every security module. Does SGX not track > > this state itself? > > > > > > > >SGX does track equivalent state. > > > > > > > >There are three proposals on the table (I think): > > > > > > > > 1. Require userspace to explicitly specificy (maximal) enclave > > page > > > > permissions at build time. The enclave page permissions are > > provided > > > > to, and checked by, LSMs at enclave build time. > > > > > > > > Pros: Low-complexity kernel implementation, straightforward > > auditing > > > > Cons: Sullies the SGX UAPI to some extent, may increase > > complexity of > > > > SGX2 enclave loaders. > > > > > > > > 2. Pre-check LSM permissions and dynamically track mappings to > > enclave > > > > pages, e.g. add an SGX mprotect() hook to restrict W->X and WX > > > > based on the pre-checked permissions. > > > > > > > > Pros: Does not impact SGX UAPI, medium kernel complexity > > > > Cons: Auditing is complex/weird, requires taking enclave- > > specific > > > > lock during mprotect() to query/update tracking. > > > > > > > > 3. Implement LSM hooks in SGX to allow LSMs to track enclave > > regions > > > > from cradle to grave, but otherwise defer everything to LSMs. > > > > > > > > Pros: Does not impact SGX UAPI, maximum flexibility, precise > > auditing > > > > Cons: Most complex and "heaviest" kernel implementation of the > > three, > > > > pushes more SGX details into LSMs. > > > > > > > >My RFC series[1] implements #1. My understanding is that Andy > > > >(Lutomirski) prefers #2. Cedric's RFC series implements #3. > > > > > > > >Perhaps the easiest way to make forward progress is to rule out the > > > >options we absolutely *don't* want by focusing on the potentially > > > >blocking issue with each option: > > > > > > > > #1 - SGX UAPI funkiness > > > > > > > > #2 - Auditing complexity, potential enclave lock contention > > > > > > > > #3 - Pushing SGX details into LSMs and complexity of kernel > > > > implementation > > > > > > > > > > > >[1] > > > >https://lkml.kernel.org/r/20190606021145.12604-1-sean.j.christopherso > > > >n@intel.com > > > > > > Given the complexity tradeoff, what is the clear motivating example > > > for why > > > #1 isn't the obvious choice? That the enclave loader has no way of > > > knowing a priori whether the enclave will require W->X or WX? But > > > aren't we better off requiring enclaves to be explicitly marked as > > > needing such so that we can make a more informed decision about > > > whether to load them in the first place? > > > > Andy and/or Cedric, can you please weigh in with a concrete (and > > practical) use case that will break if we go with #1? The auditing > > issues for #2/#3 are complex to say the least... > > How does enclave loader provide per-page ALLOW_* flags? And a related question is why they are necessary for enclaves but unnecessary for regular executables or shared objects. > > What's the story for SGX2 if mmap()'ing non-existing pages is not allowed? > I think it just works. Either you can't mmap() the page until you have explicitly EAUG-ed it, or you add a new ioctl() that is effectively "EAUG lazily". The latter would declare that address and request that it get allocated and EAUGed when faulted, but it wouldn't actually do the EAUG. --Andy