Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1064499imu; Tue, 11 Dec 2018 12:05:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/UwndaAw/KBxIxDdaDyw4r2yGJ/o1RgzU2xiTGJ5dbXS/uvtnGeOt5sKF0cN5A+XZhY00Mn X-Received: by 2002:a17:902:2862:: with SMTP id e89mr17558799plb.158.1544558750874; Tue, 11 Dec 2018 12:05:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544558750; cv=none; d=google.com; s=arc-20160816; b=O9DwpAgphkRzOdhjA26VqVcXTjXxATDNe0/MOhi/rHVONQx/04ibirRAid2ke+K498 08RPV/zIJdcZxR//OQZ5eMwEaRxyBrRIjoH+96sU8NlkRMV/3ra2uXoi3sSy6oANnELL 7/NPjScTaCuCF/Usze3QCKk223Gu+3BneJBxcAIgvj28wjNkQBYzeUDY8tlm5+sUFrF8 eBPsXwsAdLAFZUp+KcO+1p8s3SdYO0Rm1NulzbrriUULyiZww3FqsOlEPL6Db1N4fgfA xa6FrHXqx5EsZCAVrRhE8SwN4sMD8KhasZ4znZVA5/SeW69IWMKKqe5xzOkF5uydTnbO sL0g== 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=wwDQkTWYbK3t1iaXcn1U5hxVRVkL+8fT/uJHIxN9Mbs=; b=CFoPOOpWR+Qib/1OWxdRJ9Fs+0QVAB3eXyL7YD5w8zMrvMfIV9nc2eLJHAdrP6c69U MGiQveGi0+0nGAP7eya7aMTQgPN5exCITX2k1Me2ndc1sVBibFr0P8YGSv+3D2dSEGvo xZ3Un7LYDVgsCUzboPJVyGlyQmuW3fBh2mAUCZyXvtbgorQjJssdV7rMXgy6F5aZC71X 3LUibnP3yJDANKI4f5DZwUDmi1DbQ5StdQ5byXkQmNFiReQ7ZzR89RyyxAWjpsej9Zhw ZjMWufVyrCiI1QZW5zDhfiHHpJFqrcqciia1HDK/t8B7F8MGnWNlGheFdOQAqv9YHimP FR5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lVJVN7Yn; 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 q14si12158063pgf.47.2018.12.11.12.05.23; Tue, 11 Dec 2018 12:05:50 -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=lVJVN7Yn; 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 S1726211AbeLKUEb (ORCPT + 99 others); Tue, 11 Dec 2018 15:04:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:55828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbeLKUEb (ORCPT ); Tue, 11 Dec 2018 15:04:31 -0500 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 04B7320870 for ; Tue, 11 Dec 2018 20:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544558670; bh=iceCIJ+MOdnemZmdzZgpg+G/tOQaPMTxkFD74NoBchM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lVJVN7Yn138t2ZkHGtkzYmRtwHAPjhugGq8/SDYGjJP+Hcyvr3WyxGQZtAFI6Pise 9dcfj+lUj96mfD6p4LlorR4LVhDbuq9xmTp8xxanOOx78SB7Kf4c539eRrh0F0OZg8 6qQidZ/pBs1Noo3Sbqf3zEU6868nY7PKkkCQL0cU= Received: by mail-wm1-f42.google.com with SMTP id y1so3502894wmi.3 for ; Tue, 11 Dec 2018 12:04:29 -0800 (PST) X-Gm-Message-State: AA+aEWYPOb5pi1DnQcg2luEE+HApiZAbkbzr4EP5r35dQ/0RPPoYUdYO VbyMXiGlCYeVp1XqYBZvZ5RWRKt8OTPxM94oCI2chg== X-Received: by 2002:a1c:b1d5:: with SMTP id a204mr3904123wmf.32.1544558668451; Tue, 11 Dec 2018 12:04:28 -0800 (PST) MIME-Version: 1.0 References: <20181206221922.31012-5-sean.j.christopherson@intel.com> <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> In-Reply-To: <20181211193144.GG14731@linux.intel.com> From: Andy Lutomirski Date: Tue, 11 Dec 2018 12:04:15 -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 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.