Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp987338imu; Fri, 7 Dec 2018 12:10:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/V5gaH3Di8Axq7JHBIu7TzvzJO1jl569WsGaeALsSi+FFjOs5gdB0Sw7phgJpT/s/U6Frcg X-Received: by 2002:a17:902:292b:: with SMTP id g40mr949805plb.82.1544213430141; Fri, 07 Dec 2018 12:10:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544213430; cv=none; d=google.com; s=arc-20160816; b=LfXh5pS5URnm/lgRmPOpqhvPIJmrSQO4Twi49v39fKdzuv6BAoXx86BBGdrb2wH59G u6uPLRpgoLyiIRfKFsilCQb3ocwIE4MMDR8jUz/M5zsYWRYCR0ON8fG20iwil0U9n41J hmaHjOrtsaczyW3Peb4r9L7tGqQErMxHy6DW/cPbLB0N6tSPOQ9dt8TS/Ihkv2wH9mjL Xts9xsrfEQ9lb30DPliBHUHNMkuzXcff8sMBf1rERABHVGgs+kaEVMf+lSpf3D46DoKG McmJzV89/FQiv0iiVAqR+KxWKmCUIuwZxtB/PWozznsT7Gxx9u73yzot9iPllIjSsNlB u7CQ== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=OLw7c490E6scIamkR+l/yOrUm1suhhGitVpQjmd3QoA=; b=F9rStk3Uc1yyX2fgUyIw6ZCf0Bbjcn1SlI+gmVjMiOvyii4Hlp+R3qJqwbOydswOsW n+jTZRomWbXKeaSlWI3h4qB0Iml93bLBSZzy1Im+eKseFrCmbSvI4Rv6h4POxH/8VfI3 93thkSq+Y/V2EnQg7VZEy9+U4mgROpK2n25zD2ER4n2dzImI16dVwsWOZ95BswadaCI3 uJwAipPKHEOlEaHoF0siNvVpcrWwokNm7oOxjmWZDgILV4WdRaPZjkwcUUFszV61JkQ1 QRkQbh4QpP8Gb09h/dcs0K/cof8C6Mu8MKFYmKQsvKuqTQHevwyi0qRDcY6+tob0NTcC oxcw== 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 123si3987561pfx.109.2018.12.07.12.10.14; Fri, 07 Dec 2018 12:10:30 -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 S1726090AbeLGUJh (ORCPT + 99 others); Fri, 7 Dec 2018 15:09:37 -0500 Received: from mga01.intel.com ([192.55.52.88]:23490 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726008AbeLGUJg (ORCPT ); Fri, 7 Dec 2018 15:09:36 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Dec 2018 12:09:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,327,1539673200"; d="scan'208";a="107860138" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by fmsmga008.fm.intel.com with ESMTP; 07 Dec 2018 12:09:35 -0800 Date: Fri, 7 Dec 2018 12:09:35 -0800 From: Sean Christopherson To: Andy Lutomirski Cc: Andy 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@linux.intel.com, 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: <20181207200935.GE10404@linux.intel.com> References: <20181206221922.31012-1-sean.j.christopherson@intel.com> <20181206221922.31012-5-sean.j.christopherson@intel.com> <20181207165145.GB10404@linux.intel.com> <20181207190257.GC10404@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 Fri, Dec 07, 2018 at 11:23:10AM -0800, Andy Lutomirski wrote: > > > On Dec 7, 2018, at 11:02 AM, Sean Christopherson wrote: > > > >> On Fri, Dec 07, 2018 at 09:56:09AM -0800, Andy Lutomirski wrote: > >> On Fri, Dec 7, 2018 at 8:51 AM Sean Christopherson > >> wrote: > >>> I like that the exit handler allows userspace to trap/panic with the full > >>> call stack in place, and in a dedicated path, i.e. outside of the basic > >>> enter/exit code. An exit handler probably doesn't fundamentally change > >>> what userspace can do with respect to debugging/reporting, but I think > >>> it would actually simplify some userspace implementations, e.g. I'd use > >>> it in my tests like so: > >>> > >>> long fault_handler(struct sgx_enclave_exit_info *exit_info, void *tcs, void *priv) > >>> { > >>> if (exit_info->leaf == SGX_EEXIT) > >>> return 0; > >>> > >>> > >>> } > >>> > >> > >> Hmm. That't not totally silly, although you could accomplish almost > >> the same thing by wrapping the vDSO helper in another function. > > > > True, but I think there's value in having the option to intercept an > > exception at the exact(ish) point of failure, without having to return > > up the stack. > > > > The enclave has full access to the process' memory space, including the > > untrsuted stack. It's not too far fetched to envision a scenario where > > the enclave corrupts the stack even if the enclave isn't intentionally > > using the stack, e.g. the host passes in variable that a points at the > > stack instead of whatever memory is supposed to be shared between the > > enclave and host. It'd be nice to have the ability to triage something > > like that without having to e.g. configure breakpoints on the stack. > > Ah, I see. You’re saying that, if the non-enclave stare is corrupted such > that RIP is okay and RSP still points somewhere reasonable but the return > address is garbage, then we can at least get to the fault handler and print > something? Yep. Even for something more subtle like GPR corruption it could dump the entire call stack before attempting to return back up. > This only works if the fault handler pointer itself is okay, though, which > somewhat limits the usefulness, given that its pointer is quite likely to > be on the stack very close to the return address. Yeah, it's not a silver bullet by any means, but it does seem useful for at least some scenarios. Even exploding when invoking the handler instead of at a random point might prove useful, e.g. "calling my exit handler exploded, maybe my enclave corrupted the stack!". > I really wish the ENCLU instruction had seen fit to preserve some registers. Speaking of preserving registers, the asm blob needs to mark RBX as clobbered since it's modified for EEXIT.