Files
Michał Kowalczyk 3d31f2d18d Introduce one, central manifest, zero-config children and constant MRENCLAVE
This is the next part of the great loader rework, with a lot of breaking changes:

- Complete removal of the "trusted children" thing - now children
  processes can be spawned arbitrarily and from arbitrary mountpoint
  types, without any additional configuration needed.

- There's a new, required option in the manifest: `libos.entrypoint` - it
  specifies the URI to the entry binary in the first process. There's no
  need anymore to name the manifest and the first binary identically.

- On SGX, the main binary is not measured in MRENCLAVE anymore - only
  PAL, LibOS and the manifest are measured. This is enough to bind
  MRENCLAVE to a specific entrypoint user executable if wanted - it
  just has to be mounted as a trusted file.

- All Graphene SGX enclaves have now exactly the same MRENCLAVE. This is
  a hash of a "Graphene stub", which can "fork" into one of two states
  in runtime: initial process or child. The initial process creates a
  new "Graphene namespace" with a clean state, it can also be attested
  remotely (contrary to child processes). The initial process can spawn
  children processes by spawning a Graphene stub and directing it to
  start in the child mode. It then attests it locally, and if
  successful, establishes an encrypted pipe, "connects" to its own
  namespace and treats as trusted (including sending protected files
  key).

- Now, there's only one, central manifest describing the initial state
  of a Graphene instance which can be spawned from it (previously, each
  process required a separate manifest which could have different
  configuration - which wasn't actually supported and didn't make sense
  design-wise). One downside of central manifests is that all processes
  require the same enclave configuration (e.g. size), but that was
  already the case so far because of broken checkpointing code. Also,
  this is only a temporary problem, which will cease to exist after the
  introduction of EDMM.

