Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3926727ybi; Tue, 18 Jun 2019 08:42:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIzcRS273vzdj+XXY8gVmazf5CMBQ6XLcHufKk1QXTECKCQ/6APY4Mm811F3BYOfV9zBXg X-Received: by 2002:a17:902:9a91:: with SMTP id w17mr17969526plp.126.1560872574707; Tue, 18 Jun 2019 08:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560872574; cv=none; d=google.com; s=arc-20160816; b=p3oJawxKse/ykxwBPOMt7Jg4hu1BEB+9WUZVmM23I62wiB3d/2p5mX9cBcjXyYI+g1 5ZbTsVwLC8qyaaGnPxlIt9M/fXtuOzCh2IdUXl8Ii6yND//YbWdxs8YyuzN9xS+LN3pY r6D8xWkyeNYfjVlEzMxT0kahb/MupKhUL5t758hEu/mqV+RvSor+3NZpiftD753QB+QU GrNEyRJPuIwA+wh/gpumtFFAebfz6VnCYzz4ll4z9OwZ03Hhjx2+ps0tV1THvVU3sdTA ncUrFZlJ24euQxloLqzJP0fUUHbaifznNOrTslUaHPJc4Cmb0NteBSCrcuSwxbVeJF1X nGXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=qP8AlOpEbEsqLDEKCqs6YSR51pHiupbwBDIxd8p98aA=; b=SDQricvu59qgf+Ok41Sn0tpWDT/Ojjx787lwV3llQPBg+X2DE2cWw4CAeY+6KLURJV EAxx40gvmZSRKonp8YQVt/fKUxkc2s5QAZQ8HuOYIshppXZd5jerB+BGlQJbrN3vsKW5 aVE9bJfZjV89OWnVGq8AsSXFFrcJOET3Zl6zycm5TsuxYurHQg+zOhB+N7vrTUw4UKsZ 40I0T2ucSQLsSwFBKZco+n4fsEal3k4wAg5/fNN2VqC7C6s9+a1l830Lv+fhGT2d33NE 78LlUIJJZhWWnYCSHnbB7EtYiLUEHv3p+63NvU30exqbvclug/aPDvge0r4pjQvygY8A 3bMQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h21si454655pgv.102.2019.06.18.08.42.39; Tue, 18 Jun 2019 08:42:54 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729774AbfFRPmB (ORCPT + 99 others); Tue, 18 Jun 2019 11:42:01 -0400 Received: from wind.enjellic.com ([76.10.64.91]:35716 "EHLO wind.enjellic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729349AbfFRPmA (ORCPT ); Tue, 18 Jun 2019 11:42:00 -0400 Received: from wind.enjellic.com (localhost [127.0.0.1]) by wind.enjellic.com (8.15.2/8.15.2) with ESMTP id x5IFegEV006176; Tue, 18 Jun 2019 10:40:42 -0500 Received: (from greg@localhost) by wind.enjellic.com (8.15.2/8.15.2/Submit) id x5IFeepQ006175; Tue, 18 Jun 2019 10:40:40 -0500 Date: Tue, 18 Jun 2019 10:40:40 -0500 From: "Dr. Greg" To: Sean Christopherson Cc: Andy Lutomirski , Stephen Smalley , Cedric Xing , LSM List , selinux@vger.kernel.org, LKML , linux-sgx@vger.kernel.org, Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , Paul Moore , Eric Paris , Jethro Beekman , Dave Hansen , Thomas Gleixner , Linus Torvalds , Andrew Morton , nhorman@redhat.com, pmccallum@redhat.com, "Ayoun, Serge" , "Katz-zamir, Shay" , "Huang, Haitao" , Andy Shevchenko , "Svahn, Kai" , Borislav Petkov , Josh Triplett , "Huang, Kai" , David Rientjes , "Roberts, William C" , Philip Tricca Subject: Re: [RFC PATCH v1 2/3] LSM/x86/sgx: Implement SGX specific hooks in SELinux Message-ID: <20190618154040.GA4603@wind.enjellic.com> Reply-To: "Dr. Greg" References: <20190611220243.GB3416@linux.intel.com> <8d99d8fb-a921-286a-8cf0-cd522e09b37c@tycho.nsa.gov> <20190614004600.GF18385@linux.intel.com> <20190614153840.GC12191@linux.intel.com> <20190617164915.GA25085@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190617164915.GA25085@linux.intel.com> User-Agent: Mutt/1.4i X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.2.3 (wind.enjellic.com [127.0.0.1]); Tue, 18 Jun 2019 10:40:42 -0500 (CDT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 17, 2019 at 09:49:15AM -0700, Sean Christopherson wrote: Good morning to everyone. > On Sun, Jun 16, 2019 at 03:14:51PM -0700, Andy Lutomirski wrote: > > The most significant issue I see is the following. Consider two > > cases. First, an SGX2 enclave that dynamically allocates memory but > > doesn't execute code from dynamic memory. Second, an SGX2 enclave > > that *does* execute code from dynamic memory. In #1, the untrusted > > stack needs to decide whether to ALLOW_EXEC when the memory is > > allocated, which means that it either needs to assume the worst or it > > needs to know at allocation time whether the enclave ever intends to > > change the permission to X. > I'm just not convinced that folks running enclaves that can't > communicate their basic functionality will care one whit about > SELinux restrictions, i.e. will happily give EXECMOD even if it's > not strictly necessary. Hence the comments in my mail from last Friday. It seems to us that the path forward is to require the enclave author/signer to express their intent to implement executable dynamic memory, see below. > > I suppose there's a middle ground. The driver could use model #1 for > > driver-filled pages and model #2 for dynamic pages. I haven't tried > > to fully work it out, but I think there would be the ALLOW_READ / > > ALLOW_WRITE / ALLOW_EXEC flag for EADD-ed pages but, for EAUG-ed > > pages, there would be a different policy. This might be as simple as > > internally having four flags instead of three: > > > > ALLOW_READ, ALLOW_WRITE, ALLOW_EXEC: as before > > > > ALLOW_EXEC_COND: set implicitly by the driver for EAUG. > > > > As in #1, if you try to mmap or protect a page with neither ALLOW_EXEC > > variant, it fails (-EACCES, perhaps). But, if you try to mmap or > > mprotect an ALLOW_EXEC_COND page with PROT_EXEC, you ask LSM for > > permission. There is no fancy DIRTY tracking here, since it's > > reasonable to just act as though *every* ALLOW_EXEC_COND page is > > dirty. There is no real auditing issue here, since LSM can just log > > what permission is missing. > > > > Does this seem sensible? It might give us the best of #1 and #2. > It would work and is easy to implement *if* SELinux ties permissions > to the process, as the SIGSTRUCT vma/file won't be available at > EAUG+mprotect(). I already have a set of patches to that effect, > I'll send 'em out in a bit. The VMA that is crafted from the enclave file is going to exist for the life of the enclave. If the intent to use executable dynamic memory is specified when the enclave image is being built, or as a component of enclave initialization, the driver is in a position to log/deny a request to EAUG+mprotect whenever it occurs. The sensitive criteria would seem to be any request for dynamically allocated memory with executable status. The potential security impact of dynamically executable content is something that is dependent on the enclave author rather then the context of execution that is requesting pages to be allocated for such purposes. There is going to be an LSM hook to evaluate the SIGSTRUCT at the time of EINIT, so all of the necessary information is there to make a decision on whether or not to flag the VMA as being allowed to support dynamically executable content. It doesn't seem like an onerous requirement for this information to be specified in the enclave metadata. For optimum security, one could perhaps argue that the ability to implement dynamic memory should have been a specifiable attribute of the enclave, similar to the debug, launch and provisioning attributes. As we have indicated in the past, once the enclave is initialized with permissions for dynamically executable content, the platform is completely dependent on the security intentions of the author of the enclave. Given that, the notion of enduring significant LSM complexity does not seem to be justified. Which opens up another set of security implications to discuss but we will let those lie for the moment. Have a good day. Dr. Greg As always, Dr. G.W. Wettstein, Ph.D. Enjellic Systems Development, LLC. 4206 N. 19th Ave. Specializing in information infra-structure Fargo, ND 58102 development. PH: 701-281-1686 EMAIL: greg@enjellic.com ------------------------------------------------------------------------------ "More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk." -- Bruce Schneier Beyond Fear