Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp8237imd; Fri, 2 Nov 2018 16:34:25 -0700 (PDT) X-Google-Smtp-Source: AJdET5c4N+zEgwXySDBDHqW1wWTdsnmohhjwp2aiCDzKrBN4UwJ2VmTPc+KSja3anNU+myHLBnYj X-Received: by 2002:a17:902:9696:: with SMTP id n22-v6mr13678544plp.282.1541201665571; Fri, 02 Nov 2018 16:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541201665; cv=none; d=google.com; s=arc-20160816; b=X28TpwM+HdQBRrN5vyodhZcaSHx74pKOJ3+OPdlmpNwyvfLJJMTUyAL5fdgANQkPpt Cr49IUizj2D7001NMuly8TgjsahbYFWlwUzEalo9P2NBdrc4Xcwyc3Iq/kCQwR0d0JKf s4ky6EvWY2pRc0k7IO6Lc93l6zltXVn+EWupA5vYwJg45Aq5cP/4tnvbw92r9BQRLL6D UgpASCmsyiMp/5PAkEBwPXITS11oiWbhXnPB57cdoFvDb87oYRMSmrP63lF/epxzSlLl jNuXLVdEdsMLPZZcUEIAz7s/6QUmQaql9ANCJmvLxyC4lbYFERvhKb1xzc4MNTMYtJs+ S/+Q== 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=8L0neaP4E9ZQAvEdbubAv5LRw1WiiJEG/T+ZQZ3m1dM=; b=ZSEe03Wm+hqPA7vrWbNEBmEecqRllRO5s1EWFszGp2u8MXkg7wxHFOB4IckWC6L2N/ S5T8mBd3x0PBm5a2r3IjIHgv1r/SiW/KMUCyCKEdFFL1oy4Ei5jDXI4sx+kF7jJfnOph CSBtIgiXLWjaKNRBMM8PhVW/RKTTF8yeWP7Mt6ZXw5pc+mVYxScsovW+mkzee+TjgY7D 6qQyKBdqOc6O98yfzCWmAI2Qg5otW7JL8N81fkG0wcDqx86kGKXfIIov9mLaheGN8cBQ SpKPrwsYqfojQnEDHSG1C39P3mauCGetU5qSC6LXIBLCvyDCN8gpAX0nGtp55RRKKfpV JxxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zhzgU7QS; 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 t76-v6si35027487pgc.485.2018.11.02.16.34.11; Fri, 02 Nov 2018 16:34:25 -0700 (PDT) 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=zhzgU7QS; 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 S1728715AbeKCIl7 (ORCPT + 99 others); Sat, 3 Nov 2018 04:41:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:44208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbeKCIl7 (ORCPT ); Sat, 3 Nov 2018 04:41:59 -0400 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 6079520880 for ; Fri, 2 Nov 2018 23:32:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541201566; bh=4dxCewbtnfxDrWK9IPS49qvQeMRU68tFk5tBneTDDsY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=zhzgU7QSrzSf2prnSRUXgIBdnLOvhN9QSq1dEiz5Tepy+L7PLTUCzt5VLFJMn+GOu bHuJoNXc73Sx/EG9RAgOLHkZX6HaH0XIsjanLPUAFmgFOramoKDjWSsu9uKz0l9Eov sM1CMnC2JuoMrFPZMH4uA9XKdkmO0HHt9tUsLRwA= Received: by mail-wm1-f41.google.com with SMTP id a8-v6so3135702wmf.1 for ; Fri, 02 Nov 2018 16:32:46 -0700 (PDT) X-Gm-Message-State: AGRZ1gKDj+Y1AtGYTQutd3oiilZMmCT+0i+2COoW9JY3t0TN2lQluZSG bajTGKZDZ2+uXEPyabjbIm3ivVpm0D3F0RpomdJp5Q== X-Received: by 2002:a1c:410a:: with SMTP id o10-v6mr10379wma.19.1541201564661; Fri, 02 Nov 2018 16:32:44 -0700 (PDT) MIME-Version: 1.0 References: <20181102163034.GB7393@linux.intel.com> <7050972d-a874-dc08-3214-93e81181da60@intel.com> <20181102170627.GD7393@linux.intel.com> <20181102173350.GF7393@linux.intel.com> <20181102182712.GG7393@linux.intel.com> <20181102220437.GI7393@linux.intel.com> In-Reply-To: From: Andy Lutomirski Date: Fri, 2 Nov 2018 16:32:32 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: RFC: userspace exception fixups To: Jann Horn Cc: "Christopherson, Sean J" , Andrew Lutomirski , Dave Hansen , 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-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 Fri, Nov 2, 2018 at 4:28 PM Jann Horn wrote: > > On Fri, Nov 2, 2018 at 11:04 PM Sean Christopherson > wrote: > > On Fri, Nov 02, 2018 at 08:02:23PM +0100, Jann Horn wrote: > > > On Fri, Nov 2, 2018 at 7:27 PM Sean Christopherson > > > wrote: > > > > On Fri, Nov 02, 2018 at 10:48:38AM -0700, Andy Lutomirski wrote: > > > > > This whole mechanism seems very complicated, and it's not clear > > > > > exactly what behavior user code wants. > > > > > > > > No argument there. That's why I like the approach of dumping the > > > > exception to userspace without trying to do anything intelligent in > > > > the kernel. Userspace can then do whatever it wants AND we don't > > > > have to worry about mucking with stacks. > > > > > > > > One of the hiccups with the VDSO approach is that the enclave may > > > > want to use the untrusted stack, i.e. the stack that has the VDSO's > > > > stack frame. For example, Intel's SDK uses the untrusted stack to > > > > pass parameters for EEXIT, which means an AEX might occur with what > > > > is effectively a bad stack from the VDSO's perspective. > > > > > > What exactly does "uses the untrusted stack to pass parameters for > > > EEXIT" mean? I guess you're saying that the enclave is writing to > > > RSP+[0...some_positive_offset], and the written data needs to be > > > visible to the code outside the enclave afterwards? > > > > As is, they actually do it the other way around, i.e. negative offsets > > relative to the untrusted %RSP. Going into the enclave there is no > > reserved space on the stack. The SDK uses EEXIT like a function call, > > i.e. pushing parameters on the stack and making an call outside of the > > enclave, hence the name out-call. This allows the SDK to handle any > > reasonable out-call without a priori knowledge of the application's > > maximum out-call "size". > > But presumably this is bounded to be at most 128 bytes (the red zone > size), right? Otherwise this would be incompatible with > non-sigaltstack signal delivery. I think Sean is saying that the enclave also updates RSP. One might reasonably wonder how the SDX knows the offset from RSP to the function ID. Presumably using RBP? Anyway, it seems like this is a mess and it's going to be quite hard to do this in the vDSO due to a lack of any sane way to store the return address.