Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1986310pxk; Sat, 26 Sep 2020 12:07:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRfFRCsTXTr+NPUbZNekqnh0SqbMccE8Y/EFiSaIRZXqlyHCkw0latssYKvU1MZ0zu6peQ X-Received: by 2002:a17:906:1945:: with SMTP id b5mr8899324eje.102.1601147267923; Sat, 26 Sep 2020 12:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601147267; cv=none; d=google.com; s=arc-20160816; b=l5lA7sjK4Q4VYx0GboqNGm6En5+KVJOQja7LnNStKm2ZPNdst07QniFKUBw02xrc1u eyadHmAwEXyLoUd09GW1ie9LH3XVwBzG/0sH1vY2oNRXjO37S1IA5WHJFjl7EZNQxjD8 hf9Ppxqxze/JFC3JqK1bwnt+1TmXUVWXw6RyEk6wcBvtoRx4s7OzCL9Nu+FjZkMZ0rUK 1ZyC6B353OujUFrUy+P9H2DkOcmia5B+90zGdIUvpntqLMxfhUKAD8azMw0NojbksdZK VIbKtJ8/wYEZUhO5PwRXYTS1bclBFTEHd1M5YLJP5ZZ8F9wsk2WZj/ZeM1sgKAFo4u6n Ejng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mPiOjxnfckCJ2olsYcj2PFAropvvAexoNP5xDA3b6wM=; b=qqFPbXsTfkQ9UbfXxPZb+zGt8lyRwARrIwnd3A++wZ6XTsvvioHdVsSPpQOaUKzHyx 92CmcxYz0pQwuo4NSx6MxO/I8MUzkiL2D1uig1IfwQ1nzUGJZgZgXF2yd8+F0KlG/Fcm MqijuRJWQuCA4XY/4wub174m1ZTYx2JFHr7CxoADlXzfeODDaU/+HZYTre0x88Z9WeLk /ndigK81zXKMpOdoiejxVrKCIutMzt3UNj/MO+UruURAYJLUXwGDGx3Xe52kcqQ9gknN SJU4BzbP1lzX8TttdkP2dQRVWI+b8zVDSyN/Cz2d3k6irwd5XZxUjd11fPdGPhEvpvgL t7gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ChgCopoL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id mc3si4402062ejb.404.2020.09.26.12.07.25; Sat, 26 Sep 2020 12:07:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ChgCopoL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730196AbgIZTFo (ORCPT + 99 others); Sat, 26 Sep 2020 15:05:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:58400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730180AbgIZTFl (ORCPT ); Sat, 26 Sep 2020 15:05:41 -0400 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 2D19C21D7F for ; Sat, 26 Sep 2020 19:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601147140; bh=67bbGqnrZpP+z/jSHSAMocksxZlI1NfOMQdsOtoJVaI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ChgCopoLb3Y/YZxQRtKP3P7EC5wdq6b5F4cmSlAuzG59XIIOjIjtRNOUulCYY54vd 3kCaQItNgjw1DYkzxcTodlUZpfN8ryjKJW55dwrp7EKfSczwSJfOwpUkmGubweE9x9 1BgBPNtsNLBy+FqZai+o11RNt0ooVIQJXGR9hYxw= Received: by mail-wr1-f46.google.com with SMTP id z1so7469160wrt.3 for ; Sat, 26 Sep 2020 12:05:40 -0700 (PDT) X-Gm-Message-State: AOAM530JhkeeqLofXwQrxMkfiub8Bp3XO3TOSlPHxPtblLqzgGIJWS62 MVpaxQtWjnWc5voQlIAKJHxnJF2WXnCV7wgrG5UiEA== X-Received: by 2002:adf:a3c3:: with SMTP id m3mr10501074wrb.70.1601147138798; Sat, 26 Sep 2020 12:05:38 -0700 (PDT) MIME-Version: 1.0 References: <20200925190915.GD31528@linux.intel.com> <20200925222938.GI31528@linux.intel.com> In-Reply-To: <20200925222938.GI31528@linux.intel.com> From: Andy Lutomirski Date: Sat, 26 Sep 2020 12:05:26 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Can we credibly make vdso_sgx_enter_enclave() pleasant to use? To: Sean Christopherson Cc: Andy Lutomirski , Borislav Petkov , Jethro Beekman , Jarkko Sakkinen , Dave Hansen , LKML , Nathaniel McCallum , Cedric Xing , linux-sgx@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 25, 2020 at 3:29 PM Sean Christopherson wrote: > > On Fri, Sep 25, 2020 at 01:20:03PM -0700, Andy Lutomirski wrote: > > On Fri, Sep 25, 2020 at 12:09 PM Sean Christopherson > > wrote: > > > But where would the vDSO get memory for that little data structure? It can't > > > be percpu because the current task can get preempted. It can't be per instance > > > of the vDSO because a single mm/process can have multiple tasks entering an > > > enclave. Per task might work, but how would the vDSO get that info? E.g. > > > via a syscall, which seems like complete overkill? > > > > The stack. > > Duh. > > > The vDSO could, logically, do: > > > > struct sgx_entry_state { > > unsigned long real_rbp; > > unsigned long real_rsp; > > unsigned long orig_fsbase; > > }; > > > > ... > > > > struct sgx_entry_state state; > > state.rbp = rbp; [ hey, this is pseudocode. the real code would be in asm.] > > state.rsp = rsp; > > state.fsbase = __rdfsbase(); > > rbp = arg->rbp; > > > > /* set up all other regs */ > > wrfsbase %rsp > > movq enclave_rsp(%rsp), %rsp > > I think this is where there's a disconnect with what is being requested by the > folks writing run times. IIUC, they want to use the untrusted runtime's stack > to pass params because it doesn't require additional memory allocations and > automagically grows as necessary (obviously to a certain limit). I.e. forcing > the caller to provide an alternative "stack" defeats the purpose of using the > untrusted stack. I personally find this concept rather distasteful. Sure, it might save a couple cycles, but it means that the enclave has hardcoded some kind of assumption about the outside-the-enclave stack. Given that RBP seems reasonably likely to be stable across enclave executions, I suppose we could add a flag and an RSP value in the sgx_enclave_run structure. If set, the vDSO would swap out RSP (but not RBP) with the provided value on entry and record the new RSP on exit. I don't know if this would be useful to people. I do think we need to add at least minimal CFI annotations no matter what we do.