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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 67E6EC4727D for ; Tue, 29 Sep 2020 14:24:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D988520739 for ; Tue, 29 Sep 2020 14:24:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D988520739 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 25BEE6B006E; Tue, 29 Sep 2020 10:24:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22DB26B0071; Tue, 29 Sep 2020 10:24:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D1036B0072; Tue, 29 Sep 2020 10:24:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id EC3276B006E for ; Tue, 29 Sep 2020 10:24:28 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B07E48249980 for ; Tue, 29 Sep 2020 14:24:28 +0000 (UTC) X-FDA: 77316319416.24.teeth30_5303cc82718a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 849791A4A5 for ; Tue, 29 Sep 2020 14:24:28 +0000 (UTC) X-HE-Tag: teeth30_5303cc82718a X-Filterd-Recvd-Size: 9731 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Sep 2020 14:24:26 +0000 (UTC) IronPort-SDR: GouO6wD9YyzMxsiYZYE7RjieF8iURFAZrnjoLH1OaLjFxNBP4FA/bHMGvzc+uWz2G7CDXIxHZY 8c9ajEytE+Ew== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="162266049" X-IronPort-AV: E=Sophos;i="5.77,318,1596524400"; d="scan'208";a="162266049" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2020 07:24:25 -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+IofwvXzX2ON/Mj7aQwf5W iC+3nWC7q0uxKwwsddJ0Nu+dpA/UORQWa1NiAftEoSpk5+nUUi0WE+5DRm0H+TXKBWMGNCFn c6+EKg5zQaa8KqymHcOrSXNPmzJuXvDQ8uj2J8XuzCZfK4uy1+YdIr0yyEMI7mdh4KX50LO1 pmowEqDh7dLShTOif/7UtQYrzYq9cPnjU2ZW4qd5Qz2joSGTG9eCXLz5PRe5SqHxv6ljk8mb ApNuY7bOXO/A7T2j5RwXIlcmssqIjBcxsRRoIbpCwWWGjkYjzYCjgsNFL6rt4OL11OUF37wL QcTl7fbCGv53KfKPdYD5hcbguLKi/aCccJK18ZwNjFhqr4MliQARAQABzShEYXZpZCBDaHJp c3RvcGhlciBIYW5zZW4gPGRhdmVAc3I3MS5uZXQ+wsF7BBMBAgAlAhsDBgsJCAcDAgYVCAIJ CgsEFgIDAQIeAQIXgAUCTo3k0QIZAQAKCRBoNZUwcMmSsMO2D/421Xg8pimb9mPzM5N7khT0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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: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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=E2=80=99t personally care that much about EMODPE but, you could = probably >> get the point across with something like: >> >> SGX=E2=80=99s 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=E2=80=99s exist= ence >> demonstrates that EADD / EEXTEND are not special. >=20 > 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. >=20 > I did only very rudimentary clean up for the text (e.g. fix the ioctl > name, add shortt summary and not much else). >=20 > 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. >=20 > " > mm: Add 'mprotect' hook to struct vm_operations_struct >=20 > Background > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > 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. Fo= r > instance, before copying data to an executable enclave page, we migh= t > 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 an= d > 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()). >=20 > Solution > =3D=3D=3D=3D=3D=3D=3D=3D >=20 > The solution is to force enclaves creators to declare their intent up f= ront > to ioctl(fd, SGX_IOC_ENCLAVE_ADD_PAGES). This intent can me immediatel= y > compared to the source data mapping (and rejected if necessary). It is > also stashed off and then later compared with enclave PTEs to ensure th= at > any future mmap()/mprotect() operations performed by the enclave creato= r 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 stas= hed > intent. There is an existing vm_ops->mmap() hook which allows SGX to d= o > 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 driv= er. >=20 > Implications > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > However, there is currently no implementation of the intent checks at t= he > time of ioctl(fd, SGX_IOC_ENCLAVE_ADD_PAGES). That means that the inte= nt > 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?