Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1232397imu; Tue, 11 Dec 2018 15:24:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/XmDjAYyW3dOt0W8+mbDUM/cz20oXizjUrcSX8xWMSsYTJx/2J93y7YLsv8Nrhj9ati1YQu X-Received: by 2002:a17:902:ab84:: with SMTP id f4mr17409624plr.207.1544570643761; Tue, 11 Dec 2018 15:24:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544570643; cv=none; d=google.com; s=arc-20160816; b=hHr5pBB0T/e258xTjHWtKVUFvjkbecRhk2nMPwY2kGUxlsASMTugYFhaCsXxJkwJD9 zcJpvcHE0xpGSXzKpNUbUq7BtzI3m7YQglWQlzsAqEiCuOMJzO/PRqfab8EOzwQQb/+s 7VF5dLrDrwQJsHp2QrDcUDRC3Eppl5nxLzfOzvg+9JCwGhuwiwBZuzepQj5GPkoWv/3f pmN0WX+wSxgyaFwZYqG5wMDynhuhNP3VSnWWALjyUrd5CBEbyZ4r3C7rNnxR4tKeLZpw Zw6+9abFlftb/c+DDZd4FhN2MwE88Jw4f6s8oHkteuu72h7kq+uL9wFB7Db17HwbERqo Ra/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5LlvqE+OakFWILUl5mwKuOeNYJv8pDA7GlJSWscR1/w=; b=elsgAlGSSErLsdGUK6x6Vi7z0IJdzDzGTdJOf6o7obcY145sgBUfdwhZtAdjirGNu8 jNaDCyor0EUEAGhkjUTGSi6QylY9Bq91NghY/gkQw3tWsa0LkPtQ8Ixk5yfJJaCDZhuy B0bs09NCS+oky42WiBmBh9+g0sEC1Fzia13xSJPGOnI4JLwcFzb+ZhnWQ6VbaQbA9vUd mmxNKP4fq/eSd600L/VTPORKNHgRAXBiCy0WAZrB4s/Q0STwDb5pBvttU8y4RkTvuT8T ZeVGbQ080udQg7vdD261NW75vN7nkQ3qz0791ojX+BgScoT1CJKdTZNGfc4ZXiaiCRO8 op/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UBapF1SS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j3si12960052plk.199.2018.12.11.15.23.47; Tue, 11 Dec 2018 15:24:03 -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; dkim=pass header.i=@kernel.org header.s=default header.b=UBapF1SS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726250AbeLKXM3 (ORCPT + 99 others); Tue, 11 Dec 2018 18:12:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:50806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726158AbeLKXM3 (ORCPT ); Tue, 11 Dec 2018 18:12:29 -0500 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 2AD982084C for ; Tue, 11 Dec 2018 23:12:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544569948; bh=OKUSz3fk1wncHnkmLeETn7cUxXQPPoRi88bsW5T7ytQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UBapF1SSlTBjdbIs5S9FQJHfudA8FdaJmDpIWz0kQOwwtCtZSGGGpgUnRSzsCcTyj tpTp0vdRzu6OCUBpwv7S44nCXJk+9nIQmn7uDZ/VjERIJwBSfeViOo/zQqaHK1oNh9 tmygWYZZ7jeQauHpdbw2eC66lBJ4jxlWDN54dnIY= Received: by mail-wr1-f44.google.com with SMTP id b14so15806066wru.12 for ; Tue, 11 Dec 2018 15:12:28 -0800 (PST) X-Gm-Message-State: AA+aEWZUF3WMpR4MAmz7/Y95/ND2E6XUEAvXNYVD024ld10S+eFNJr/T DkN+wjn1ox4rKRf/lN5ny1wolQWvboNxMBeyAW95Wg== X-Received: by 2002:adf:8323:: with SMTP id 32mr14525244wrd.176.1544569946669; Tue, 11 Dec 2018 15:12:26 -0800 (PST) MIME-Version: 1.0 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> <20181211220010.GH14731@linux.intel.com> In-Reply-To: <20181211220010.GH14731@linux.intel.com> From: Andy Lutomirski Date: Tue, 11 Dec 2018 15:12:14 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v2 4/4] x86/vdso: Add __vdso_sgx_enter_enclave() to wrap SGX enclave transitions To: "Christopherson, Sean J" Cc: Andrew Lutomirski , 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" Content-Type: text/plain; charset="UTF-8" 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 2:00 PM Sean Christopherson wrote: > > 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. Fair enough, although the case where we do an EENTER, an AEP, a kernel entry, an IRET, and an ERESUME will be so slow that the CALL+RET seems even less relevant. The EENTER+EEXIT case at least avoids the round trip through x86's amazingly performant exception handling mechanism :)