Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2353855imu; Tue, 6 Nov 2018 13:08:50 -0800 (PST) X-Google-Smtp-Source: AJdET5dbPMXty+hzJQv8rkSPEwABlX92xdB89QMAGUTiEhw8W5IyKbeGspQGNCyK/D3kLGZsgIVC X-Received: by 2002:a63:594d:: with SMTP id j13mr17467971pgm.210.1541538530036; Tue, 06 Nov 2018 13:08:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541538530; cv=none; d=google.com; s=arc-20160816; b=cZ8tv2F9yBriyS0z9hFF6fIG8kqQuwHLn2jxTR0LtFnGCkroOa44SRPLB43v3r/4Ur VmoPfYu6rCrpoV7+qmU5SZdFCtx3NqW6+tcPoV8n3mR2g9AJZlQVV3OeuiKf1+rxhS9v q7la8b3UBUdN90Cr9w4LsiwnVXspZycETMIVi9hhdI8AKu/M/rKSUed2UjE9ycC8RjYM lhd5ganms9/4GwSdNaY3I+wEeR05HJH0rXuD/pJEQsUjAiIp1n3ZVnzaPP1SEnf0PrcL N7mwsr6rvMnemq9fyTqxYzGjJjHlryI/9SHhFtVmnl2IXNsdjQg7ME5/0U6Pe5t/bwIm JerA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=j/p4Rkoi1f8osFSfUldINn+hQAee4qZ2uYwdF+ITjj4=; b=KiOPS7YuMMx4KyD/bF3I7L72TQWn353kPYvttrAIPCZx+Qg/X6IbRCEXCnurwGmXij tjIPkhwe+xtw8y7zXimY7TEWy2hjXm9K9I22SRq3TwAGExhMPnDNjEDKoddmCASAL9YF dDZPqIBw1iXC7kgJ1ydGJbyVSshlCOfG2z/pVHQbi26lX5rikJ2TnQdkCYgaLhCi7xvx pgWrtZuWD2T5Pmq3vWFnk4OiP+UDrI3zIze1S+7ZKUvs6SvcCRVGvQETM2rf0BpAUrGI Ql0sBmWmwi8fDVIpUF723AtNxZZ+4ygEjI2ORhO3m5xpNvaOCzV22HewSCMCAQW5zS39 0aQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=04IKQHjy; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l22-v6si50794792pfj.188.2018.11.06.13.08.34; Tue, 06 Nov 2018 13:08:49 -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=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=04IKQHjy; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388801AbeKGGfF (ORCPT + 99 others); Wed, 7 Nov 2018 01:35:05 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43545 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388387AbeKGGfF (ORCPT ); Wed, 7 Nov 2018 01:35:05 -0500 Received: by mail-pl1-f193.google.com with SMTP id g59-v6so6781830plb.10 for ; Tue, 06 Nov 2018 13:07:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=j/p4Rkoi1f8osFSfUldINn+hQAee4qZ2uYwdF+ITjj4=; b=04IKQHjye1aJ6ChMu0ak3em2+V9j5vjNQHj3zO+hBaQHNFVCWrBKOocwI6WeAqW4/Z daGsDMCnPyebmeMXiRWbN59xEDjI0fuGBcC+793l9jBeOvXAJTmi0od4SpQESmSH71or c/aYANAkWrsxUt9SCPfesKFb0fy50CSuPQOetH5iw4QLXLn22U7fhXzhpf407Az6NFV+ 0TKqTib/aff76vlt8iKwVaFYNsETXcJVR++GtavggEO+a85wulAwGJ7hS186IoRViED9 WjDwR21nYqsJpGnoMJhGLjjMDb+EEKceKFmhoywYQ934un6tWOfI1xtnyKe4vAXeTuaS VMAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=j/p4Rkoi1f8osFSfUldINn+hQAee4qZ2uYwdF+ITjj4=; b=Ihil27bfjMZaJO5RdouFMf43WHEaH1gh/+8XkcjlMc59x3M8F1qPxjCPGOfRP8YyP7 9fn9xrPlXxjbrBA1pzxEvUHNvseSjY5UJvKqtUl8JSWkYhf59UmXhHqWlEHnai0wqUR0 FqeTkm1grEJL5DBRb+W2OJ8nkXZWaKxiSsoTEJjhXpzOF6lRsNmHm3KIqplYff2KXOsZ trRV9cpK0lh4IcdTQlv/grqkJ6OE8SVfxwcikVFgXLlY4hEiiuBOaBunJm0NWAitPivp Z0au3uvrnwn2xZWxR4k3OX9p16tQUouu0JkGPqXaPJIcbvXT9kxB6Kv+yetTdkmpL/zn 4f6Q== X-Gm-Message-State: AGRZ1gJS/rdlwmE4zBG+BpUJEuH/J8Cq6RoJ2f0pg1uWmjpm+WCXT6d4 lpG/Tm6psMUJb/mTqYc5U82cXA== X-Received: by 2002:a17:902:4523:: with SMTP id m32-v6mr4461946pld.276.1541538476331; Tue, 06 Nov 2018 13:07:56 -0800 (PST) Received: from ?IPv6:2601:646:c200:7429:8c77:2d31:8ab8:32d8? ([2601:646:c200:7429:8c77:2d31:8ab8:32d8]) by smtp.gmail.com with ESMTPSA id b11-v6sm36889995pgi.10.2018.11.06.13.07.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 13:07:55 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: RFC: userspace exception fixups From: Andy Lutomirski X-Mailer: iPhone Mail (16A404) In-Reply-To: <209cf4a5-eda9-2495-539f-fed22252cf02@intel.com> Date: Tue, 6 Nov 2018 13:07:54 -0800 Cc: Andy Lutomirski , "Christopherson, Sean J" , Jann Horn , Linus Torvalds , Rich Felker , Dave Hansen , Jethro Beekman , Jarkko Sakkinen , Florian Weimer , Linux API , X86 ML , linux-arch , LKML , Peter Zijlstra , nhorman@redhat.com, npmccallum@redhat.com, "Ayoun, Serge" , shay.katz-zamir@intel.com, linux-sgx@vger.kernel.org, Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Carlos O'Donell , adhemerval.zanella@linaro.org Content-Transfer-Encoding: quoted-printable Message-Id: <9B76E95B-5745-412E-8007-7FAA7F83D6FB@amacapital.net> References: <20181102170627.GD7393@linux.intel.com> <20181102173350.GF7393@linux.intel.com> <20181102182712.GG7393@linux.intel.com> <20181102220437.GI7393@linux.intel.com> <1541518670.7839.31.camel@intel.com> <1541524750.7839.51.camel@intel.com> <22596E35-F5D1-4935-86AB-B510DCA0FABE@amacapital.net> <1C426267-492F-4AE7-8BE8-C7FE278531F9@amacapital.net> <209cf4a5-eda9-2495-539f-fed22252cf02@intel.com> To: Dave Hansen Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Nov 6, 2018, at 1:00 PM, Dave Hansen wrote: >=20 >> On 11/6/18 12:12 PM, Andy Lutomirski wrote: >> True, but what if we have a nasty enclave that writes to memory just >> below SP *before* decrementing SP? >=20 > Yeah, that would be unfortunate. If an enclave did this (roughly): >=20 > 1. EENTER > 2. Hardware sets eenter_hwframe->sp =3D %sp > 3. Enclave runs... wants to do out-call > 4. Enclave sets up parameters: > memcpy(&eenter_hwframe->sp[-offset], arg1, size); > ... > 5. Enclave sets eenter_hwframe->sp -=3D offset >=20 > If we got a signal between 4 and 5, we'd clobber the copy of 'arg1' that > was on the stack. The enclave could easily fix this by moving ->sp first.= >=20 > But, this is one of those "fun" parts of the ABI that I think we need to > talk about. If we do this, we also basically require that the code > which handles asynchronous exits must *not* write to the stack. That's > not hard because it's typically just a single ERESUME instruction, but > it *is* a requirement. >=20 I was assuming that the async exit stuff was completely hidden by the API. T= he AEP code would decide whether the exit got fixed up by the kernel (which m= ay or may not be easy to tell =E2=80=94 can the code even tell without kerne= l help whether it was, say, an IRQ vs #UD?) and then either do ERESUME or ca= use sgx_enter_enclave() to return with an appropriate return value.