Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp883244ybi; Fri, 24 May 2019 13:05:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKykL0iNt45vH47HWsZblmZ3bIAJX9N5Owt/Gb3hqx/6xvk70KwqsAv/6a27bDxdTJQlBP X-Received: by 2002:a63:6a41:: with SMTP id f62mr106315781pgc.392.1558728301052; Fri, 24 May 2019 13:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558728301; cv=none; d=google.com; s=arc-20160816; b=uUa/6TPXcT2OfrANdcEbEU8YWr9wmJmEd1A+7PlDG+8oISt4luycxqgR+1b59R0JDK lGxnlJx6i9wTdPWUWtqY8X5EckV6qEE8o7S6Lg7DemKomlj8Z61v0jjNev/+tmQ+0qsD bhy0uU9TU+3yWFMO6mMSahQON0oKtQI9c0ByYIhgnoYGsz8usUYPc7ccJ+dhchSIaDt3 YI5KAbB+5BdLp5tENjD5bKWxZt4lww0MHcGHpxgnDlDYuf33LM0CWIaBlxj5H/MzZc4D jvIH8XcTqpLM5he9XLQGE+dAUnS0fRr7xXiz4tiiMr6PQLUIP1mydbpHWX0vMJ2Uqsev h2lA== 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:message-id:subject:cc :to:from:date; bh=cWL0jj//oLvvmKms8cPYosFv9VWwmM0hjEHG/b9wnIY=; b=mLB+n4SR2ozZavbYqdOqtVfI/2e069yK6Myf5KMOERlmMkX/IIyZaClO84CDZkrh0f v+DQmZLdqwYSJINc9zliXy8qn27nOIqx/2QWV5wgWgM3wz32CKGYxgyloIS16kUUyITa OcAfqBfrmxsSd6QwQWYF8M3BfMEa7LeOS+6A+S7yAg3uCiaAsNMKSg7IYnUWII/zIwmM +iE2KjBudgmojQb5TumCQVHCHWRXLO8qSHpoN0h0RzQqdsTackwR9vd7paP8GRX1/baI 0smS+x5nEdZv4J75+RNHkipJdxLhVWevjO8m+U9mF5Il2ZmMu1bk2Y5I7Gc26hdL89zb MHJg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bf1si5261187plb.49.2019.05.24.13.04.44; Fri, 24 May 2019 13:05:01 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391782AbfEXUDg (ORCPT + 99 others); Fri, 24 May 2019 16:03:36 -0400 Received: from mga11.intel.com ([192.55.52.93]:59357 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391612AbfEXUDf (ORCPT ); Fri, 24 May 2019 16:03:35 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 May 2019 13:03:34 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by fmsmga001.fm.intel.com with ESMTP; 24 May 2019 13:03:33 -0700 Date: Fri, 24 May 2019 13:03:33 -0700 From: Sean Christopherson To: Andy Lutomirski Cc: "Xing, Cedric" , Stephen Smalley , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , LSM List , Paul Moore , Eric Paris , "selinux@vger.kernel.org" , Jethro Beekman , "Hansen, Dave" , Thomas Gleixner , "Dr. Greg" , Linus Torvalds , LKML , X86 ML , "linux-sgx@vger.kernel.org" , Andrew Morton , "nhorman@redhat.com" , "npmccallum@redhat.com" , "Ayoun, Serge" , "Katz-zamir, Shay" , "Huang, Haitao" , Andy Shevchenko , "Svahn, Kai" , Borislav Petkov , Josh Triplett , "Huang, Kai" , David Rientjes Subject: Re: SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support) Message-ID: <20190524200333.GF365@linux.intel.com> References: <20190523141752.GA12078@linux.intel.com> <20190523234044.GC12078@linux.intel.com> <960B34DE67B9E140824F1DCDEC400C0F654E8956@ORSMSX116.amr.corp.intel.com> <20190524174243.GA365@linux.intel.com> <20190524175458.GB365@linux.intel.com> <960B34DE67B9E140824F1DCDEC400C0F654E8E1D@ORSMSX116.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 24, 2019 at 12:37:44PM -0700, Andy Lutomirski wrote: > On Fri, May 24, 2019 at 11:34 AM Xing, Cedric wrote: > > > > If "initial permissions" for enclaves are less restrictive than shared > > objects, then it'd become a backdoor for circumventing LSM when enclave > > whitelisting is *not* in place. For example, an adversary may load a page, > > which would otherwise never be executable, as an executable page in EPC. > > > > In the case a RWX page is needed, the calling process has to have a RWX > > page serving as the source for EADD so PROCESS__EXECMEM will have been > > checked. For SGX2, changing an EPC page to RWX is subject to FILE__EXECMEM > > on /dev/sgx/enclave, which I see as a security benefit because it only > > affects the enclave but not the whole process hosting it. > > So the permission would be like FILE__EXECMOD on the source enclave > page, because it would be mapped MAP_ANONYMOUS, PROT_WRITE? > MAP_SHARED, PROT_WRITE isn't going to work because that means you can > modify the file. Was this in response to Cedric's comment, or to my comment? > I'm starting to think that looking at the source VMA permission bits > or source PTE permission bits is putting a bit too much policy into > the driver as opposed to the LSM. How about delegating the whole > thing to an LSM hook? The EADD operation would invoke a new hook, > something like: > > int security_enclave_load_bytes(void *source_addr, struct > vm_area_struct *source_vma, loff_t source_offset, unsigned int > maxperm); > > Then you don't have to muck with mapping anything PROT_EXEC. Instead > you load from a mapping of a file and the LSM applies whatever policy > it feels appropriate. If the first pass gets something wrong, the > application or library authors can take it up with the SELinux folks > without breaking the whole ABI :) > > (I'm proposing passing in the source_vma because this hook would be > called with mmap_sem held for read to avoid a TOCTOU race.) > > If we go this route, the only substantial change to the existing > driver that's needed for an initial upstream merge is the maxperm > mechanism and whatever hopefully minimal API changes are needed to > allow users to conveniently set up the mappings. And we don't need to > worry about how to hack around mprotect() calling into the LSM, > because the LSM will actually be aware of SGX and can just do the > right thing. This doesn't address restricting which processes can run which enclaves, it only allows restricting the build flow. Or are you suggesting this be done in addition to whitelisting sigstructs? What's the value prop beyond whitelisting sigstructs? Realistically, I doubt LSMs/users will want to take the performance hit of scanning the source bytes every time an enclave is loaded. We could add seomthing like security_enclave_mprotect() in lieu of abusing security_file_mprotect(), but passing the full source bytes seems a bit much.