Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1066673img; Fri, 22 Mar 2019 15:00:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpy//DFrQyc1Xj6nNaRlp/iC03Tn05PZ81rysEgTztc3uSn25FW/aeTwCVfzBqVr6OB8ja X-Received: by 2002:a63:cf0f:: with SMTP id j15mr11150534pgg.329.1553292000695; Fri, 22 Mar 2019 15:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553292000; cv=none; d=google.com; s=arc-20160816; b=EvhF+uJt2qLr4ZosEb403rehxbKPNctAqjjBFmbh+oTeUmoM/g4Bb+Yl6jh8InjcmA BWWyVXy3n0xGcOSl9B0qhyQoVL6lYZDS8jsaPzPUI2FBMaqiIImsaEFVHHIA2Uf6qxyV hdvR1YjJ+880Hu2w04PqGkWZFgNalyutzPORumnhZNfq29LtBy4hft35YxUvOjoLtfvo SaJX5Cnmng71RmB6BaLgdHPA24d4I8AezpWsjyvnoIUXKljz3Kp4r/7EDvh5EGYoHLO6 3oU5bmu/7Slwma1fzBGsazxZ5sL+a/eonaLq/iZja+S8vAC5PrQ/6Xy8wvTriNIarGTM ciRQ== 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=OwVCKhG8BXBJE3LvXdiejQDNkl6B0dZKFHmeV3ko1Go=; b=Ka7iczqj+WqHole4EWXViIJ1BlOAuu8MKSI1MV3tJt1P+EJSXLZNWAxsTKrsI4kbAi qhlK67k4K+7+QOFR27i6n9XLHyIrk5uczyKHxLJq/NdXh37vDVI8v97xNkBpvXxEttQM /wYEQ742TtwYvxZkp9YFtWX3iIOWTID6zge9u8PdNcv+4kAvpTt72h7TJOomj1zc1GKT zgyndPm71FOEEBzM5i/iJ95sSTmdb5FDU5MqYg/nokp598tTSSPKTxajMlDSjNi27gC4 42r+RFZz7yUjCTx+N8z6QU3IhdMD/HcTDZtNXu/LMOPH9ICwzE3CpZUGhT6Qm6Jbvwp7 gkCQ== 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 32si672994pgz.259.2019.03.22.14.59.45; Fri, 22 Mar 2019 15:00:00 -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 S1727733AbfCVV7F (ORCPT + 99 others); Fri, 22 Mar 2019 17:59:05 -0400 Received: from mga03.intel.com ([134.134.136.65]:13513 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727440AbfCVV7F (ORCPT ); Fri, 22 Mar 2019 17:59:05 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Mar 2019 14:59:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,256,1549958400"; d="scan'208";a="144434603" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.181]) by orsmga002.jf.intel.com with ESMTP; 22 Mar 2019 14:59:03 -0700 Date: Fri, 22 Mar 2019 14:59:03 -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: <20190322215903.GE12666@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> <20190320191318.GF30469@linux.intel.com> <960B34DE67B9E140824F1DCDEC400C0F4E85C5AB@ORSMSX116.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <960B34DE67B9E140824F1DCDEC400C0F4E85C5AB@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 01:38:04PM -0700, Xing, Cedric wrote: > > > 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. > > Which is the most convenient approach is always dependent on data size and/or even how the data is produced/consumed. It's kind of a spectrum and we're just talking in the sense of probability. You are right that "inarguably" is arguable if the buffer is small enough to fit in registers, and the producer/consumer also has access to registers. > > > > > 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. > > I'm NOT ruling out your approach. > > And like you said, the untrusted stack enables certain trickery that helps > debugging and also simplifies enclaves (even just a little). Then why are > you trying to rule that out? Because of 9 LOC in vDSO? Although its just 9 LOC, consider its impact on someone who is looking at the kernel's SGX support for the first time. Questions they may have when looking at the vDSO code/documentation: - What's an exit handler? - Why is an exit handler optional? Don't I always want to handle exits? - What value should my exit handler return? - What should my exit handler do if it detects an error? - Why would I want to preserve %rbp and not %rsp? - Isn't it insecure to use the untrusted stack in my enclave? AFAIK, the only reason to preserve %rbp instead of %rsp, i.e. support an "exit handler" callback, is to be able to implement an o-call scheme using the untrusted stack to pass data. Every idea I came up with for using the callback, e.g. logging, handling stack corruptiong, testing hooks, etc... was at worst no more difficult to implement when using a barebones vDSO. So, given the choice between a) documenting and maintaining all the baggage that comes with the exit handler and b) saying "go use signals", I chose option b.