Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3836691pxk; Tue, 29 Sep 2020 07:29:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2Iw7KrJHBqrAOACgj2HOjIxm6SQ+eC0TsWM/cM5qHR5FIGTpbxgII0OGCn6JY91RZnrTV X-Received: by 2002:a17:906:d936:: with SMTP id rn22mr4284073ejb.4.1601389745030; Tue, 29 Sep 2020 07:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601389745; cv=none; d=google.com; s=arc-20160816; b=Cmq8SI0J7oK3WWDtVriBMDZlKYJsK69Q9cqj86Srr3eC4Fzc5x34Ys2ZBrKJwf7IpJ TvEWSKfbtNoxPmr++l8Fijs0CAH1LiHXEPDLLYjinzlaPYGpiKvAzIUxM4ABxOSC+W4C Gzb3ijJbH30cnbdv+zjY+7aR6H3BAYpd72gUmICXUb0e9SSwuSnewX/f6eEHYG2AM/cr XMHFVGmue9h40gVmVGcL7ed1WdimD47/B8ZcRj3qp9AzlqYctqs1Hs+krB/tiP2KfyVS cHTOwJqi3H2vcrzOYnerHrCFxlnNanom4XF7kB9T8cdDWeQTJJVuZ760au8jeKoRspzQ uMOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:autocrypt:from :references:cc:to:subject:ironport-sdr:ironport-sdr; bh=QqmuveJrTCfd46WkacBsGz+TyhhRbgscIfFt8rz4G6A=; b=UyEaRB7QIMgmtinQxxgwbmPyc0Fbd/GE8sRG7hvK8lLjnB1ERNr4VDu6PHW5fRtALS pGpitGHCxjfGhHDeJYRbaPM6PanMOOQ9+RC9Z2OpkL5o1xU1233YrCJ7kI64ilTIsI8g XTGnBJBfc7DtiHuxgbjXjMk/qhTfLtaPR+ydbJOCXpd7fel0vQxKpltF2KrymsKP92C9 3ZnxuLDC4iSB5+KSiu0AziqLfO53D48wfgRqnolI0qNBx1+6nPwNx5zvmGY6RdxUb2Ca S2ikzOqhhQwREwEDRzZgpQijMXWMvV38Vvi+ecqAbuJpyxbHtcEQtxAgc+sb2/np0zKB sl0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id o18si2935696ejg.313.2020.09.29.07.28.40; Tue, 29 Sep 2020 07:29:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728944AbgI2OY1 (ORCPT + 99 others); Tue, 29 Sep 2020 10:24:27 -0400 Received: from mga05.intel.com ([192.55.52.43]:50898 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728696AbgI2OY0 (ORCPT ); Tue, 29 Sep 2020 10:24:26 -0400 IronPort-SDR: C8Tm5MyfGSFG/SHq9HSQbfBflSJ5MxDgZ0Js9KKYY0TAOuUgPZAO2fJTy8MrcUaMIdd8a46/UP 4BBvHa6a7Kug== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="246933757" X-IronPort-AV: E=Sophos;i="5.77,318,1596524400"; d="scan'208";a="246933757" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2020 07:24:26 -0700 IronPort-SDR: bsz4KTLlJ0AoLUD9EJWic3WY2MGKrHtWC4/SLXSwPr4s3AlMNrWtWghfWqJmaRiyxFGGeXfkp1 h27me8bmOhRA== X-IronPort-AV: E=Sophos;i="5.77,318,1596524400"; d="scan'208";a="324687376" Received: from balumahx-mobl.amr.corp.intel.com (HELO [10.212.138.118]) ([10.212.138.118]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2020 07:24:24 -0700 Subject: Re: [PATCH v38 10/24] mm: Add vm_ops->mprotect() To: Jarkko Sakkinen , Andy Lutomirski Cc: Sean Christopherson , Haitao Huang , Andy Lutomirski , X86 ML , linux-sgx@vger.kernel.org, LKML , Linux-MM , Andrew Morton , Matthew Wilcox , Jethro Beekman , Darren Kenny , Andy Shevchenko , asapek@google.com, Borislav Petkov , "Xing, Cedric" , chenalexchen@google.com, Conrad Parker , cyhanish@google.com, "Huang, Haitao" , Josh Triplett , "Huang, Kai" , "Svahn, Kai" , Keith Moyer , Christian Ludloff , Neil Horman , Nathaniel McCallum , Patrick Uiterwijk , David Rientjes , Thomas Gleixner , yaozhangx@google.com References: <20200928201959.GA3856@linux.intel.com> <20200929040521.GC301037@linux.intel.com> From: Dave Hansen Autocrypt: addr=dave.hansen@intel.com; keydata= xsFNBE6HMP0BEADIMA3XYkQfF3dwHlj58Yjsc4E5y5G67cfbt8dvaUq2fx1lR0K9h1bOI6fC oAiUXvGAOxPDsB/P6UEOISPpLl5IuYsSwAeZGkdQ5g6m1xq7AlDJQZddhr/1DC/nMVa/2BoY 2UnKuZuSBu7lgOE193+7Uks3416N2hTkyKUSNkduyoZ9F5twiBhxPJwPtn/wnch6n5RsoXsb ygOEDxLEsSk/7eyFycjE+btUtAWZtx+HseyaGfqkZK0Z9bT1lsaHecmB203xShwCPT49Blxz VOab8668QpaEOdLGhtvrVYVK7x4skyT3nGWcgDCl5/Vp3TWA4K+Iofw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dpWrCJ1E3m/RIlXy/2Y3YOVVohfSy+4kvvYU3 lXUdPb04UPw4VWwjcVZPg7cgR7Izion61bGHqVqURgSALt2yvHl7cr68NYoFkzbNsGsye9ft M9ozM23JSgMkRylPSXTeh5JIK9pz2+etco3AfLCKtaRVysjvpysukmWMTrx8QnI5Nn5MOlJj 1Ov4/50JY9pXzgIDVSrgy6LYSMc4vKZ3QfCY7ipLRORyalFDF3j5AGCMRENJjHPD6O7bl3Xo 4DzMID+8eucbXxKiNEbs21IqBZbbKdY1GkcEGTE7AnkA3Y6YB7I/j9mQ3hCgm5muJuhM/2Fr OPsw5tV/LmQ5GXH0JQ/TZXWygyRFyyI2FqNTx4WHqUn3yFj8rwTAU1tluRUYyeLy0ayUlKBH ybj0N71vWO936MqP6haFERzuPAIpxj2ezwu0xb1GjTk4ynna6h5GjnKgdfOWoRtoWndMZxbA z5cecg== Message-ID: <1b1bd1f8-210d-486a-b038-2d6eea9d35cd@intel.com> Date: Tue, 29 Sep 2020 07:24:24 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200929040521.GC301037@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/28/20 9:05 PM, Jarkko Sakkinen wrote: > On Mon, Sep 28, 2020 at 06:37:54PM -0700, Andy Lutomirski wrote: >> I don’t personally care that much about EMODPE but, you could probably >> get the point across with something like: >> >> SGX’s EPCM permission bits do not obviate the need to enforce these >> rules in the PTEs because enclaves can freely modify the EPCM >> permissions using EMODPE. >> >> IOW, EMODPE is not really special here; rather, EMODPE’s existence >> demonstrates that EADD / EEXTEND are not special. > > So I did "disagree and commit" with this one. I'm not actually > diagreeing on anything what Dave wrote, on the contrary it is an > understandable high level description. I just thought that it would not > hurt to remark that the ISA contains such peculiarities as EMODPE. > > I did only very rudimentary clean up for the text (e.g. fix the ioctl > name, add shortt summary and not much else). > > Does not make sense to waste more time to this. I'll move on to > implement the missing boot time patching for the vDSO so that we > get the next version out. > > " > mm: Add 'mprotect' hook to struct vm_operations_struct > > Background > ========== > > 1. SGX enclave pages are populated with data by copying data to them > from normal memory via ioctl(fd, SGX_IOC_ENCLAVE_ADD_PAGES). > 2. We want to be able to restrict those normal memory data sources. For > instance, before copying data to an executable enclave page, we might > ensure that the source is executable. I know I wrote that. I suck, and I wrote it in a changelog-unacceptable way. Folks dislike the use of "we" in these things. Here's a better version: 2. It is desirable to be able to restrict those normal memory data sources. For instance, the kernel can ensure that the source is executable, before copying data to an executable enclave page. > 3. Enclave page permissions are dynamic just like normal permissions and > can be adjusted at runtime with mprotect() (along with a > corresponding special instruction inside the enclave). > 4. The original data source may have have long since vanished at the > time when enclave page permission are established (mmap() or > mprotect()). > > Solution > ======== > > The solution is to force enclaves creators to declare their intent up front > to ioctl(fd, SGX_IOC_ENCLAVE_ADD_PAGES). This intent can me immediately > compared to the source data mapping (and rejected if necessary). It is > also stashed off and then later compared with enclave PTEs to ensure that > any future mmap()/mprotect() operations performed by the enclave creator or > the enclave itself are consistent with the earlier declared permissions. Let's also say "... or *requested* by the enclave itself ...", since the enclave itself can't directly make syscalls. > Essentially, this means that whenever the kernel is asked to change an > enclave PTE, it needs to ensure the change is consistent with that stashed > intent. There is an existing vm_ops->mmap() hook which allows SGX to do > that for mmap(). However, there is no ->mprotect() hook. Add a > vm_ops->mprotect() hook so that mprotect() operations which are > inconsistent with any page's stashed intent can be rejected by the driver. > > Implications > ============ > > However, there is currently no implementation of the intent checks at the > time of ioctl(fd, SGX_IOC_ENCLAVE_ADD_PAGES). That means that the intent > argument (SGX_PROT_*) is currently unused. This was incorrect to say. Sean corrected me on this point. Could you look through the thread and incorporate that?