Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6790036yba; Tue, 14 May 2019 13:47:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoSJbX7dJABtya4Qij2M6l3qo99wgj4n9+HlXivQ+FO0sb5nv1Jj7+pMVlcXVTZU8c/SqF X-Received: by 2002:a63:3182:: with SMTP id x124mr39142921pgx.364.1557866859199; Tue, 14 May 2019 13:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557866859; cv=none; d=google.com; s=arc-20160816; b=0Tt9KqdMY1DDgls5plhRMs1PF3zfzFOCx1oB9niIjyMgivB6AfUTBI7DeK4+5v/fx5 D/2eMTThayG/J8V2afkVO7HCSH4Lrllfi3fDzAXae05v1U7ztTXpzzqAaVoGjULJd7eh xJAgxdvDxvEcxSlrCCHIyO0udryWJeWi0012I3Rl8GHBhqXGXrqTUj9/dcjIQYDFnpUE /aohBeg7UQ/ijP9f8v6gFqlnjZqj3/C+HTF0gNl/FEndCFhZnjcEn4pbvG8y838czfXR vGJYsMhoL779OWQi5gDvlkP1lfgAHvyVDmby0TJciZnmBdX2D9vxy5oM67prJ6kGXcoa Re4w== 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=ZZFXW+doSzvZnuLSzVRK2BS/4IQ2J6TBFru4H7yLedc=; b=Bc5GkhwHXuUibvjy9IgcEUOePR/Hx2dryJTFjF9b7ThDoz5X9FaQXuGHKypgyU8ZWV +Jp0II+JJAajqNXCShQZD8VwXVWvdjfQ0YJ9LR8d25CR951xW3pczFCtpaBo7PP/pwlC Vy2mXNDtd0LDYG9i99OKWiEPANqeTbaGNahRjDRLPiO9ImN+e8Bdcig4JtCJksHHTG9n T6WQILop5EDCs6qV4yAKYAgzhS1KQ32LcdLoogALpgggqyHa6Njh8Q4zmxG0QHAVTqRw dAzZmY6dbKq5E0DkE1I6yFrKae3dR6haqwg5elQFEJTmEp2liCV5G/YjXX0cjuVNSGW/ DUhg== 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 j10si21457906pgh.273.2019.05.14.13.47.23; Tue, 14 May 2019 13:47:39 -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 S1726533AbfENUpa (ORCPT + 99 others); Tue, 14 May 2019 16:45:30 -0400 Received: from mga06.intel.com ([134.134.136.31]:19237 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfENUpa (ORCPT ); Tue, 14 May 2019 16:45:30 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2019 13:45:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,470,1549958400"; d="scan'208";a="171727087" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by fmsmga002.fm.intel.com with ESMTP; 14 May 2019 13:45:27 -0700 Date: Tue, 14 May 2019 13:45:27 -0700 From: Sean Christopherson To: Andy Lutomirski Cc: 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 Subject: Re: [PATCH v20 00/28] Intel SGX1 support Message-ID: <20190514204527.GC1977@linux.intel.com> References: <960B34DE67B9E140824F1DCDEC400C0F4E885F9D@ORSMSX116.amr.corp.intel.com> <979615a8-fd03-e3fd-fbdb-65c1e51afd93@fortanix.com> <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> 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 Tue, May 14, 2019 at 08:13:36AM -0700, Andy Lutomirski wrote: > On Tue, May 14, 2019 at 3:43 AM Jarkko Sakkinen > wrote: > > > > On Mon, May 13, 2019 at 01:29:26PM +0300, Jarkko Sakkinen wrote: > > > I did study through SDK's file format and realized that it does not > > > does make sense after all to embed one. > > > > > > To implement it properly you would probably need a new syscall (lets say > > > sgx_load_enclave) and also that enclaves are not just executables > > > binaries. It is hard to find a generic format for them as applications > > > range from simply protecting part of an application to running a > > > containter inside enclave. > > > > I'm still puzzling what kind of changes you were discussing considering > > SGX_IOC_ENCLAVE_ADD_PAGE. > > I think it's as simple as requiring that, if SECINFO.X is set, then > the src pointer points to the appropriate number of bytes of > executable memory. (Unless there's some way for an enclave to change > SECINFO after the fact -- is there?) Nit: SECINFO is just the struct passed to EADD, I think what you're really asking is "can the EPCM permissions be changed after the fact". And the answer is, yes. On SGX2 hardware, the enclave can extend the EPCM permissions at runtime via ENCLU[EMODPE], e.g. to make a page writable. Hardware also doesn't prevent doing EADD to the same virtual address multiple times, e.g. an enclave could EADD a RX page, and then EADD a RW page at the same virtual address with different data. The second EADD will affect MRENCLAVE, but so long as it's accounted for by the enclave's signer, it's "legal". SGX_IOC_ENCLAVE_ADD_PAGE *does* prevent adding the "same" page to an enclave multiple times, so effectively this scenario is blocked by the current implementation, but it's more of a side effect (of a sane implementation) as opposed to deliberately preventing shenanigans. Regarding EMODPE, the kernel doesn't rely on EPCM permissions in any way shape or form (the EPCM permissions are purely to protect the enclave from the kernel), e.g. adding +X to a page in the EPCM doesn't magically change the kernel's page tables and attempting to execute from the page will still generate a (non-SGX) #PF. So rather than check SECINFO.X, I think we'd want to have EADD check that the permissions in SECINFO are a subset of the VMA's perms (IIUC, this is essentially what Cedric proposed). That would prevent using EMODPE to gain executable permissions, and would explicitly deny the scenario of a double EADD to load non-executable data into an executable page. Oh, and EADD should probably also require EEXTEND for executable pages. > Sadly, we don't really have the a nice in-kernel API for that right now. > You could do down_read(mmap_sem) and find_vma(). Arguably there is no > value to checking that PKRU allows execute to the data. > > Hey, Dave, if you're still paying attention to this thread, should we > have copy_from_user_exec() that does the right thing wrt the page > permissions and PKRU.