Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1167359imu; Tue, 11 Dec 2018 14:01:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/VSYmQPq8MaH3JjHxvx0HnUTVnGqm+BIHn4SJMWKpoKOc+JHIgLquRLFXIWPuIbUrVS1J8U X-Received: by 2002:a63:4384:: with SMTP id q126mr15975015pga.160.1544565686305; Tue, 11 Dec 2018 14:01:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544565686; cv=none; d=google.com; s=arc-20160816; b=XNpsUzGMZdd5i6V+EUH6D0s69w8S5oHM8YglyC7oD1C7EfMHkgLZDPBSdyHjQTCaYb E/QHV4/oMkPuSbRfTb8/BKUkSRXhy3yZSMoJ5v4k/rEpBGA8f9FHs6/nAo5fpbnhaQG4 YF3iLiEPLOMnMUHSoG0CGgKAQzMSnJo4DT/3XqeOY6vIm2O+LedWI9rVVSJ+I6QT6Mno 56cSmtxS4AKTrGgJagI2kVHxfZGD3VpvyEdjkayLkG/HShL6AUOKoXVzErT0eAMG3B+E mRUAK7OFtszW8H0L2bhPw5KX/VS7pKDniu1U66uQtzFHLWe0ZOEV8xgiIXxMHzJO9X0l 2/LQ== 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=2EGW2kFeq7u0ifQbddqBE2GU959qWNzA4cOkG3PMMQk=; b=vgqhHEdC9A+wJfCxAT2JUAT6ZcQ5Uyw58ew3sBfl/ZG0QG3gNatKCHsGE7p4moq03J V15jG3MGvZoLdnsv4gqVUdEe7Q0hvHAmBmLQ5PQ6bwwFqfzYiLfnoNH1OqWGupB/iDtQ a6JJ+faLyI7JcDjehxc3Ny2PeBsqSYXD7fRe7cXt5sOPh2QBYPk9KQVCvoq/1ezF7R/8 hfWocCaHXHua37rWHkIr/nLKzFWXHiMPTDfmgMqqV1wAQC1MbTcLJMpnNdZ8FrKh7vRN 6wCl/sPBkeLJaZ7NV1o27cSdYiZVgHxqgnr72jtD2A83plneUeMqqh7Z/7tK2SBFcs1c Ooxg== 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 j11si13191445pgk.265.2018.12.11.14.01.10; Tue, 11 Dec 2018 14:01:26 -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 S1726282AbeLKWAN (ORCPT + 99 others); Tue, 11 Dec 2018 17:00:13 -0500 Received: from mga18.intel.com ([134.134.136.126]:34371 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbeLKWAM (ORCPT ); Tue, 11 Dec 2018 17:00:12 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 14:00:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="106688496" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by fmsmga007.fm.intel.com with ESMTP; 11 Dec 2018 14:00:10 -0800 Date: Tue, 11 Dec 2018 14:00:11 -0800 From: Sean Christopherson To: Andy Lutomirski Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , X86 ML , Dave Hansen , Peter Zijlstra , "H. Peter Anvin" , LKML , Jarkko Sakkinen , Josh Triplett , linux-sgx@vger.kernel.org, Haitao Huang , Jethro Beekman , "Dr. Greg Wettstein" Subject: Re: [RFC PATCH v2 4/4] x86/vdso: Add __vdso_sgx_enter_enclave() to wrap SGX enclave transitions Message-ID: <20181211220010.GH14731@linux.intel.com> References: <20181207165145.GB10404@linux.intel.com> <20181207190257.GC10404@linux.intel.com> <20181207200935.GE10404@linux.intel.com> <4CEB5945-9562-40FA-8CCA-A1675D55B001@amacapital.net> <20181207212649.GG10404@linux.intel.com> <20181211193144.GG14731@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Tue, Dec 11, 2018 at 12:04:15PM -0800, Andy Lutomirski wrote: > On Tue, Dec 11, 2018 at 11:31 AM Sean Christopherson > wrote: > > > > On Fri, Dec 07, 2018 at 03:33:57PM -0800, Andy Lutomirski wrote: > > > On Fri, Dec 7, 2018 at 1:26 PM Sean Christopherson > > > wrote: > > > > > > > > Running a checksum on the stack for every exit doesn't seem like it'd > > > > be worth the effort, especially since this type of bug should be quite > > > > rare, at least in production environments. > > > > > > > > If we want to pursue the checksum idea I think the easiest approach > > > > would be to combine it with an exit_handler and do a simple check on > > > > the handler. It'd be minimal overhead in the fast path and would flag > > > > cases where invoking exit_handle() would explode, while deferring all > > > > other checks to the user. > > > > > > How about this variant? > > > > > > #define MAGIC 0xaaaabbbbccccddddul > > > #define RETADDR_HASH ((unsigned long)__builtin_return_address(0) ^ MAGIC) > > > > > > void foo(void) > > > { > > > volatile unsigned long hash = RETADDR_HASH; > > > > > > /* placeholder for your actual code */ > > > asm volatile ("nop"); > > > > > > if (hash != RETADDR_HASH) > > > asm volatile ("ud2"); > > > } > > > > > > But I have a real argument for dropping exit_handler: in this new age > > > of Spectre, the indirect call is a retpoline, and it's therefore quite > > > slow. > > > > Technically slower, but would the extra CALL+RET pair even be noticeable > > in the grand scheme of SGX? > > But it's CALL, CALL, MOV to overwrite return address, intentionally > midpredicted RET, and RET because Spectre. That whole sequence seems > to be several tens of cycles, so it's a lot worse than just CALL+RET. > Whether it's noticeable overall is a fair question, though. I was thinking of the case where the handler re-entered the enclave vs. leaving and re-calling the vDSO, which would be RET+CALL and some other stuff.