Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp294677pxb; Wed, 14 Apr 2021 15:53:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxX0tjCMrb1A1FVMJqzw8CipC7yarrwlIQP6r4rSEpZBS4N0+qWosiK+ohhGvMRFxc+/3d2 X-Received: by 2002:a63:af5d:: with SMTP id s29mr597174pgo.220.1618440818796; Wed, 14 Apr 2021 15:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618440818; cv=none; d=google.com; s=arc-20160816; b=G4abisTYjV8ChRk8xg4oQkoH4I29yC/8MW3u7Lg8AMoZ06JCqNFbkHhy/vTD4olCGG EcW6ZV9KCQxLC/fKorysCh0W43jp13lAXe/VVWgPRjxBPhvFS1W0tRWu3QTKTfcQoVaN LakwqnjC+p4P5Y0xVhlYuiLPhZibcXlubQJtwcxleNYOz4PizYI0fngLtDjpf22DkBUU YtDx3+JYVqCFQ30iejo1z9Jv+26ql+P4C4y+A1mOdmZyKRBlayxflOXeGYpor9+v84dd H3LypD1XGFxF7/0P/pxY613copVXLhYJ6W0KZEx7Loa4mkB1PEY3UdyT5jhWMkaIV110 NhkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dlhOir+nK9EgIrUXLnnN0rdl/1nRLS/7RZBbWdcASls=; b=aQBzqv7+dhNWNwT+wbeeioXSK4mGvghn0kAbN4mQh9Hm50fluvxUT1o7J9XahMjo7o DwV/IMMFqX50qT+92i+sLEDpOWOto3bFuUZiADepBjbiedVdLSe86dMdrISs634yiQtm U7FqTVOwRqSQOsqvaGjAPNy8jtoTsysqlM+INzfyYEAn4y9y0WbqQ8+p5VMU/VfxDHD3 udS0UECS75+2cvTfzkpKN/eb9qBKtRLLOcluf8LhHVJHLbTS4Yr8uPMF2IXN3HDioF4b wEJCZI4pSqHl2wEq+54W08B9hArbP6QdRsXAiTu01mgNeyVFcsppyzt70KaLhsuA9qD7 L1iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="I95/Mfzq"; 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 z24si1043136pjq.11.2021.04.14.15.53.26; Wed, 14 Apr 2021 15:53:38 -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=k20201202 header.b="I95/Mfzq"; 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 S234444AbhDNKxK (ORCPT + 99 others); Wed, 14 Apr 2021 06:53:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:37786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232196AbhDNKxJ (ORCPT ); Wed, 14 Apr 2021 06:53:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 278C56128E; Wed, 14 Apr 2021 10:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618397568; bh=0c0DKD6R3exJ1ALKp0ZnNiJTJMmJ82AFfIDhibBbQjs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I95/MfzqPZi2LAE9J5fOO9WSTnWTyfy69u8Wc3KSUCHKmGBnsSLoNdW77oZjEhZjX uchIecdDVJ3c/lgVimaE/bb9MGQrGdrdmcMwEWo7QQGN2LBgSaZzVvDn5mxww96L3X SerzpWT62JdHYGTy5E4UHQmX0eLLw1fjYioBRZHQaeA+VZbbMpjULZvzcQCMix2VaP kMe+XIkHFIWAY26ow7MO2mBfTAqrr1/JdsfDIxy+298L774pN7pPizaJzV4TlOA+9d 0eIebquwDJBQmkzkJERq8BpUS8cRSITFDLwA7kqPJj1xSY9NwpjDx74O52mg5ySx5J Rh0g6QwlpFmBQ== Date: Wed, 14 Apr 2021 13:52:45 +0300 From: Jarkko Sakkinen To: Raoul Strackx Cc: Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 0/3] x86/sgx: eextend ioctl Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 12, 2021 at 10:59:56AM +0200, Raoul Strackx wrote: > Creation of an SGX enclave consists of three steps. First, a new enclave > environment is created by the ECREATE leaf function. Some enclave settings > are specified at this step by passing an SGX Enclave Control Structure > (SECS) that contains the enclave MRENCLAVE, MRSIGNER, etc. This > instruction also starts a cryptographic log of the enclave being built. > (This log should eventually result in the MRENCLAVE.) Second, pages are > added to the enclave. The EADD leaf function copies 4KB data to an empty > EPC page. The cryptographic log records (among other properties) the > location and access rights of the page being added. It _does not_ include > an entry of the page content. When the enclave writer wishes to ensure the > content of (a part of) the enclave page as well, she must use the EEXTEND > leaf function. Extending the enclave cryptographic log can only be done > per 256 bytes. Extending the log with a full 4K page thus requires 16 > invocations of the EEXTEND leaf function. It is however up to the enclave > developer to decide if and how enclave memory is added to the > cryptographic log. EEXTEND functions may be issued only for relevant parts > of an enclave page, may happen only after all pages have been added, and > so on. Finally, the enclave is finalized by the EINIT leaf function. Any > new invocations of the EADD or EEXTEND leaf functions will result in a > fault. With EINIT a number of checks are performed as well. The > cryptographic hash of the final cryptographic log is compared to the > MRENCLAVE field of the SECS structure passed to the ECREATE leaf function > (see step one). The signature (MRSIGNER) over this MRENCLAVE is verified > as well. When all checks pass, the enclave loading is complete and it > enters the executable state. Who do you expect to read this paragraph, seriously? > The SGX driver currently only supports extending the cryptographic log as > part of the EADD leaf function and _must_ cover complete 4K pages. > Enclaves not constructed within these constraints, currently cannot be > loaded on the Linux platform. Trying to do so will result in a different > cryptographic log; the MRENCLAVE specified at enclave creation time will > not match the cryptographic log kept by the processor and EINIT will fail. > This poses practical problems: > - The current driver does not fully support all possible SGXv1 enclaves. > It creates a separation between enclaves that run everywhere and > enclaves that run everywhere, except on Linux. This includes enclaves > already in use on other systems today. > - It limits optimizations loaders are able to perform. For example, by > only measuring relevant parts of enclave pages, load time can be > minimized. > > This patch set adds a new ioctl to enable userspace to execute EEXTEND > leaf functions per 256 bytes of enclave memory. With this patch in place, > Linux will be able to build all valid SGXv1 enclaves. > > See additional discussion at: > https://lore.kernel.org/linux-sgx/20200220221038.GA26618@linux.intel.com/ > T/#m93597f53d354201e72e26d93a968f167fcdf5930 > > > Raoul Strackx (3): > x86/sgx: Adding eextend ioctl > x86/sgx: Fix compatibility issue with OPENSSL < 1.1.0 > x86/sgx: eextend ioctl selftest > > arch/x86/include/uapi/asm/sgx.h | 11 +++++ > arch/x86/kernel/cpu/sgx/ioctl.c | 81 ++++++++++++++++++++++++++++----- > tools/testing/selftests/sgx/defines.h | 1 + > tools/testing/selftests/sgx/load.c | 57 +++++++++++++++++++---- > tools/testing/selftests/sgx/main.h | 1 + > tools/testing/selftests/sgx/sigstruct.c | 43 ++++++++--------- > 6 files changed, 154 insertions(+), 40 deletions(-) > > -- > 2.7.4 > > /Jarkko