Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp851987img; Wed, 20 Mar 2019 12:14:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNTkrZyrNHAT7NQSp2IxQ2vhdn3iMoUqSfSo7FViQ2qjGv6HXGhCWD+jAtUc6oETFk0Z2x X-Received: by 2002:a17:902:9f83:: with SMTP id g3mr9816799plq.296.1553109265353; Wed, 20 Mar 2019 12:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553109265; cv=none; d=google.com; s=arc-20160816; b=uJkVBRNBRami7dVgVBO3p4iQjkQ5Ooj83WSJrEJ6zJMwmGOAR1YBcRkPLQUhGQmYiL 1Ic0Ohw1M/mLwIEYqXj0gFlsO6MokiPL7J5pQJnUVdjMz2tgNWAo36ZACczVN6VrI6Ro E+AZwEabyt8PpOIuyy0rlIJ0DIHe+kJ0dQMjDR3e7hcczA7fYqifNklC/Wt5vIC2JLfq 9ZHWXFOkG+EfBcpU9fJFmDl9ocwXMEY532uUXvWljXyHgfqK7pxFsBMZZbC+C9nBE2Jy WwLPsp4JnqElCql4SJXScFcl7m4fN0IPKeq4tFcfJIiSnWkf1caOkhWRC3vnalXK9rgb zTWA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Hp4loT3GTJiILHVsXNCqkk5BJau9uWeneKBeIQ2c4lo=; b=UBM3niSfUTWXJEFpXKaild+jfufE13rRFWm7w7wnm/O2xwh56Kzuj5hgqUpSVgxrgm FpHeet36WSym7F3PwgAEkSMVHF9Z0hLiM76C/pBzjxwJaLXdtEbnW6BhE/I8H5cXXkA3 wZekPViTgXGKgwtbm43Xt3HvPE1ixswRefcytD9m8dcWwaJCYMjN06Ao0cuivpsJ6YZ9 Qc51h/DfKLc/awLMeZAK3cHYp+L979IUkGT+f+wNVl6MagSprRjoZiISu0au7xyijaRC XkyBSNYnZ4S0uHuOSE7JE7jTuI2nQA3YF4PmVvyST4m334beR+UFvPZyOXuNmP6uDkuM fjpg== 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 68si2175365pga.497.2019.03.20.12.14.10; Wed, 20 Mar 2019 12:14:25 -0700 (PDT) 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 S1726875AbfCTTNV (ORCPT + 99 others); Wed, 20 Mar 2019 15:13:21 -0400 Received: from mga06.intel.com ([134.134.136.31]:8939 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726067AbfCTTNU (ORCPT ); Wed, 20 Mar 2019 15:13:20 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2019 12:13:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,249,1549958400"; d="scan'208";a="330415797" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.181]) by fmsmga005.fm.intel.com with ESMTP; 20 Mar 2019 12:13:18 -0700 Date: Wed, 20 Mar 2019 12:13:18 -0700 From: Sean Christopherson To: "Xing, Cedric" Cc: Jarkko Sakkinen , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "linux-sgx@vger.kernel.org" , "akpm@linux-foundation.org" , "Hansen, Dave" , "nhorman@redhat.com" , "npmccallum@redhat.com" , "Ayoun, Serge" , "Katz-zamir, Shay" , "Huang, Haitao" , "andriy.shevchenko@linux.intel.com" , "tglx@linutronix.de" , "Svahn, Kai" , "bp@alien8.de" , "josh@joshtriplett.org" , "luto@kernel.org" , "Huang, Kai" , "rientjes@google.com" , Andy Lutomirski , Dave Hansen , Haitao Huang , Jethro Beekman , "Dr . Greg Wettstein" Subject: Re: [PATCH v19,RESEND 24/27] x86/vdso: Add __vdso_sgx_enter_enclave() to wrap SGX enclave transitions Message-ID: <20190320191318.GF30469@linux.intel.com> References: <20190320162119.4469-1-jarkko.sakkinen@linux.intel.com> <20190320162119.4469-25-jarkko.sakkinen@linux.intel.com> <960B34DE67B9E140824F1DCDEC400C0F4E85C484@ORSMSX116.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <960B34DE67B9E140824F1DCDEC400C0F4E85C484@ORSMSX116.amr.corp.intel.com> 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 Wed, Mar 20, 2019 at 11:30:26AM -0700, Xing, Cedric wrote: > > +/** > > + * __vdso_sgx_enter_enclave() - Enter an SGX enclave > > + * > > + * %eax: ENCLU leaf, must be EENTER or ERESUME > > + * %rbx: TCS, must be non-NULL > > + * %rcx: Optional pointer to 'struct sgx_enclave_exception' > > + * > > + * Return: > > + * 0 on a clean entry/exit to/from the enclave > > + * -EINVAL if ENCLU leaf is not allowed or if TCS is NULL > > + * -EFAULT if ENCLU or the enclave faults > > + * > > + * Note that __vdso_sgx_enter_enclave() is not compliant with the x86- > > 64 ABI. > > + * All registers except RSP must be treated as volatile from the > > +caller's > > + * perspective, including but not limited to GPRs, EFLAGS.DF, MXCSR, > > FCW, etc... > > + * Conversely, the enclave being run must preserve the untrusted RSP > > and stack. > > By requiring preservation of RSP at both AEX and EEXIT, this precludes > the possibility of using the untrusted stack as temporary storage by > enclaves. While that looks reasonable at first glance, I'm afraid it > isn't the case in reality. The untrusted stack is inarguably the most > convenient way for data exchange between an enclave and its enclosing > process, I vehemently disagree with "inarguably". IMO, passing data via registers is much more convenient. Even if you qualify your assertion with "data of arbitrary size unknown at build time", I still disagree. Using the untrusted stack allows for trickery when a debugger is involved, other than that I see no advantages over allocating virtual memory and handing the pointer to the enclave at launch time. Sure, it requires a few more lines of code to setup, but it's literally ~20 LoC out of thousands required to sign, build and launch an enclave, but it doesn't require playing games with the stack. Not to mention that the entire concept of using the untrusted stack is based on the assumption that the enclave is making ocalls, e.g. stateless enclaves or libraries that use a message queue have zero need/benefit for using the untrusted stack. > and is in fact being used for that purpose by almost all existing enclaves > to date. That's a bit misleading, since almost all existing enclaves are built against Intel's SDK, which just so happens to unconditionally use the untrusted stack. It's not like all enclave developers made a concious decision to use the untrusted stack. If Intel rewrote the SDK to use a different method then one could argue that the new approach is the most common method of passing data. > Given the expectation that this API will be used by all future SGX > application, it looks unwise to ban the most convenient and commonly > used approach for data exchange. > > Given an enclave can touch everything (registers and memory) of the > enclosing process, it's reasonable to restrict the enclave by means > of "calling convention" to allow the enclosing process to retain its > context. And for that purpose, SGX ISA does offer 2 registers (i.e. > RSP and RBP) for applications to choose. Instead of preserving RSP, > I'd prefer RBP, which will end up with more flexibility in all SGX > applications in future. I disagree that the SGX ISA intends for applications to choose between preserving RSP and RBP, e.g. the SDM description of SSA.UR{B,S}P states: Non-Enclave (outside) {RBP,stack} pointer. Saved by EENTER, restored on AEX. To me, the "Saved/restored" wording implies that URBP and URSP should *never* be touched by the enclave. Sure, the proposed vDSO interface doesn't require RBP to be preserved, but only because the goal was to deviate from hardware as little as possible, not because anyone wants to encourage enclaves to muck with RBP.