Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1143370yba; Thu, 16 May 2019 15:17:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyb6QMZfM3L08hzjRqwCUjf+KHj+Dp8PACIvxIeUWoAcjtXuAnz7bwWVBxZVeUSVDgrcsF X-Received: by 2002:a63:c54d:: with SMTP id g13mr53323492pgd.376.1558045072028; Thu, 16 May 2019 15:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558045072; cv=none; d=google.com; s=arc-20160816; b=EaGmf/oneEZgxg+flVyMVTXV2PXwY+nklM+Uofs0naVpicg0j5+p3EIcgkVbVvJ3+F lu6gs4PjB6IxNOS0Of8+9AwPyaalZVzFFnJqs4JgjwkNs3qlPMGnHhxcGDkmSri8Kegx 7Kgtxt/S/4O4MsKxji5sQmxqk43Md8JeVOiglFVLHHlBy3iXMhvZnIJf1nHgH7rS/mVB k8Y6ylLEgGV1Ym8NZzCGExaFZ+YOftkD+QRFwULSNP/Vp7bbzu8yD3RbBVjUcg0Gq+uq asSiI6BB329k3HC5eteE/YADOZkYBcCkD1vCcRanPxQPhCCKra9a92GDWegVdew9Arbo xExA== 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=rqHezYL7PLE8fRNMfr3UwxTbDzfmjEU4eyD6kxWYvn0=; b=yKELc/uB55dWQQmScs8DwaTPXk+8G7fldJwc+QSLHbXmfKeEEQQdkUBB6lL6bgz/sE vhRKIdtfDvrMEar4aY1uGSMc2No4eTbixPfQFdQyie5GczckQaOCDgIFimB8K6BHKWY/ zw+UMUUUC7SULIfG0aQz7dlbpk1Zt75mZ9xMz5Fb+djADl2KjBlEo9MDrpHifGxFzWCt pPebLzjB1bkYjf2q3fjoUwmR2D3o82SDtvbfv4oIy4ll+rRI2ARkI/iNKXNmyIkUhdeD GbhQlx10ENR1pNGKuyzaTxTxUfGjEgsgnW2ToSg7PD/Iy/MM+QuPXtJki7wx1ttaRRoq 2czg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Qn7kjHIp; 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 25si6101249pgs.239.2019.05.16.15.17.35; Thu, 16 May 2019 15:17:52 -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=Qn7kjHIp; 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 S1728209AbfEPVDN (ORCPT + 99 others); Thu, 16 May 2019 17:03:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:52690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbfEPVDN (ORCPT ); Thu, 16 May 2019 17:03:13 -0400 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 45CF620848 for ; Thu, 16 May 2019 21:03:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558040591; bh=NO9G06JDTnmk7v8QHSnoMAUvRcyj/9lnX0RTiqK+xcY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Qn7kjHIprHMIS5LUTr8DlWiUs+osDXQecSfgGM4n7WqcqzpD718QXoaxS8kRobOec p7pxTTETmQDT/VHTsiOwVaDRH2dnZiltdz2QtPSWvKSkZwTjDoDEPK75R1gibc/AGc qn6Sby9LWJHIyRlmObLu5cGyHe1fDjUOzWX+Ka3A= Received: by mail-wr1-f48.google.com with SMTP id h4so4861581wre.7 for ; Thu, 16 May 2019 14:03:11 -0700 (PDT) X-Gm-Message-State: APjAAAXEsJSTJhXRehb6VRP0KgfLBn5ogR1l7LUbHt7yeaxwXSlBe//b 9BWEU0uQ+cg+jlVoO5X4SyOhUPugHyYuFeaKu7/jSA== X-Received: by 2002:a5d:45c7:: with SMTP id b7mr9091972wrs.176.1558040589844; Thu, 16 May 2019 14:03:09 -0700 (PDT) MIME-Version: 1.0 References: <960B34DE67B9E140824F1DCDEC400C0F4E886094@ORSMSX116.amr.corp.intel.com> <6da269d8-7ebb-4177-b6a7-50cc5b435cf4@fortanix.com> <20190513102926.GD8743@linux.intel.com> <20190514104323.GA7591@linux.intel.com> <20190514204527.GC1977@linux.intel.com> <20190515013031.GF1977@linux.intel.com> <20190516051622.GC6388@linux.intel.com> In-Reply-To: <20190516051622.GC6388@linux.intel.com> From: Andy Lutomirski Date: Thu, 16 May 2019 14:02:58 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support) To: Jarkko Sakkinen Cc: Andy Lutomirski , Sean Christopherson , James Morris , "Serge E. Hallyn" , LSM List , Paul Moore , Stephen Smalley , Eric Paris , selinux@vger.kernel.org, Jethro Beekman , "Xing, Cedric" , "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 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 May 15, 2019, at 10:16 PM, Jarkko Sakkinen wrote: > >> On Wed, May 15, 2019 at 11:27:04AM -0700, Andy Lutomirski wrote: >> Hi, LSM and SELinux people- >> >> We're trying to figure out how SGX fits in with LSMs. For background, >> an SGX library is functionally a bit like a DSO, except that it's >> nominally resistant to attack from outside and the process of loading >> it is complicated. To load an enclave, a program can open >> /dev/sgx/enclave, do some ioctls to load the code and data segments >> into the enclave, call a special ioctl to "initialize" the enclave, >> and then call into the enclave (using special CPU instructions). >> >> One nastiness is that there is not actually a universally agreed upon, >> documented file format for enclaves. Windows has an undocumented >> format, and there are probably a few others out there. No one really >> wants to teach the kernel to parse enclave files. >> >> There are two issues with how this interacts with LSMs: >> >> 1) LSMs might want to be able to whitelist, blacklist, or otherwise >> restrict what enclaves can run at all. The current proposal that >> everyone seems to dislike the least is to have a .sigstruct file on >> disk that contains a hash and signature of the enclave in a >> CPU-defined format. To initialize an enclave, a program will pass an >> fd to this file, and a new LSM hook can be called to allow or disallow >> the operation. In a SELinux context, the idea is that policy could >> require the .sigstruct file to be labeled with a type like >> sgx_sigstruct_t, and only enclaves that have a matching .sigstruct >> with such a label could run. > > Similarly if we could take data for the enclave from fd and enforce > it with sgx_enclave_t label. That certainly *could* be done, and I guess the decision could be left to the LSMs, but I'm not convinced this adds value. What security use case does this cover that isn't already covered by requiring EXECUTE (e.g. lib_t) on the enclave file and some new SIGSTRUCT right on the .sigstruct? > >> 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. > > With the fd based model for source I'd mark SECINFO.W pages as unsafe > to execute and then check unsafe bit before applying lets say EMODT > or EMODPR. > > There is a problem here though. Usually the enclave itself is just a > loader that then loads the application from outside source and creates > the executable pages from the content. > > A great example of this is Graphene that bootstraps unmodified Linux > applications to an enclave: > > https://github.com/oscarlab/graphene > ISTM you should need EXECMEM or similar to run Graphene, then.