From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4080C4346E for ; Tue, 29 Sep 2020 04:05:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4994920BED for ; Tue, 29 Sep 2020 04:05:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4994920BED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 83AC38E0001; Tue, 29 Sep 2020 00:05:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C4306B005D; Tue, 29 Sep 2020 00:05:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68B3E8E0001; Tue, 29 Sep 2020 00:05:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 4EDFE6B005C for ; Tue, 29 Sep 2020 00:05:37 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 08963181AE861 for ; Tue, 29 Sep 2020 04:05:37 +0000 (UTC) X-FDA: 77314759914.11.sack00_27062b127187 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id D6D42180F8B82 for ; Tue, 29 Sep 2020 04:05:36 +0000 (UTC) X-HE-Tag: sack00_27062b127187 X-Filterd-Recvd-Size: 5790 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Sep 2020 04:05:35 +0000 (UTC) IronPort-SDR: qSsbWgsDl9nyewHpIxzb+Ldbeyt1jtmIJ+QySptJkyPq5UKDXp1vv/gBTGVHjg1DyQ1TveiYhs hnD/3ySMBCjw== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="159487867" X-IronPort-AV: E=Sophos;i="5.77,316,1596524400"; d="scan'208";a="159487867" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 21:05:33 -0700 IronPort-SDR: iZSKmayZEHDcJLbGgcE5jfe9paSA/H1Upti0oBr800nlSWuQn/BTiylluBMqvQvdcz5VB7SHbZ IA++IStvfudg== X-IronPort-AV: E=Sophos;i="5.77,317,1596524400"; d="scan'208";a="488909080" Received: from jlasecki-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.49.78]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 21:05:25 -0700 Date: Tue, 29 Sep 2020 07:05:21 +0300 From: Jarkko Sakkinen To: Andy Lutomirski Cc: Dave Hansen , 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 Subject: Re: [PATCH v38 10/24] mm: Add vm_ops->mprotect() Message-ID: <20200929040521.GC301037@linux.intel.com> References: <20200928201959.GA3856@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Sep 28, 2020 at 06:37:54PM -0700, Andy Lutomirski wrote: > I don=E2=80=99t personally care that much about EMODPE but, you could p= robably > get the point across with something like: >=20 > SGX=E2=80=99s EPCM permission bits do not obviate the need to enforce t= hese > rules in the PTEs because enclaves can freely modify the EPCM > permissions using EMODPE. >=20 > IOW, EMODPE is not really special here; rather, EMODPE=E2=80=99s existe= nce > 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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. 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 =3D=3D=3D=3D=3D=3D=3D=3D The solution is to force enclaves creators to declare their intent up fro= nt 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. Essentially, this means that whenever the kernel is asked to change an enclave PTE, it needs to ensure the change is consistent with that stashe= d 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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. " /Jarkko