Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp821845ybv; Thu, 13 Feb 2020 10:08:02 -0800 (PST) X-Google-Smtp-Source: APXvYqwpt7PlAXbZW9paGYiMORssW5emJ3CnQWTlX2zIRS31ArdNIl2qKnK0WHbOVDpAehiOEQIM X-Received: by 2002:a05:6830:154a:: with SMTP id l10mr14480622otp.44.1581617282098; Thu, 13 Feb 2020 10:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581617282; cv=none; d=google.com; s=arc-20160816; b=T6yjJjXxrch/rb0JjIFuDO76eNy3COHOiPPUOjeJiMgbebAk13UX6btsNKD5DE5WhB WVvnopJjGGXMcKQcywyelBLiGKggTMiiOkeSmlAerufkIH6vGn7BkmWrsMD+yBg6daR0 VPTsZ6RIeC+so3cq58QLViupMJWDoiFMA+38lumSKSP5ebymwCiJ/uvI3Ytf+Yo2Q1aK c1MmUuJ4QV3zXheNQavG3O0XhSsUmIvsD8XoaO32zGaTzpnhXb0trHiWTJYtSnuJrnUB QlCoAj3Fjrbj4zKR3h4oK12B16aJ/zXn5esPXl+ax526I5+AYXR5N18lhA4I3kG4Ibr6 RqLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=QivA+kfTJMDnw0DZHHxCfh4DWj+wDvyIOVUBdenhyPI=; b=S2iZJ7HccI/kyrS92xFUXJWJdVckxR5KnFbao6pqctjNtfpd18mS+qUo72TtlJzh7D qKjPJ8g9B2BhTzRXBX8r32SZiVDGsnPJ8MHS3FfSrYi48n2Fp1xAbszuHmG2OLegU/6u NAV8AvOm+d9IjpTWRiOwIRkwoDJ+lUJP2+7RZWjsbxtl0vZ6N4uqxES2ELMUYYij/jC8 a4FIlfZjCowJtooKUEXFQJGPV4g44zzDcln5P0XFNPH1Rh+RVzIYdtTNJ4q/ts6x6+MU 6N9TV7Q+10iH2PG/29YkwBnXqwY1Vb8X2rjCJgpBE+I+Yqqh0PDAWHu66RtdjC+xmx7H aLVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id h18si1458863otk.227.2020.02.13.10.07.48; Thu, 13 Feb 2020 10:08:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728192AbgBMSHk (ORCPT + 99 others); Thu, 13 Feb 2020 13:07:40 -0500 Received: from mga09.intel.com ([134.134.136.24]:55155 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbgBMSHk (ORCPT ); Thu, 13 Feb 2020 13:07:40 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2020 10:07:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,437,1574150400"; d="scan'208";a="238107659" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by orsmga006.jf.intel.com with ESMTP; 13 Feb 2020 10:07:37 -0800 Date: Thu, 13 Feb 2020 10:07:37 -0800 From: Sean Christopherson To: Jethro Beekman Cc: Jarkko Sakkinen , linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, nhorman@redhat.com, npmccallum@redhat.com, haitao.huang@intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, bp@alien8.de, josh@joshtriplett.org, luto@kernel.org, kai.huang@intel.com, rientjes@google.com, cedric.xing@intel.com, puiterwijk@redhat.com, linux-security-module@vger.kernel.org, Suresh Siddha , Haitao Huang Subject: Re: [PATCH v26 10/22] x86/sgx: Linux Enclave Driver Message-ID: <20200213180737.GC18610@linux.intel.com> References: <20200209212609.7928-1-jarkko.sakkinen@linux.intel.com> <20200209212609.7928-11-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 13, 2020 at 02:59:52PM +0100, Jethro Beekman wrote: > On 2020-02-09 22:25, Jarkko Sakkinen wrote: > > +/** > > + * struct sgx_enclave_add_pages - parameter structure for the > > + * %SGX_IOC_ENCLAVE_ADD_PAGE ioctl > > + * @src: start address for the page data > > + * @offset: starting page offset > > + * @length: length of the data (multiple of the page size) > > + * @secinfo: address for the SECINFO data > > + * @flags: page control flags > > + * @count: number of bytes added (multiple of the page size) > > + */ > > +struct sgx_enclave_add_pages { > > + __u64 src; > > + __u64 offset; > > + __u64 length; > > + __u64 secinfo; > > + __u64 flags; > > + __u64 count; > > +}; > > Compared to the last time I looked at the patch set, this API removes the > ability to measure individual pages chunks. That is not acceptable. Why is it not acceptable? E.g. what specific use case do you have that _requires_ on measuring partial 4k pages of an enclave? > On 2019-10-11 16:37, Sean Christopherson wrote: > > Hiding the 256-byte granualarity from userspace is a good idea as it's not > > intrinsically tied to the SGX architecture and exists only because of > > latency requirements. > > What do you mean by "it's not intrinsically tied to the SGX architecture"? > This is a fundamental part of the SGX instruction set. This is the > instruction definition from the SDM: "EEXTEND—Extend Uninitialized Enclave > Measurement by 256 Bytes". SGX fundamentally works at a 4k granularity. EEXTEND is special cased because extending the measurement is a slow operation, i.e. EEXTEND on more than 256 byte chunks, *with the current implementation*, would exceeded latency requirements, e.g. block interrupts for too long and hose the kernel. A future implementation of SGX could change the latency of extending the measurement, e.g. a different algorithm that is slower/faster, and so could introduce EEXTEND2 which would work at a different granularity than EEXTEND. EEXTEND could have avoided the latency problems via other methods, e.g. by being interruptible a la EINIT and/or by being restartable. But that ship has sailed, so to avoid future complication in the kernel's ABI we're proposing/advocating supporting only measuring at a 4k granularity. > The exact sequence of EADD/EEXTEND calls is part of the enclave hash. The OS > mustn't arbitrarily restrict how an enclave may be loaded. If the enclave It's not arbitrary, there are good reasons for wanting to work with 4k granularity. Regardless, there are many examples of the kernel arbitrarily restricting what can be done relative to what is physically possible in hardware. > loader were to follows OS-specific restrictions, that would result in > effectively different enclaves. Because of these interoperability concerns, > 256-byte granularity *must* be exposed through the UAPI. Interoperability with what? Other OSes? > Besides only partially measuring a page, there are some other fringe cases > that are technically possible, although I haven't seen any toolchains that do > that. These include not interleaving EADD and EEXTEND, not using logical > ordering for the EEXTENDs, and call EEXTEND multiple times on the same chunk. > Maximum interoperability would require supporting any EADD/EEXTEND sequence. Same interoperability question as above. > Maybe we should just add an EEXTEND@offset ioctl? This would give > fine-grained control when needed (one could set flags=0 in the add pages > ioctl and interleave with EEXTEND as needed). If you're ok adding an EEXTEND > ioctl I don't think this issue needs to block landing the driver in its > current form, in which case: We've also discussed an EEXTEND ioctl(), but ultimately couldn't come up with a use case that _required_ partial page measurement. > Tested-by: Jethro Beekman > > Sorry for being super late with this, I know you asked me for feedback about > this specific point in October. However, I did previously mention several > times that being able to measure individual 256-byte chunks is necessary. > > -- Jethro Beekman | Fortanix