Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6438773yba; Tue, 14 May 2019 07:35:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxw+6+J2IaWZoaMfwshXXkmwmVITF3kaGxe07IKfyfueGBgy2ldCnAR1+5L+kM6yYkwioL X-Received: by 2002:a17:902:7d8a:: with SMTP id a10mr17694328plm.63.1557844521593; Tue, 14 May 2019 07:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557844521; cv=none; d=google.com; s=arc-20160816; b=RrzC4m9pTOpZXqski+e8TFFoOOP7QI1tsyNiiK+HToX3tXkyihKfpjIAy0tRFAnl4a tQrP4BpkpQNlUKQFmdeRAsTsfqMy6tydokNmgWNoQB7amzGZUqxU9aFN6s0OykbEGFNU WfwKcwPwOcrCwtBCdFxdf2E7m8UvYqMKZMgiTfJu8fTHTMAd1JVRMG3CTBUd03gdmGYE K1POkqY62OtjTSXNV3PfBuC5RWrPtzLv09AXyjWHm4UH87RwesbNiPcGII4Zr5X+h78I 0dANXC/cvPN066cTcxfcD/KG7TU+YphOZiu62hbRYqzdli4C0FhqtobKcfpg0LBKNQUE bmLg== 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:message-id :organization:from:content-transfer-encoding:mime-version:date :references:reply-to:subject:cc:to; bh=Pg4CytNxAxImr94nM+T6zD37qdY6NGVvnTpDwqTkfZ8=; b=Svcp1fN8l6yJ9seHNamcd+iRdpU/dTSPhAajaACMvfM4zzfFr2nWp2TwhCucM82HkV AaPmkl3RFCHASesGEllYMfrD1gl2DK+3WFZ12ycnVHW1SqvJIsEjj3bDSH8HpiWCPspZ GKPTutGq2SJDt+dna0k7111nEif3oytvLuKKpisp9R1yM0VlYz9MfI3nfP6uz0wZvW6/ mgqSi+VQXk6CPAjM1ivDL35nn0AADS0FImWvaoMWdwdRT+lxh3DrR4ckqu4F31TXXUfR Gl7ULVQYfUpTilUfys0gd3i1V92v7TijbLF8cy9IP6idbicikHFE6ifONc6Pxb7qjHv1 GffQ== 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 g10si13585565pgj.275.2019.05.14.07.35.05; Tue, 14 May 2019 07:35:21 -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 S1726190AbfENOd7 (ORCPT + 99 others); Tue, 14 May 2019 10:33:59 -0400 Received: from mga18.intel.com ([134.134.136.126]:51147 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfENOd7 (ORCPT ); Tue, 14 May 2019 10:33:59 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2019 07:33:57 -0700 X-ExtLoop1: 1 Received: from hhuan26-mobl.amr.corp.intel.com ([10.255.33.85]) by orsmga008.jf.intel.com with ESMTP; 14 May 2019 07:33:52 -0700 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: "Jethro Beekman" , "Andy Lutomirski" Cc: "Xing, Cedric" , "Hansen, Dave" , "Thomas Gleixner" , "Dr. Greg" , "Jarkko Sakkinen" , "Linus Torvalds" , LKML , "X86 ML" , "linux-sgx@vger.kernel.org" , "Andrew Morton" , "Christopherson, Sean J" , "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 Reply-To: haitao.huang@linux.intel.com References: <20190417103938.7762-1-jarkko.sakkinen@linux.intel.com> <8c5133bc-1301-24ca-418d-7151a6eac0e2@fortanix.com> <2AE80EA3-799E-4808-BBE4-3872F425BCF8@amacapital.net> <49b28ca1-6e66-87d9-2202-84c58f13fb99@fortanix.com> <444537E3-4156-41FB-83CA-57C5B660523F@amacapital.net> <5854e66a-950e-1b12-5393-d9cdd15367dc@fortanix.com> <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> Date: Tue, 14 May 2019 09:33:51 -0500 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Haitao Huang" Organization: Intel Message-ID: In-Reply-To: User-Agent: Opera Mail/1.0 (Win32) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 10 May 2019 14:22:34 -0500, Andy Lutomirski wrote: > On Fri, May 10, 2019 at 12:04 PM Jethro Beekman > wrote: >> >> On 2019-05-10 11:56, Xing, Cedric wrote: >> > Hi Jethro, >> > >> >> ELF files are explicitly designed such that you can map them (with >> mmap) >> >> in 4096-byte chunks. However, sometimes there's overlap and you will >> >> sometimes see that a particular offset is mapped twice because the >> first >> >> half of the page in the file belongs to an RX range and the second >> half >> >> to an R-only range. Also, ELF files don't (normally) describe stack, >> >> heap, etc. which you do need for enclaves. >> > >> > You have probably misread my email. By mmap(), I meant the enclave >> file would be mapped via *multiple* mmap() calls, in the same way as >> what dlopen() would do in loading regular shared object. The intention >> here is to make the enclave file subject to the same checks as regular >> shared objects. >> >> No, I didn't misread your email. My original point still stands: >> requiring that an enclave's memory is created from one or more mmap >> calls of a file puts significant restrictions on the enclave's on-disk >> representation. >> > > For a tiny bit of background, Linux (AFAIK*) makes no effort to ensure > the complete integrity of DSOs. What Linux *does* do (if so > configured) is to make sure that only approved data is mapped > executable. So, if you want to have some bytes be executable, those > bytes have to come from a file that passes the relevant LSM and IMA > checks. Given this, I just want to step back a little to understand the exact issue that SGX is causing here for LSM/IMA. Sorry if I missed points discussed earlier. By the time of EADD, enclave file is opened and should have passed IMA and SELinux policy enforcement gates if any. We really don't need extra mmaps on the enclave files to be IMA and SELinux compliant. We are loading enclave files as RO and copying those into EPC. An IMA policy can enforce RO files (or any file). And SELinux policy can say which processes can open the file for what permissions. No extra needed here. And sgx enclaves are always signed and integrity protected and verified at the time of EINIT. So if EINIT passes, we know the content loaded (including permission flags) is matching the sigstruct. But sigstruct/signature is part of the file, should be accounted for in IMA measurement of the whole file, so it is also verified by IMA during file open, right? The only potential gap/difference comparing to regular ELF executable or DSOs:for enclaves, we need mmap portions of enclave linear range with RW to do EADD IOC, then mprotect those pages to RX after EINIT. But this is operated on enclave fd provided by driver. So we can have an SELinux policy say: only this type of processes is allowed to open enclave fd, and allowed to do mmap/mprotect with read, write, execute on it. Wouldn't that be enough? Thanks Haitao