Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1856528ybi; Sun, 16 Jun 2019 15:18:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+5d2HA/2n7DNn2vZs2p6ftbLL8C5/OPFcSrMF8BasreN5ndR84e+EgMwvnObmCAGL4VP4 X-Received: by 2002:aa7:8dd2:: with SMTP id j18mr40959459pfr.88.1560723533723; Sun, 16 Jun 2019 15:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560723533; cv=none; d=google.com; s=arc-20160816; b=HbFQwDUgpL/6I98bA3fPTIGyAsfnJbAc3ZCoiajYPw0zeXrq7ZjmGgWr6GopJ8FjP6 0vCVzpka7hC0vlJahhObk/YxmYlJxNrPQe4aFl4CAf0gVYE8eU3D68etuHuzOA1tMyrw 6wDhtDYM+0nooYu1nNZLdZhoiRiJz3mPQuDcbdsawXiKImzczgVyTWJ83rQg6nlvUL2k DQNcInu7TU2by3VGJtwecbfeiJkZA/h9Dhisbo+k8F4mxW6x0n2vZwJ+bKhYVvqS/E5V BmCgmUQEXu4SwL250rnAmHhgpv7vPOVtDr/Drk3EIVbq6Hx6qAxB5UgAVnc7J35MgIlr V89A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=E7V7P66VnTZ3pl0vw9L/85BVdL4DF/V/j1UL7RfvbfY=; b=ac9M/GgQpge0wpyJ6CR/Z1oY3nRhw4wbPdpME/LqVu/j4hFw6R1L4+zKntfP6F0+U5 wn1R3FkoJswpSNS0Lb4FaCa1GbV9fdWaGV8h+YWibA+oBV4L43zPTwIsCenFddg2J/eW kumbcm1hvqLyhhNHX7kCFKUe7OjZruZjAjoZtwm73pURVUaxbhfsZb063VRdPAtfkSSA jJrScrLDKDK5azk0u0x9iaQu82MCqi78fu09VfO2dHVJJv2wmSeAmK5g6TMMywvkbVPX Uv1/FJ1m1cuarJgoXWf9tcjh9zxwjRHUTl4ntQENr/sHMjS6WfG5IsPMThT3uFfJzfNa j1Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T+y0s0KC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y138si8756826pfb.3.2019.06.16.15.18.38; Sun, 16 Jun 2019 15:18:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T+y0s0KC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727478AbfFPWQs (ORCPT + 99 others); Sun, 16 Jun 2019 18:16:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:41454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727447AbfFPWQr (ORCPT ); Sun, 16 Jun 2019 18:16:47 -0400 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 D49CA2087F 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-f46.google.com with SMTP id f17so4591734wme.2 for ; Sun, 16 Jun 2019 15:16:45 -0700 (PDT) X-Gm-Message-State: APjAAAUmx96IqHxpP+/2lHjYWLS2dPspG9UQ4aRzRMmOUJ90fjk7PAFZ KQaOiDHLlaVBuEigj+3GyTvtRyKDWh4jeBqNulyOzA== 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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