Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3401306ybi; Mon, 10 Jun 2019 09:37:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8Uw+I1qH4etys/7hagrQK+VbHDOxxwi/Qcxzs168c6r26snweuJa95LSRAqpACjsZUJLC X-Received: by 2002:a62:e511:: with SMTP id n17mr67638627pff.181.1560184647287; Mon, 10 Jun 2019 09:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560184647; cv=none; d=google.com; s=arc-20160816; b=km+78fhroF6yL1nOkhU5exiT8imhQKtaxKXeV2SVsLGzl7SfTQqSVKhr8u1dU0epgC gP65OY4G+N4W9q4/1caTRMKGfBHiNl5ssuXphQx/FcsAZ470zPQv/nlQVgsx233nK5LK tsKfZjjvNcwRpTgAaEZ3MOZfduhtR/WaIKJTxR3AYOjeaaCRHqKX5A6Rxg08pCHvFXNG itLYQKAjdrV9AEb05W9+sq3MLKMY3cdSqbzAiI1k0Afi6j3sKcxh+wwSGJHPfomiRDlN FxLo892Y4Az8YtZtSF1T5wa0Xfq2uf/JLdcyR1TPbxBXy1BfeAfQZCtoRpjbRXPH0Z01 hdkQ== 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=2uhZnIJQ/Mef1zV8kvt8luv1Pd076/d6ycUIR0xDAwQ=; b=unxJajMJV4iDvHIwnM9L2JyBWEIZcLOodM0K4dwNPlNeLJxotJaEwrFyx8Wuo9td7V VBFlz72KKRmt6nXS/D/Swymq9K05/WjeYmJBjWF1GwCgBBZ2jWViKj19cOnGSZ0Jfrjh 7uagbXuwpmeVesgDw8QYXv4Z3xfSX9oZV6IGpCETJMJsulxabd3NGGjq+1tLiJxKIScR Nl9+NpKD76USmWvoO0zGmTWeIBgA9Ja32DCXjtnST0MMEk8d+zAM2EFRZ7LfRAGiuF2s IMWmX/P8J7lVAy8wXQh2uRKlyDM67qkiXCyJnDms/n9Ml57WWNnAruaLSoDrd8xKscxS Bstg== 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 gb4si10323841plb.429.2019.06.10.09.37.12; Mon, 10 Jun 2019 09:37:27 -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 S2404056AbfFJP4B (ORCPT + 99 others); Mon, 10 Jun 2019 11:56:01 -0400 Received: from mga12.intel.com ([192.55.52.136]:5731 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404020AbfFJPzu (ORCPT ); Mon, 10 Jun 2019 11:55:50 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jun 2019 08:55:49 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by orsmga004.jf.intel.com with ESMTP; 10 Jun 2019 08:55:49 -0700 Date: Mon, 10 Jun 2019 08:55:49 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: Andy Lutomirski , Cedric Xing , Stephen Smalley , James Morris , "Serge E . Hallyn" , LSM List , Paul Moore , Eric Paris , selinux@vger.kernel.org, Jethro Beekman , Dave Hansen , Thomas Gleixner , Linus Torvalds , LKML , X86 ML , linux-sgx@vger.kernel.org, Andrew Morton , nhorman@redhat.com, npmccallum@redhat.com, Serge Ayoun , Shay Katz-zamir , Haitao Huang , Andy Shevchenko , Kai Svahn , Borislav Petkov , Josh Triplett , Kai Huang , David Rientjes , William Roberts , Philip Tricca Subject: Re: [RFC PATCH v2 1/5] mm: Introduce vm_ops->may_mprotect() Message-ID: <20190610155549.GB15995@linux.intel.com> References: <20190606021145.12604-1-sean.j.christopherson@intel.com> <20190606021145.12604-2-sean.j.christopherson@intel.com> <20190610150600.GA3752@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190610150600.GA3752@linux.intel.com> 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 Mon, Jun 10, 2019 at 06:06:00PM +0300, Jarkko Sakkinen wrote: > On Wed, Jun 05, 2019 at 07:11:41PM -0700, Sean Christopherson wrote: > > SGX will use the may_mprotect() hook to prevent userspace from > > circumventing various security checks, e.g. Linux Security Modules. > > Naming it may_mprotect() instead of simply mprotect() is intended to > > reflect the hook's purpose as a way to gate mprotect() as opposed to > > a wholesale replacement. > > "This commit adds may_mprotect() to struct vm_operations_struct, which > can be used to ask from the owner of a VMA if mprotect() is allowed." > > This would be more appropriate statement because that is what the code > change aims for precisely. I did not even understand what you meant by > gating in this context. I would leave SGX and LSM's (and especially > "various security checks", which means abssolutely nothing) out of the > first paragraph completely. > > > Enclaves are built by copying data from normal memory into the Enclave > > Page Cache (EPC). Due to the nature of SGX, the EPC is represented by a > > single file that must be MAP_SHARED, i.e. mprotect() only ever sees a > > MAP_SHARED vm_file that references single file path. Furthermore, all > > enclaves will need read, write and execute pages in the EPC. > > I would just say that "Due to the fact that EPC is delivered as IO > memory from the preboot firmware, it can be only mapped as MAP_SHARED". > It is what it is. I was trying to convey that the nature of SGX itself requires that an enclave's pages are shared between process. E.g. {MAP,VM}_SHARED would be required even if we modified the mmu to handle EPC memory in such a way that it didn't have to be tagged with VM_PFNMAP. > > As a result, LSM policies cannot be meaningfully applied, e.g. an LSM > > can deny access to the EPC as a whole, but can't deny PROT_EXEC on page > > that originated in a non-EXECUTE file (which is long gone by the time > > mprotect() is called). > > I have hard time following what is paragraph is trying to say. > > > By hooking mprotect(), SGX can make explicit LSM upcalls while an > > enclave is being built, i.e. when the kernel has a handle to origin of > > each enclave page, and enforce the result of the LSM policy whenever > > userspace maps the enclave page in the future. > > "LSM policy whenever calls mprotect()"? I'm no sure why you mean by > mapping here and if there is any need to talk about future. Isn't this > needed now? Future is referring to the timeline of a running kernel, not the future of the kernel code. Rather than trying to explain all of the above with words, I'll provide code examples to show how ->may_protect() will be used by SGX and why it is the preferred solution. > > Alternatively, SGX could play games with MAY_{READ,WRITE,EXEC}, but > > that approach is quite ugly, e.g. would require userspace to call an > > SGX ioctl() prior to using mprotect() to extend a page's protections. > > Instead of talking "playing games" I would state what could be done with > VM_MAY{READ,WRITE,EXEC} and why it is bad. Leaves questions otherwise. > > > Signed-off-by: Sean Christopherson > > --- > > include/linux/mm.h | 2 ++ > > mm/mprotect.c | 15 +++++++++++---- > > 2 files changed, 13 insertions(+), 4 deletions(-) > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index 0e8834ac32b7..a697996040ac 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -458,6 +458,8 @@ struct vm_operations_struct { > > void (*close)(struct vm_area_struct * area); > > int (*split)(struct vm_area_struct * area, unsigned long addr); > > int (*mremap)(struct vm_area_struct * area); > > + int (*may_mprotect)(struct vm_area_struct * area, unsigned long start, > > + unsigned long end, unsigned long prot); > > Could be just boolean. > > /Jarkko