Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4993517pxb; Wed, 19 Jan 2022 08:54:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4HqNvfZE+fehc07p5OEczJCX8lZ8qPJ5rUzJzCC+0igR6m7Tow6mxtbbEzgXIt1gfZ8pf X-Received: by 2002:a17:902:ab89:b0:14a:1802:7c15 with SMTP id f9-20020a170902ab8900b0014a18027c15mr32816309plr.88.1642611284373; Wed, 19 Jan 2022 08:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642611284; cv=none; d=google.com; s=arc-20160816; b=0wyesOO11tieo+A1/UlO8qImupir0LyhfQR7mM9LP7LwC3Sd+0HiYOAva77vtL/aSC 7LXFJa/XdqQkYlJPhNJ1htWMsM61nSTPr1L6mjtJ0V6kxo2Rae2uZ7+nFw5EpI/BomNi 9UlZ5fGlBP4qv6hICFUTcmnLYt5EkJ3TreG1lMIita6COlRIuUY5QvNYmBpSb0gsvErE HESEqSy2q8W2an7hGzr9lL+gqxfv7lc6hy/PmFKHrk/AVCLLXZ2fP9Mev5pESugx25lW yIEliUdPwL0eC0YvJ2tZx7hT87JZmWm/YL1O/QqyqDbxAwnF/Lnk8mjepd9uczemMgSG b6pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=P32vJpAlRCkal5kf4W/ioWHLpbYUsnCjCIf/gE8G+Bc=; b=fQ0/u7h84VIkywPwIu+YTp3Bmd6cIjp6od45BdcQl9Rw3Fq3sMyH60TbNdr9qwFF+F o9Qx7udw4f2PfzzqLXeO7JIq6rtq0a98Eq0iJyxvqxblgSwmegXy9qV+M2Q/hZPkNhGY HybGZYbtuy/JltobgtKgN/NFra0XEHHFga7LYWHxXQVRWpg3gR+imK1j7r3nWf3HoiBF RYf2cSznZjyJo3LBZGqxM+MV0Gfh+MyWdOvKRb+8faWiRmPQzSzjYXL7Igs+u6pzvuoW SeWdNFGSgsz6zIEooi9Wz0Ik4uAznnEBcDkQLtkfL2D7cCerJzuxaEZ6TXO5LQliz+UY Gdpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Uvj0oFb1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a184si330366pfb.57.2022.01.19.08.54.30; Wed, 19 Jan 2022 08:54:44 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Uvj0oFb1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348542AbiARDkO (ORCPT + 99 others); Mon, 17 Jan 2022 22:40:14 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:57804 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376258AbiARDcH (ORCPT ); Mon, 17 Jan 2022 22:32:07 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 82568B811CE; Tue, 18 Jan 2022 03:32:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABBE8C004E1; Tue, 18 Jan 2022 03:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642476724; bh=syj2iJNuuvz/tnj5IIbpThSSE2X8toyYmURpMGjqHGE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Uvj0oFb1W+4LuVhpYtvs841hEnuCaEMrL0XzUZk1udEooTWKNTKrfRiBczQbw5/Kf EEDu700umatDXDbVSnzP8VL/5gl8Nr87VbYdexv5va/oawAGtV8xkk/RS0P6uDhFb9 l+B/WQ7CnCpfeghzc14NKhjT5B9qLDf9Ih4ijGb+ofFXwT5JcuS1ix9qLB7ZZbL6eR qUenUuhusfDrNBteAS2ljFVm9vlQcCopRGUrZVGRPmU3AKzjCzt/G1vrOMVYCrhS1u 87CyXFn4VpDrobkz8ji5SLHsXid134QFIO1caF9k3CC8bbVxZgDlKL0qDDkBqkASZL w5NOEnPaQFB1w== Date: Tue, 18 Jan 2022 05:31:49 +0200 From: Jarkko Sakkinen To: Nathaniel McCallum Cc: Reinette Chatre , Haitao Huang , Andy Lutomirski , dave.hansen@linux.intel.com, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, linux-sgx@vger.kernel.org, x86@kernel.org, seanjc@google.com, kai.huang@intel.com, cathy.zhang@intel.com, cedric.xing@intel.com, haitao.huang@intel.com, mark.shanahan@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 05/25] x86/sgx: Introduce runtime protection bits Message-ID: References: <6e1cb295-b86e-ae09-2cf0-cfefd1a10e65@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 18, 2022 at 04:22:45AM +0200, Jarkko Sakkinen wrote: > On Tue, Jan 18, 2022 at 03:59:29AM +0200, Jarkko Sakkinen wrote: > > On Mon, Jan 17, 2022 at 08:13:32AM -0500, Nathaniel McCallum wrote: > > > On Sat, Jan 15, 2022 at 6:57 AM Jarkko Sakkinen wrote: > > > > > > > > On Sat, Jan 15, 2022 at 03:18:04AM +0200, Jarkko Sakkinen wrote: > > > > > On Fri, Jan 14, 2022 at 04:41:59PM -0800, Reinette Chatre wrote: > > > > > > Hi Jarkko, > > > > > > > > > > > > On 1/14/2022 4:27 PM, Jarkko Sakkinen wrote: > > > > > > > On Fri, Jan 14, 2022 at 04:01:33PM -0800, Reinette Chatre wrote: > > > > > > >> Hi Jarkko, > > > > > > >> > > > > > > >> On 1/14/2022 3:15 PM, Jarkko Sakkinen wrote: > > > > > > >>> On Fri, Jan 14, 2022 at 03:05:21PM -0800, Reinette Chatre wrote: > > > > > > >>>> Hi Jarkko, > > > > > > >>> > > > > > > >>> How enclave can check a page range that EPCM has the expected permissions? > > > > > > >> > > > > > > >> Only way to change EPCM permissions from outside enclave is to run ENCLS[EMODPR] > > > > > > >> that needs to be accepted from within the enclave via ENCLU[EACCEPT]. At that > > > > > > >> time the enclave provides the expected permissions and that will fail > > > > > > >> if there is a mismatch with the EPCM permissions (SGX_PAGE_ATTRIBUTES_MISMATCH). > > > > > > > > > > > > > > This is a very valid point but that does make the introspection possible > > > > > > > only at the time of EACCEPT. > > > > > > > > > > > > > > It does not give tools for enclave to make sure that EMODPR-ETRACK dance > > > > > > > was ever exercised. > > > > > > > > > > > > Could you please elaborate? EACCEPT is available to the enclave as a tool > > > > > > and it would fail if ETRACK was not completed (error SGX_NOT_TRACKED). > > > > > > > > > > > > Here is the relevant snippet from the SDM from the section where it > > > > > > describes EACCEPT: > > > > > > > > > > > > IF (Tracking not correct) > > > > > > THEN > > > > > > RFLAGS.ZF := 1; > > > > > > RAX := SGX_NOT_TRACKED; > > > > > > GOTO DONE; > > > > > > FI; > > > > > > > > > > > > Reinette > > > > > > > > > > Yes, if enclave calls EACCEPT it does the necessary introspection and makes > > > > > sure that ETRACK is completed. I have trouble understanding how enclave > > > > > makes sure that EACCEPT was called. > > > > > > > > I'm not concerned of anything going wrong once EMODPR has been started. > > > > > > > > The problem nails down to that the whole EMODPR process is spawned by > > > > the entity that is not trusted so maybe that should further broke down > > > > to three roles: > > > > > > > > 1. Build process B > > > > 2. Runner process R. > > > > 3. Enclave E. > > > > > > > > And to the costraint that we trust B *more* than R. Once B has done all the > > > > needed EMODPR calls it would send the file descriptor to R. Even if R would > > > > have full access to /dev/sgx_enclave, it would not matter, since B has done > > > > EMODPR-EACCEPT dance with E. > > > > > > > > So what you can achieve with EMODPR is not protection against mistrusted > > > > *OS*. There's absolutely no chance you could use it for that purpose > > > > because mistrusted OS controls the whole process. > > > > > > > > EMODPR is to help to protect enclave against mistrusted *process*, i.e. > > > > in the above scenario R. > > > > > > There are two general cases that I can see. Both are valid. > > > > > > 1. The OS moves from a trusted to an untrusted state. This could be > > > the multi-process system you've described. But it could also be that > > > the kernel becomes compromised after the enclave is fully initialized. > > > > > > 2. The OS is untrustworthy from the start. > > > > > > The second case is the stronger one and if you can solve it, the first > > > one is solved implicitly. And our end goal is that if the OS does > > > anything malicious we will crash in a controlled way. > > > > > > A defensive enclave will always want to have the least number of > > > privileges for the maximum protection. Therefore, the enclave will > > > want the OS to call EMODPR. If that were it, the host could just lie. > > > But the enclave also verifies that the EMODPR operation was, in fact, > > > executed by doing EACCEPT. When the enclave calls EACCEPT, if the > > > kernel hasn't restricted permissions then we get a controlled crash. > > > Therefore, we have solved the second case. > > > > So you're referring to this part of the SDM pseude code in the SDM: > > > > (* Check the destination EPC page for concurrency *) > > IF ( EPC page in use ) > > THEN #GP(0); FI; > > > > I wonder does "EPC page in use" unconditionally trigger when EACCEPT > > is invoked for a page for which all of these conditions hold: > > > > - .PR := 0 (no EMODPR in progress) > > - .MODIFIED := 0 (no EMODT in progress) > > - .PENDING := 0 (no EMODPR in progress) > > > > I don't know the exact scope and scale of "EPC page in use". > > > > Then, yes, EACCEPT could be at least used to validate that one of the > > three operations above was requested. However, enclave thread cannot say > > which one was it, so it is guesswork. > > OK, I got it, and this last paragraph is not true. SECINFO given EACCEPT > will lock in rest of the details and make the operation deterministic. > > The only question mark then is the condition when no requests are active. This the big picture model how I look at SGX2 patches, and perhaps this could bring some more common sense idioms to this discussion. There is not one but two passes of measurement: 1. A static pass. 2. A dynamic pass. The static pass is the full process of doing ioctls that trigger ECREATE, EADD and EEXTEND. It ends to EINIT, which triggers to pass/fail condition. The 2nd pass is the dynamic pass. It's the pass where enclave measures itself and is performed by the full set of all EACCEPT operations done by the enclave. It ends to either all EACCEPT operations succeeding, or any of them #GP. Confidentiality is the state established exactly when both passes are completed. /Jarkko