- `sgx.static_address` was renamed to `sgx.nonpie_binary` and now has to
  be inserted manually by users (`sgx_sign` tools doesn't know about the
  binaries run inside, which can be even provided or generated in
  runtime by the user's workload).

- Caveat: the memory gap for non-PIE executables was removed because it
  requires adding a new option to the manifest to be cleanly
  implemented. This is left for some future loader rework PR.
2021-01-12 19:53:24 +01:00

110 lines
4.4 KiB
Makefile

manifests = $(addsuffix .manifest,label_image)
exec_target = $(manifests)
target = label_image
GRAPHENEDIR ?= ../..
SGX_SIGNER_KEY ?= $(GRAPHENEDIR)/Pal/src/host/Linux-SGX/signer/enclave-key.pem
TF_DIR ?= tensorflow
BAZEL_BIN ?= $(HOME)/bin/bazel
GIT_COMMIT ?= v1.9.0
TAR_SHA256 ?= ffc3151b06823d57b4a408261ba8efe53601563dfe93af0866751d4f6ca5068c
.PHONY: all
all: label_image.manifest
ifeq ($(SGX),1)
all: label_image.manifest.sgx label_image.sig label_image.token
endif
include ../../Scripts/Makefile.configs
$(TF_DIR)/configure:
$(GRAPHENEDIR)/Scripts/download --output tensorflow.tar.gz --sha256 $(TAR_SHA256)\
--url https://github.com/tensorflow/tensorflow/archive/$(GIT_COMMIT).tar.gz
mkdir $(TF_DIR)
tar -C $(TF_DIR) --strip-components=1 -xf tensorflow.tar.gz
$(TF_DIR)/bazel-bin/tensorflow/contrib/lite/examples/label_image/label_image: $(TF_DIR)/configure
cd $(TF_DIR) && $(BAZEL_BIN) build tensorflow/contrib/lite/examples/label_image
label_image: $(TF_DIR)/bazel-bin/tensorflow/contrib/lite/examples/label_image/label_image
cp $^ .
libtensorflow_framework.so: label_image
cp $(TF_DIR)/bazel-bin/tensorflow/libtensorflow_framework.so $@
INCEPTION_HASH=b1a1f91276e48a9ddf0cb0d854f044ebfbf985dc2c2cedceb52b3d668894299a
inception_v3.tflite:
$(GRAPHENEDIR)/Scripts/download --output inception_v3_2018_04_27.tgz --sha256 $(INCEPTION_HASH)\
--url https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz
tar xfz inception_v3_2018_04_27.tgz
labels.txt: $(TF_DIR)/tensorflow/contrib/lite/java/ovic/src/testdata/labels.txt
cp $^ $@
image.bmp: $(TF_DIR)/tensorflow/contrib/lite/examples/label_image/testdata/grace_hopper.bmp
cp $^ $@
$(GRAPHENEDIR)/Runtime/libgcc_s.so.1:
cp $(ARCH_LIBDIR)/libgcc_s.so.1 $@
$(GRAPHENEDIR)/Runtime/libstdc++.so.6:
cp /usr/$(ARCH_LIBDIR)/libstdc++.so.6 $@
label_image.manifest: libtensorflow_framework.so label_image inception_v3.tflite labels.txt image.bmp
label_image.manifest: $(GRAPHENEDIR)/Runtime/libgcc_s.so.1 $(GRAPHENEDIR)/Runtime/libstdc++.so.6
label_image.manifest: label_image.manifest.template
sed -e 's|$$(GRAPHENEDIR)|'"$(GRAPHENEDIR)"'|g' \
-e 's|$$(GRAPHENEDEBUG)|'"$(GRAPHENEDEBUG)"'|g' \
$< > $@
label_image.manifest.sgx: label_image.manifest inception_v3.tflite labels.txt
$(GRAPHENEDIR)/Pal/src/host/Linux-SGX/signer/pal-sgx-sign \
-libpal $(GRAPHENEDIR)/Runtime/libpal-Linux-SGX.so \
-key $(SGX_SIGNER_KEY) \
-manifest $< -output $@
$(GRAPHENEDIR)/Pal/src/host/Linux-SGX/signer/pal-sgx-get-token \
-output label_image.token -sig label_image.sig
.PHONY: check
check: all
$(GRAPHENEDIR)/Runtime/pal_loader ./label_image -m inception_v3.tflite -i image.bmp -t 4
.PHONY: run-native
run-native: all
./label_image -m inception_v3.tflite -i image.bmp -t 4
.PHONY: run-graphene
run-graphene: all
$(GRAPHENEDIR)/Runtime/pal_loader ./label_image -m inception_v3.tflite -i image.bmp -t 4
.PHONY: clean
clean:
$(RM) label_image.manifest label_image.manifest.sgx label_image.sig label_image.token
.PHONY: distclean
distclean: clean
$(RM) -r label_image
$(RM) inception_v3_2018_04_27.tgz inception_v3.pb inception_v3.tflite labels.txt image.bmp
$(RM) -r $(TF_DIR) tensorflow.tar.gz libtensorflow_framework.so bazel-*-installer-linux-*.sh
BAZEL_INSTALLER_HASH=17ab70344645359fd4178002f367885e9019ae7507c9c1ade8220f3628383444
.PHONY: install-dependencies-ubuntu
install-dependencies-ubuntu:
apt-get update
apt-get install -y python-dev python-pip wget git
# https://docs.bazel.build/versions/master/install-ubuntu.html
apt-get install -y pkg-config zip g++ zlib1g-dev unzip python
$(GRAPHENEDIR)/Scripts/download --output bazel-0.16.1-installer-linux-x86_64.sh --sha256 $(BAZEL_INSTALLER_HASH)\
--url https://github.com/bazelbuild/bazel/releases/download/0.16.1/bazel-0.16.1-installer-linux-x86_64.sh
chmod +x bazel-0.16.1-installer-linux-x86_64.sh
./bazel-0.16.1-installer-linux-x86_64.sh --user
.PHONY: install-dependencies-fedora
install-dependencies-fedora:
dnf -y install python3-devel python3-pip wget git pkg-config zip gcc-g++ zlib-devel unzip
$(GRAPHENEDIR)/Scripts/download --output bazel-0.16.1-installer-linux-x86_64.sh --sha256 $(BAZEL_INSTALLER_HASH)\
--url https://github.com/bazelbuild/bazel/releases/download/0.16.1/bazel-0.16.1-installer-linux-x86_64.sh
chmod +x bazel-0.16.1-installer-linux-x86_64.sh
./bazel-0.16.1-installer-linux-x86_64.sh --user