Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1445431pxb; Fri, 6 Nov 2020 09:46:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbKC2O6qr6rLGnAIDljv93v+MA6o93sIKlX6I5ZTFU2kKAekmhvZA77uFdLw6XgH3sV0Ef X-Received: by 2002:a17:906:824a:: with SMTP id f10mr3343135ejx.167.1604684807591; Fri, 06 Nov 2020 09:46:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604684807; cv=none; d=google.com; s=arc-20160816; b=JcRmIeGGGh7upEVzqt6Rf56gWEzeWkRBUUKIdaS9q6hYHbyeqbjgFSA3529F8XTPjZ E5sw5Ej7K37dMjbsOrevMt7R2KQfqLE6n7yKd9il+/N/M0TM/J1zwDxVaml7N+mpSsrT dwFX5FIkjutKSsvKrSmbhOmoac2/RH2r2QPyc5SXIjtmF7jtnPoUl4x2Oq2lDm8+P+ck cn6CmWiDrgn9SRll+yTWEUxTCS/mKys5KckwGH1/r1VQKXSNJMTrbcRVtUS9xrK4uyZ2 LU5HWx0BHnw5jo1hng6dry6piJMppkn+5qQc9bAS9D/b/hodjA8bqVV5C60vArdasuZ8 klAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date; bh=AazmGe6ublt0AIO16zgtcQSAwalxr7gNTBkPVp2VGlw=; b=AoVsGUHczLP1GCCd7XTd6BxIeC7n1A5kjMUZE1RjAMQZyfKyBfQw/ce2DBWYrnGIe9 LK78FzCtEivTSH2QQJLxhQFwzJvKOrBfrNsZ7zYFyl7jEAEtX2/MUxphrf8WT3FZIpJu DeorePFEpeoy+LUG4kF6vJqdSFCMvT8zlQmPf8x6mjwnHcyK/gA6dtN2CeBuqg9pXcm2 JIC8HwrVIXlSB1pfuvSF7BTi8E3VD2Z2Exr8s4huemgoqbFEDKIpj9uoGZrzSsboh+4o CmvtTKxLf4Oe5gfkCQLZlVyFVQXgUtP2GMPOZs2OWQk4TjBX9U2wCj0+SNrFPXYGTjgs AH8w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mf21si1287679ejb.722.2020.11.06.09.46.24; Fri, 06 Nov 2020 09:46:47 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbgKFRow (ORCPT + 99 others); Fri, 6 Nov 2020 12:44:52 -0500 Received: from wind.enjellic.com ([76.10.64.91]:59792 "EHLO wind.enjellic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726034AbgKFRow (ORCPT ); Fri, 6 Nov 2020 12:44:52 -0500 Received: from wind.enjellic.com (localhost [127.0.0.1]) by wind.enjellic.com (8.15.2/8.15.2) with ESMTP id 0A6Hi0HP024602; Fri, 6 Nov 2020 11:44:00 -0600 Received: (from greg@localhost) by wind.enjellic.com (8.15.2/8.15.2/Submit) id 0A6HhxkZ024601; Fri, 6 Nov 2020 11:43:59 -0600 Date: Fri, 6 Nov 2020 11:43:59 -0600 From: "Dr. Greg" To: Jarkko Sakkinen Cc: x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Jethro Beekman , Darren Kenny , andriy.shevchenko@linux.intel.com, asapek@google.com, bp@alien8.de, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com, mikko.ylinen@intel.com Subject: Re: [PATCH v40 10/24] mm: Add 'mprotect' hook to struct vm_operations_struct Message-ID: <20201106174359.GA24109@wind.enjellic.com> Reply-To: "Dr. Greg" References: <20201104145430.300542-1-jarkko.sakkinen@linux.intel.com> <20201104145430.300542-11-jarkko.sakkinen@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201104145430.300542-11-jarkko.sakkinen@linux.intel.com> User-Agent: Mutt/1.4i X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.2.3 (wind.enjellic.com [127.0.0.1]); Fri, 06 Nov 2020 11:44:00 -0600 (CST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 04, 2020 at 04:54:16PM +0200, Jarkko Sakkinen wrote: Good morning, I hope the week has gone well for everyone. > From: Sean Christopherson > > Background > ========== > > 1. SGX enclave pages are populated with data by copying from normal memory > via ioctl() (SGX_IOC_ENCLAVE_ADD_PAGES), which will be added later in > this series. > 2. It is desirable to be able to restrict those normal memory data sources. > For instance, to ensure that the source data 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(). Only relevant on SGX2 hardware, see discussion below. > This creates a problem because the original data source may have > long since vanished at the time when enclave page permissions are > established (mmap() or mprotect()). > > The solution (elsewhere in this series) is to force enclaves I don't believe that enclaves should be plural in this context. > creators to declare their paging permission *intent* up front to the > ioctl(). This intent can me immediately compared to the source The 'me' should be 'be' in the above line. > data???s mapping and rejected if necessary. > > The ???intent??? is also stashed off for later comparison with > enclave PTEs. This ensures that any future mmap()/mprotect() > operations performed by the enclave creator or done on behalf of the > enclave can be compared with the earlier declared permissions. Just some further clarifications that should, arguably, be included in the kernel documentation given their security implications. The 900 pound primate in the room, that no one is acknowledging, is that this technology was designed to not allow the operating system to have any control over what it is doing. In the mindset of kernel developers, the operating system is the absolute authority on security, so we find ourselves in a situation where the kernel needs to try and work around this fact so any solutions will be imperfect at best. As I've noted before, this is actually a primary objective of enclave authors, since one of the desires for 'Confidential Computing' is to hide things like proprietary algorithms from the platform owners. I think the driver needs to acknowledge this fact and equip platform owners with the simplest and most effective security solutions that are available. The only reason that mprotect protections are needed in this driver are to close a security loophole on SGX2 hardware, ie. hardware that supports the ENCLU[EMODPE] instruction. This instruction allows an enclave to modify page permissions that are encoded in the Enclave Page Cache Metadata (EPCM) at initialization time. In all likelihood, this is going to be the only relevant hardware that this driver runs on. On SGX2 hardware, enclave based code can conspire with its untrusted runtime to allow executable regions to have write permissions. This would allow the enclave to load and execute whatever code that it pleases and that the operating system would have no visibility into whatsoever. The non-SGX2 platforms don't need mprotect protections since even if they were to modify at the OS level their page permissions, any attempts to access a page with modified permissions would be trapped by the EPCM protections that are unmodifiable after the enclave has been initialized. In light of this, given the decision by the driver authors to not fully equip the driver with EDMM support, the mprotect protection requirements are straight forward and minimalistic. All that is needed is a binary valued variable, set on the command-line, that either allows or denies anonymous code execution by an enclave, ie. access to page protection changes after initialization. The enclave page mapping callback is elegant but has little use if the objective of all this is to allow the driver to enforce SGX1 semantics on a platform that has SGX2 instruction support. Save the elegant solution until a reasoned arguement can be made as to what anyone would actually be able to do with the per page permissions checks, even on an EDMM capable driver. I could go into detail on that issue as well but I hesitate to be an insufferable bore. I hope all of this is helpful. Have a good weekend. Dr. Greg As always, Dr. Greg Wettstein, Ph.D, Worker Autonomously self-defensive Enjellic Systems Development, LLC IOT platforms and edge devices. 4206 N. 19th Ave. Fargo, ND 58102 PH: 701-281-1686 EMAIL: greg@enjellic.com ------------------------------------------------------------------------------ "In the future, company names will be a 32-character hex string." -- Bruce Schneier