Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3330777pxk; Mon, 28 Sep 2020 14:42:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2WovOb54ZDH64Mhr34g9WhXO8z6pVS3Qie6f/S+RH5YxCgtlXJEKV8aXH1FpEUQh0WySb X-Received: by 2002:a17:907:2456:: with SMTP id yw22mr702648ejb.337.1601329350392; Mon, 28 Sep 2020 14:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601329350; cv=none; d=google.com; s=arc-20160816; b=cvF8P6fw2/WM6bYIGZyh2tSrRPQplVTLtKwxqs9TdCoQubpmsYaWnS2MVOm1TLmO9e 2vn3bY+U87ypaQoEibCNS1TyZKVqkE5hx4Au4QBiIBSw0Lre5MmufLxcq+plKJFwEyRD hL0QxZXeLmkSFvW4++Pvp35siZoz/LpVXn80hx7SdGI0Vu6Jwl4//ki1vLcBmlt4ViHj +bvv8qMe08qgvPaeUhMMbKx22ferWTw/kA60cceveab7rxP8NOdy+MW+dVOtgFXayNYB JuYG0QB4/lR/xkNhajuph+YYcbvQOtQhps8cY8EuhdDIDKyFp05h7zBARxzinfcPzcpM HTtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=1KNAHzkmKdGw40iUJcJxY+KN3EyMHT9lJLMBCiNHkHU=; b=hwqH5oOtrrTqJ7iwnMRgBsSCbDGq8AXxJ/anpwq5lL8AhQdGpCnIXYZuMjksGbRIJO unR2ttwRn41Jj8sE7lQx7JIaQeDUcXn3UhIncShrsdFpZBNGmLZ9qZakqwZJh3a/DDBz 0UrPQWG/Hrk/dTqAcgTR6EzmfygfvU1mEobYs6zIs4CGY5xpFinSairUlpWR7eET7N3Q iAy8m3K5PCH37/Et/c4gr2cgZQBdwHs7xNNPa0QApi0Mtprm4RhDb8JIuBLdcravfQPI in2URkt4fudVxd/M7jJP5aJ/7AQLORiW6zX9BfOxW5TDg5sLrcc8yvPKn1kRXfB7JWD9 MAQw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f20si1490580edv.511.2020.09.28.14.42.07; Mon, 28 Sep 2020 14:42:30 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726944AbgI1VlP (ORCPT + 99 others); Mon, 28 Sep 2020 17:41:15 -0400 Received: from mga17.intel.com ([192.55.52.151]:35328 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbgI1VlP (ORCPT ); Mon, 28 Sep 2020 17:41:15 -0400 IronPort-SDR: oX4oF4+CrrUyFzG1ZyRmRKcGI8LLr1Z9uLtj0HLneRecYUJ4SD1ueIW7qbzXNpw9B6xOYa+DxD JZUa5jyMygGQ== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="142085671" X-IronPort-AV: E=Sophos;i="5.77,315,1596524400"; d="scan'208";a="142085671" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 14:41:14 -0700 IronPort-SDR: OTd+iPriw87D2GLviynEY38Vem1m+YTu3mEbExIyscXq0e9DAgdajkULvqSVYb8toZqZ7/2PP5 6NFWt47eW7gw== X-IronPort-AV: E=Sophos;i="5.77,315,1596524400"; d="scan'208";a="488772542" Received: from jlasecki-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.49.78]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 14:41:07 -0700 Date: Tue, 29 Sep 2020 00:41:05 +0300 From: Jarkko Sakkinen To: "H.J. Lu" Cc: Andrew Cooper , the arch/x86 maintainers , linux-sgx@vger.kernel.org, LKML , Sean Christopherson , Andy Lutomirski , Jethro Beekman , Cedric Xing , Andrew Morton , andriy.shevchenko@linux.intel.com, asapek@google.com, Borislav Petkov , chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, Dave Hansen , "Huang, Haitao" , josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, Christian Ludloff , Andy Lutomirski , nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, Thomas Gleixner , yaozhangx@google.com, Yu-cheng Yu Subject: Re: [PATCH v38 21/24] x86/vdso: Implement a vDSO for Intel SGX enclave call Message-ID: <20200928214105.GD2705@linux.intel.com> References: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> <20200915112842.897265-22-jarkko.sakkinen@linux.intel.com> <721ca14e-21df-3df1-7bef-0b00d0ff90c3@citrix.com> <20200928005842.GC6704@linux.intel.com> <85bc15d5-93cd-e332-ae9a-1e1e66e1181d@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 28, 2020 at 11:07:47AM -0700, H.J. Lu wrote: > On Mon, Sep 28, 2020 at 9:44 AM Andrew Cooper wrote: > > > > On 28/09/2020 01:58, Jarkko Sakkinen wrote: > > > On Fri, Sep 25, 2020 at 07:23:59PM +0100, Andrew Cooper wrote: > > >> On 15/09/2020 12:28, Jarkko Sakkinen wrote: > > >>> diff --git a/arch/x86/entry/vdso/vsgx_enter_enclave.S b/arch/x86/entry/vdso/vsgx_enter_enclave.S > > >>> new file mode 100644 > > >>> index 000000000000..adbd59d41517 > > >>> --- /dev/null > > >>> +++ b/arch/x86/entry/vdso/vsgx_enter_enclave.S > > >>> @@ -0,0 +1,157 @@ > > >>> +SYM_FUNC_START(__vdso_sgx_enter_enclave) > > >>> > > >>> +.Lretpoline: > > >>> + call 2f > > >>> +1: pause > > >>> + lfence > > >>> + jmp 1b > > >>> +2: mov %rax, (%rsp) > > >>> + ret > > >> I hate to throw further spanners in the work, but this is not compatible > > >> with CET, and the user shadow stack work in progress. > > > CET goes beyond my expertise. Can you describe, at least rudimentary, > > > how this code is not compatible? > > > > CET Shadow Stacks detect attacks which modify the return address on the > > stack. > > > > Retpoline *is* a ROP gadget. It really does modify the return address > > on the stack, even if its purpose is defensive (vs Spectre v2) rather > > than malicious. > > > > >> Whichever of these two large series lands first is going to inflict > > >> fixing this problem on the other. > > >> > > >> As the vdso text is global (to a first approximation), it must not be a > > >> retpoline if any other process is liable to want to use CET-SS. > > > Why is that? > > > > Because when CET-SS is enabled, the ret will suffer a #CP exception > > (return address on the stack not matching the one recorded in the shadow > > stack), which I presume/hope is wired into SIGSEGV. > > > > Here is the CET compatible retpoline: > > endbr64 > /* Check if shadow stack is in use. NB: R11 is the only usable > scratch register for function calls. */ > xorl %r11d, %r11d > rdsspq %r11 > testq %r11, %r11 > jnz 3f > call 2f > 1: > pause > lfence > jmp 1b > 2: > mov %rax, (%rsp) > ret > 3: > /* Shadow stack is in use. Make the indirect call. */ > call *%rax > ret Right, so I have actually two alternatives: this and boot time patching: https://lkml.org/lkml/2020/9/25/1122 /Jarkko