[Pal/Linux-SGX] Add support for the DCAP SGX driver versions 1.5-

The DCAP SGX driver works with Flexible Launch Control (FLC) enabled
SGX processors. The FLC feature allows to use arbitrary non-Intel
Launch Enclaves and thus makes the EINITTOKEN struct unnecessary.
This commit skips the step of obtaining the EINITTOKEN struct from
the Launch enclave and instead allows to create a dummy token for
DCAP- and FLC-enabled SGX systems.
This commit is contained in:
Chihyun Song
2020-04-06 16:14:43 -07:00
committed by Dmitrii Kuvaiskii
parent dc0cbd0b68
commit 383076f2b4
9 changed files with 84 additions and 10 deletions
+8 -2
View File
@@ -86,12 +86,18 @@ Prerequisites
2. Install the Intel SGX SDK and driver
The Intel SGX Linux SDK is required to compile and run Graphene on SGX.
Download and install it from the official Intel GitHub repositories:
The Intel SGX Linux SDK and the Intel SGX driver are required to compile and
run Graphene on SGX. Download and install them from the official Intel
GitHub repositories:
- <https://github.com/01org/linux-sgx>
- <https://github.com/01org/linux-sgx-driver>
Alternatively, if you want to use the DCAP versions of the SDK and driver,
download and install them from:
- <https://github.com/intel/SGXDataCenterAttestationPrimitives>
3. Build and install the Graphene SGX driver
A Graphene-specific Linux driver must also be installed before running
Graphene in an SGX environment. Simply run the following commands to build
@@ -94,7 +94,9 @@ Prerequisites for Untrusted Host
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To run the applications on Intel SGX with Graphene-SGX, the host must have an SGX-enabled CPU, with
Intel SGX SDK and the SGX driver installed. Please download and install the SDK and the driver from:
<https://github.com/01org/linux-sgx> and <https://github.com/01org/linux-sgx-driver>.
<https://github.com/01org/linux-sgx> and <https://github.com/01org/linux-sgx-driver>. If you want
to use the DCAP SDK and driver, please download and install from:
<https://github.com/intel/SGXDataCenterAttestationPrimitives>.
A Graphene SGX driver (gsgx) also needs to be installed on the untrusted host. Simply run the
following commands to build the driver::
+7 -4
View File
@@ -34,19 +34,22 @@ SGX Quick Start
Before you run any applications in Graphene-SGX, please make sure that Intel SGX
SDK and the SGX driver are installed on your system. We recommend using Intel
SGX SDK and the SGX driver no older than version 2.1.
SGX SDK and the SGX driver no older than version 1.9 (or the DCAP SGX SDK and
the driver version 1.4/1.5).
If Intel SGX SDK and the SGX driver are not installed, please follow the READMEs
in <https://github.com/01org/linux-sgx> and
<https://github.com/01org/linux-sgx-driver> to download and install them.
If you want to use the DCAP SDK and driver, please follow the READMEs in
<https://github.com/intel/SGXDataCenterAttestationPrimitives>.
1. Ensure That Intel SGX is Enabled on Your Platform::
lsmod | grep isgx
lsmod | grep sgx
ps ax | grep [a]esm_service
The first command should list :command:`isgx` and the second command should list
the process status of :command:`aesm_service`.
The first command should list :command:`isgx` (or :command:`sgx`) and the
second command should list the process status of :command:`aesm_service`.
2. Clone the Repository and Set the Home Directory of Graphene::
+3
View File
@@ -37,6 +37,9 @@ pipeline {
ISGX_DRIVER_PATH=/opt/intel/linux-sgx-driver ISGX_DRIVER_VERSION=1.9 make
'''
sh '''
CFLAGS="-DSGX_DCAP" make -j 8 SGX=1 WERROR=1
CFLAGS="-DSGX_DCAP" make -j 8 SGX=1 clean
make -j 8 SGX=1 WERROR=1
make -j 8 SGX=1 WERROR=1 test
'''
+1 -1
View File
@@ -3,7 +3,7 @@ include ../../Scripts/Makefile.rules
include ../src/host/$(PAL_HOST)/Makefile.am
CFLAGS += -I../include/lib -I../include -I../include/pal -I../include/host/$(PAL_HOST) \
-Icrypto/mbedtls/include -Icrypto/mbedtls/crypto/include
-I../src/host/$(PAL_HOST) -Icrypto/mbedtls/include -Icrypto/mbedtls/crypto/include
CRYPTO_PROVIDER ?= mbedtls
@@ -10,6 +10,13 @@
#include "sgx_arch.h"
#include "sgx_tls.h"
/* sgx.h header from the Intel SGX driver assumes that `__packed` macro was defined */
#ifndef __packed
#define __packed __attribute__((packed))
#endif
#include "sgx.h"
#undef __packed
#include <generated-offsets-build.h>
void dummy(void)
@@ -169,4 +176,9 @@ void dummy(void)
OFFSET_T(XSAVE_HEADER_OFFSET, PAL_XREGS_STATE, header);
DEFINE(PAL_XSTATE_ALIGN, PAL_XSTATE_ALIGN);
DEFINE(PAL_FP_XSTATE_MAGIC2_SIZE, PAL_FP_XSTATE_MAGIC2_SIZE);
/* SGX_DCAP */
#ifdef SGX_DCAP
DEFINE(SGX_DCAP, SGX_DCAP);
#endif
}
+5
View File
@@ -285,6 +285,9 @@ int init_enclave(sgx_arch_secs_t * secs,
sgx_arch_enclave_css_t * sigstruct,
sgx_arch_token_t * token)
{
#ifdef SGX_DCAP
__UNUSED(token);
#endif
unsigned long enclave_valid_addr =
secs->base + secs->size - g_page_size;
@@ -298,7 +301,9 @@ int init_enclave(sgx_arch_secs_t * secs,
struct sgx_enclave_init param = {
.addr = enclave_valid_addr,
.sigstruct = (uint64_t) sigstruct,
#ifndef SGX_DCAP
.einittoken = (uint64_t) token,
#endif
};
int ret = INLINE_SYSCALL(ioctl, 3, isgx_device, SGX_IOC_ENCLAVE_INIT,
&param);
@@ -2,6 +2,7 @@
# pylint: disable=invalid-name
import argparse
import array
import os
import socket
import struct
@@ -76,6 +77,9 @@ def read_sigstruct(sig):
return attr
def is_dcap():
""" Check if we're dealing with DCAP driver."""
return hasattr(offs, 'SGX_DCAP')
def connect_aesmd(attr):
"""Connect with AESMD."""
@@ -118,6 +122,41 @@ def connect_aesmd(attr):
return ret_msg.ret.token
def create_dummy_token(attr):
""" Create dummy token with a few fields initialized with real values
and others with a placeholder ('\0')"""
token = array.array('B', b'\0'*304)
# format: field_name -> tuple (offset, type_with_size)
fields = dict()
fields['valid'] = (0, "<I")
fields['reserved'] = (4, "44B")
fields['flags'] = (48, "<Q") # attrs
fields['xfrms'] = (56, "<Q") # attrs
fields['mrenclave'] = (64, "32B")
fields['reserved2'] = (96, "32B")
fields['mrsigner'] = (128, "32B")
fields['reserved3'] = (160, "32B")
fields['cpusvnle'] = (192, "<2Q")
fields['isvprodidle'] = (208, "<H")
fields['isvsvnle'] = (210, "<H")
fields['reserved4'] = (212, "24B")
fields['misc_mask'] = (236, "<I")
fields['flagmask'] = (240, "<Q") # attrmask
fields['xfrmmask'] = (248, "<Q") # attrmask
fields['keyid'] = (256, "32B")
fields['mac'] = (288, "16B")
# fields read by create_enclave() in sgx_framework.c
actual_fields = ['flags', 'xfrms', 'misc_mask']
for key in actual_fields:
field = fields[key]
field_size = struct.Struct(field[1]).size
token[field[0]:field[0] + field_size] = array.array('B', attr[key])
return token
argparser = argparse.ArgumentParser()
argparser.add_argument('--sig', '-sig', metavar='SIGNATURE',
@@ -148,7 +187,11 @@ def main(args=None):
print(" signature: %s..." % attr['signature'].hex()[:32])
print(" date: %d-%02d-%02d" % (attr['year'], attr['month'], attr['day']))
token = connect_aesmd(attr)
if is_dcap():
token = create_dummy_token(attr)
else:
token = connect_aesmd(attr)
args.output.write(token)
return 0