Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1119799yba; Wed, 15 May 2019 16:22:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqy12cX4+eBf0KTdFVJ4O0wmBqL1LWfapahT3mNlfm1i+7ElUQcETv7yq0aKm8D/uY4wYJa1 X-Received: by 2002:a65:478a:: with SMTP id e10mr47037215pgs.310.1557962561101; Wed, 15 May 2019 16:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557962561; cv=none; d=google.com; s=arc-20160816; b=1Cz7x7u0/8uuTJHZubgup/3AdOQoBl5jywsT/gdiVjJzfbK7SB330JkpRQ+zbicHRa Cw/pczWXn7KMGFXJULaqqwhORC3b3N3dvtFZhY+PvO+1KqdwNvreSbhaUbozUkpUHDt5 bQHpnav2j8SG/1Xc1pOb6E8IaUOQN1ecKW8QDztxI1XzwkiO6YSXqih3mDY8j8YX9PX1 Y2vxuE0vzdrOz40oe/0GQ2x3THPZ8l8MrC4LOiN8kKc/eSDCp+IuTJ1iOhKc73MPm29a gEyibks/MD99bSCYdAM4RU2T1c9OTv7/NoosT1caSa/Wa9hk8mfBqvGnde50vheYN/74 zCPA== 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=ELaRfC91fyXoCH++rqIf53wmSFUc4J0wZZE2kjNDYPw=; b=WkIlmYOzkl5MN7FpttyvhyRJfvN/qMdNQZLTjxax+2OmcKwlV6uoaZdxLEW0hIyiXM 89zTvI6AjAib1S7chB91sjWzathMLWRskZJwAa3LlWaSqVTWVxxeErz1UWAb2DkASDO+ EkXCRNydhSI06ses+eiif8PYuiXgx4FXhZtG3Sno8gzYklDxQARnfnAXCWU7RcsTB22r fMktK3JkfMsrR3Sb3/mbURD9GF+wQY/7Zmw7+XYb3yDDnZr+5vpCtRN3e65LnGpX106d kHPKW0ekE2WWnYczvYHFW0kksJo7soJSxdhNJTKIj71rxSXZW/GBZAFHjSe5RTxoJtXv 9A/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VbF8Ip5K; 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 d36si3097089pla.81.2019.05.15.16.22.16; Wed, 15 May 2019 16:22:41 -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=VbF8Ip5K; 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 S1726449AbfEOXNb (ORCPT + 99 others); Wed, 15 May 2019 19:13:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:41596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726389AbfEOXNa (ORCPT ); Wed, 15 May 2019 19:13:30 -0400 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 F04FE21773 for ; Wed, 15 May 2019 23:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557962009; bh=oXIRUhaHoitttMrIPB2rv0mrXlZVPITnJpfkP2WGxVA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VbF8Ip5K02eLqRuNtSS6WygUsSTTLfyAYn9NcN3u9GKSyhtm3+BN8zkh35/Dq8Ekl BLooL6ayE6/H0fEyV9VadrhQFqHsDyCMtDszV2imLL0hKb1Cba9BH4ZcIchASyFnVv uYGJFISNfE49xSl0pLPqhJzxWUFndnszyL6u0ULw= Received: by mail-wr1-f53.google.com with SMTP id l2so1214346wrb.9 for ; Wed, 15 May 2019 16:13:28 -0700 (PDT) X-Gm-Message-State: APjAAAWxJbfhZWSjkUYeYgr2VlnBYl/LpgF7g2HlZadDRAt9RkbgELTn ZEvZmr69MNlXRQ558Ai6oZIhIW0oKrw//EHkXwMDhw== X-Received: by 2002:adf:fb4a:: with SMTP id c10mr26918322wrs.309.1557962007443; Wed, 15 May 2019 16:13:27 -0700 (PDT) MIME-Version: 1.0 References: <8fe520bb-30bd-f246-a3d8-c5443e47a014@intel.com> <358e9b36-230f-eb18-efdb-b472be8438b4@fortanix.com> <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> In-Reply-To: From: Andy Lutomirski Date: Wed, 15 May 2019 16:13:15 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support) To: James Morris Cc: Andy Lutomirski , Sean Christopherson , "Serge E. Hallyn" , LSM List , Paul Moore , Stephen Smalley , Eric Paris , selinux@vger.kernel.org, Jarkko Sakkinen , 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 Wed, May 15, 2019 at 3:46 PM James Morris wrote: > > On Wed, 15 May 2019, Andy Lutomirski wrote: > > > > Why not just use an xattr, like security.sgx ? > > > > Wouldn't this make it so that only someone with CAP_MAC_ADMIN could > > install an enclave? I think that this decision should be left up the > > administrator, and it should be easy to set up a loose policy where > > anyone can load whatever enclave they want. That's what would happen > > in my proposal if there was no LSM loaded or of the LSM policy didn't > > restrict what .sigstruct files were acceptable. > > > > You could try user.sigstruct, which does not require any privs. > I don't think I understand your proposal. What file would this attribute be on? What would consume it? I'm imagining that there's some enclave in a file crypto_thingy.enclave. There's also a file crypto_thingy.sigstruct. crypto_thingy.enclave has type lib_t or similar so that it's executable. crypto_thingy.sigstruct has type sgx_sigstruct_t. The enclave loader does, in effect: void *source_data = mmap(crypto_thingy.enclave, PROT_READ | PROT_EXEC, ...); int sigstruct_fd = open("crypto_thingy.sigstruct", O_RDONLY); int enclave_fd = open("/dev/sgx/enclave", O_RDWR); ioctl(enclave_fd, SGX_IOC_ADD_SOME_DATA, source_data + source_offset, enclave_offset, len, ...); ioctl(enclave_fd, SGX_IOC_ADD_SOME_DATA, source_data + source_offset2, enclave_offset2, len, ...); etc. /* Here's where LSMs get to check that the sigstruct is acceptable. The CPU will check that the sigstruct matches the enclave. */ ioctl(enclave_fd, SGX_INIT_THE_ENCLAVE, sigstruct_fd); /* Actually map the thing */ mmap(enclave_fd RO section, PROT_READ, ...); mmap(enclave_fd RW section, PROT_READ | PROT_WRITE, ...); mmap(enclave_fd RX section, PROT_READ | PROT_EXEC, ...); /* This should fail unless EXECMOD is available, I think */ mmap(enclave_fd RWX section, PROT_READ | PROT_WRITE | PROT_EXEC); And the idea here is that, if the .enclave file isn't mapped PROT_EXEC, then mmapping the RX section will also require EXECMEM or EXECMOD.