Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3215575pxk; Mon, 28 Sep 2020 11:13:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3owsD7zjn8ZxQ1uf20+USXS/lR/FUYSSc+uaJBpHe9Zeza+Qw2uF4DLLsSrtU50pFh2QS X-Received: by 2002:a05:6402:d09:: with SMTP id eb9mr3143633edb.219.1601316832351; Mon, 28 Sep 2020 11:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601316832; cv=none; d=google.com; s=arc-20160816; b=QLgBol4dg7Lv811/ReqwbS7HXynaBr0PLi634k2BFs2aIzsw+Am9T1tGsxziKlKrIJ r8ATBOyN1vgXcC2HVk5lblu61ZQG4nMzQfd4Duy5ZJIivRiryMGeTaGejnFN1/AXmWnx KHVcYTFYO7RTn7sOEAJVJMf34138s6kWbhR0nH2xz4tOUPsxAJDQifEBJvHLDKFC5Rm2 WZDi9ACnLX/uxHwo95CTY2Gopa3p6/RodFCRoMCRicnT+eleBXkMWA0CkGOtamSugtYl KgRO36ZyK1+ZDugH588n2kKY/CrCFJbetFGKxlp/GJ+G55p92pbnjp8d4g23xL8UGD0B nW7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WPkTUOF8LkcGo8uVJsmwIndiXi5nBa/zBH5QgEx8H1k=; b=XJVPi8kO9qqi49DecQMXLc6YDe6uU+a1K77mT4eD5UiJTIfzd/R7KtTCQpatwIl6xi eglordwszqxeURyDeO/MY6P7Md766Y7NKeHtD7KGelIO83OkRePnupOrTeJMGGUEyrXz oeitgoUMtf3ZLPmtsFeYSufCXR+LaRI3RpecjQYvvJBnHr/xBLoHynIfzmRAkG0rqWcZ 9bmZPvnkhl4OuOtavT6FRz8WYf3AlMHPPBqlemnV6ae/+JCt3tbjsClanhLATxtIrpXR MG12nQ8KZqbly1bP8CoEBM3U9yXhpk4KyfO4zysnhGcQ6Z4/gT+jaFSlKvlQxO1y20Mb q2RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C41JIxN1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f11si1128853edq.528.2020.09.28.11.13.28; Mon, 28 Sep 2020 11:13:52 -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; dkim=pass header.i=@kernel.org header.s=default header.b=C41JIxN1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726597AbgI1SMX (ORCPT + 99 others); Mon, 28 Sep 2020 14:12:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:50054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbgI1SMW (ORCPT ); Mon, 28 Sep 2020 14:12:22 -0400 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A8F1623444 for ; Mon, 28 Sep 2020 18:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601316742; bh=7q1mHjYn8Xp8QKPcJUE7lPaBq/HQxLXaK9sWb404084=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=C41JIxN10W/+7tgrEeaGv7guuVM1WuB/7sSTKC5C5Z1Vv53XxQ6EZEKosLWIcZ5MD vCaJZU7G3x5nCzfuGGjMV8JWEml9Uodltx/OPk8C/73wiDrwM23c5vXcZbvuVFiTyI 3DwQEMHhpQGwggLxL5N7FjiHMCpeaQO4mMtKKz8E= Received: by mail-wr1-f49.google.com with SMTP id c18so2361448wrm.9 for ; Mon, 28 Sep 2020 11:12:21 -0700 (PDT) X-Gm-Message-State: AOAM530DhB9bRA9geHq9EzaQ0LF33k8ER7EWNwFZT4IhGVuozx0SNDLj 2KDIzWJUWKn/4qlPWuWacD8wC3UBUILrZ2ob5U985A== X-Received: by 2002:a5d:5281:: with SMTP id c1mr3016925wrv.184.1601316740096; Mon, 28 Sep 2020 11:12:20 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: From: Andy Lutomirski Date: Mon, 28 Sep 2020 11:12:08 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v38 21/24] x86/vdso: Implement a vDSO for Intel SGX enclave call To: "H.J. Lu" Cc: Andrew Cooper , Jarkko Sakkinen , "the arch/x86 maintainers" , linux-sgx@vger.kernel.org, LKML , Sean Christopherson , Jethro Beekman , Cedric Xing , Andrew Morton , Andy Shevchenko , asapek@google.com, Borislav Petkov , chenalexchen@google.com, Conrad Parker , cyhanish@google.com, Dave Hansen , "Huang, Haitao" , Josh Triplett , "Huang, Kai" , "Svahn, Kai" , Keith Moyer , Christian Ludloff , Andy Lutomirski , Neil Horman , Nathaniel McCallum , Patrick Uiterwijk , David Rientjes , Thomas Gleixner , yaozhangx@google.com, Yu-cheng Yu Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 28, 2020 at 11:08 AM 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 What do we expect user programs to do on CET systems? It would be nice if we could instead ALTERNATIVE this out if X86_FEATURE_SHSTK. --Andy