Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp460492pxk; Wed, 23 Sep 2020 07:35:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdaYUl9dtc9MpP81SIhMGtANCN7x4Si2bOtFeeLfuda5KSriidN/zorX5IUM84fwuK8TJt X-Received: by 2002:a17:906:ce4b:: with SMTP id se11mr10323872ejb.386.1600871719233; Wed, 23 Sep 2020 07:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600871719; cv=none; d=google.com; s=arc-20160816; b=DwhE5HBGKxKpG85Msw5+t82w4F7jccGAHrcbIcHU7YZTWSrqsrewbM5iV1Cpt0dhXx pkI7jIQyJS0k+u3SptOMgmIPmY8Eq34Z7m8iOicNLSmfIs0TnGbhe0uDFUIqmCf6MgkB pDtr7ICjrx1MwLQEjcmERWnNmLJuHLsTAvLANGIUKlf2n9GGbedjg+eKoe8r4gfEd4uJ FH/PfBptg9a1wPL+AKZOOcyiy1e/xdFzI0q2/mRzp96a+5sO0emvAAefFqIkceF6pz5/ /5CBI1wW4qbzmEiUJbzu99Ul99DAatnW2pQRYso8S7s94/ujfixGhFyAc+dkQj+khIM5 xLQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=Ca0wmVP2hefXdC5UIilKMf6L1XSFpKFZTdh+4zq2TqA=; b=oPFzvvCEubCWT3v5Sqvz8a+W62EpwBZTjBmR2zCBjyOvUtdj9Q/MNZuxy0yPGiFtpx nrvNV4jKaeaxjtO8Usy6nZkXGhb0JAX+AWdr4nnjIDhxa/p8NpaVDLE4Y03SHL4vqfIs 8ReHwP/nvgYsezZLLG4rrmb3/CLet7brpTdpPJfGXnKBHgfjQ3+AEijh3YPcSNa6qVAj Go/voE7+oGJPpBE34CsG+eC+pfsN7JVfeja3ohyTKruHDS2tDZddVav5lj75h3zoT0xK +u1tcRqlnVXKK8nXT92k/8NTN6/aORPP8I34ZtwGtSjgxzPVeZDWofa1MZNIyzrLjf3L QHiw== 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 mb24si17272ejb.583.2020.09.23.07.34.54; Wed, 23 Sep 2020 07:35:19 -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 S1726801AbgIWOdR (ORCPT + 99 others); Wed, 23 Sep 2020 10:33:17 -0400 Received: from mga02.intel.com ([134.134.136.20]:57822 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726587AbgIWOdP (ORCPT ); Wed, 23 Sep 2020 10:33:15 -0400 IronPort-SDR: ZkyNyoPd3h1HfwwPjicwPH4aJkXqjh22WZqPdqbO6R9es3C5IGMmbgsfoyYQ6SStyeg0M8m6d/ 3WTNs+0GO0+Q== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="148552790" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="148552790" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 07:33:14 -0700 IronPort-SDR: ItLiQJZoZ4CdNDBYceiZlvD85IZXi7GL/1hQJIpXeosadYCS1uHk+MasVby8eq6GxSbZFtzxqO PXxbe8IMI3gw== X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="486460853" Received: from ichiojdo-mobl.ger.corp.intel.com (HELO localhost) ([10.252.51.82]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 07:33:08 -0700 Date: Wed, 23 Sep 2020 17:33:05 +0300 From: Jarkko Sakkinen To: Dave Hansen Cc: Andy Lutomirski , Sean Christopherson , 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: <20200923143305.GE5160@linux.intel.com> References: <20200918235337.GA21189@sjchrist-ice> <1B23E216-0229-4BDD-8B09-807256A54AF5@amacapital.net> <20200922125801.GA133710@linux.intel.com> <25d46fdc-1c19-2de8-2ce8-1033a0027ecf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <25d46fdc-1c19-2de8-2ce8-1033a0027ecf@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 22, 2020 at 08:11:14AM -0700, Dave Hansen wrote: > Now I'm confused. I actually don't think I have a strong understanding > of how an enclave actually gets loaded, how mmap() and mprotect() are > normally used and what this hook is intended to thwart. You saw my other comments. I scraped this together based on your feedback and my responses: " mm: Add 'mprotect' callback to vm_ops Intel Sofware Guard eXtensions (SGX) allows creation of blobs called enclaves, for which page permissions are defined when the enclave is first loaded. Once an enclave is loaded and initialized, it can be mapped to the process address space. There is no standard file format for enclaves. They are dynamically built and the ways how enclaves are deployed differ greatly. For an app you might want to have a simple static binary, but on the other hand for a container you might want to dynamically create the whole thing at run-time. Also, the existing ecosystem for SGX is already large, which would make the task very hard. Finally, even if there was a standard format, one would still want a dynamic way to add pages to the enclave. One big reason for this is that enclaves have load time defined pages that represent entry points to the enclave. Each entry point can service one hardware thread at a time and you might want to run-time parametrize this depending on your environment. The consequence is that enclaves are best created with an ioctl API and the access control can be based only to the origin of the source file for the enclave data, i.e. on VMA file pointer and page permissions. For example, this could be done with LSM hooks that are triggered in the appropriate ioctl's and they could make the access control decision based on this information. Unfortunately, there is ENCLS[EMODPE] that a running enclave can use to upgrade its permissions. If we do not limit mmap() and mprotect(), enclave could upgrade its permissions by using EMODPE followed by an appropriate mprotect() call. This would be completely hidden from the kernel. Add 'mprotect' hook to vm_ops, so that a callback can be implemeted for SGX that will ensure that {mmap, mprotect}() permissions do not surpass any of the original page permissions. This feature allows to maintain and refine sane access control for enclaves. " /Jarkko