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

121 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-3.0-or-later */
# Copyright (C) 2014 Stony Brook University
# Copyright (C) 2019 Invisible Things Lab
# Copyright (C) 2020 Intel Corporation
# Michał Kowalczyk <mkow@invisiblethingslab.com>
# Wojtek Porczyk <woju@invisiblethingslab.com>
# This is how we detect whether we're installed or running from inside git repo.
# If unchanged (i.e., if this reads IN_GIT between "at" characters), this is an
# ordinary string and test -n "$IN_GIT" is true. But when installing, this is
# rewritten using meson's configure_file() function to an empty string and the
# else branch is taken. See also: ./meson.build and
# https://mesonbuild.com/Reference-manual.html#configure_file.
IN_GIT=@IN_GIT@
if test -n "$IN_GIT"
then
while :
do
case "$1" in
"SGX")
SGX=1
export SGX
;;
"GDB")
GDB=1
;;
*)
break
;;
esac
shift
done
RUNTIME_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
if [ -z "$PAL_HOST" ]; then
if ! command -v make >/dev/null; then
libpal="$RUNTIME_DIR/libpal-*.so"
libpal="$(echo -n "$libpal")"
libpal="${libpal//$RUNTIME_DIR\//}"
if [ "$libpal" = 'libpal-*.so' ]; then
echo "Unable to detect PAL_HOST. Please install the make program."
exit 1
fi
array=("$libpal")
if [ ${#array[@]} -ne 1 ]; then
echo "Multiple libpal detected ($libpal). Please explicitly set the environment variable PAL_HOST."
exit 1
fi
PAL_HOST="${libpal%.so}"
PAL_HOST="${PAL_HOST#libpal-}"
else
PAL_HOST=$(make --no-print-directory --quiet -f "$RUNTIME_DIR/../Scripts/Makefile.configs" print_host 2>&1)
fi
fi
PAL_CMD="$RUNTIME_DIR/pal-$PAL_HOST"
LIBPAL_PATH=$(realpath "$RUNTIME_DIR/libpal-$PAL_HOST.so")
HOST_PAL_PATH=$(realpath "$RUNTIME_DIR/../Pal/src/host/$PAL_HOST")
else
PAL_CMD=@PAL_CMD@
LIBPAL_PATH=@LIBPAL_PATH@
HOST_PAL_PATH=@HOST_PAL_PATH@
SGX=@SGX@
fi
MANIFEST=
ENVS=()
PREFIX=()
if [ "$GDB" == "1" ]; then
PREFIX=("gdb" "-q")
if [ -n "$INSIDE_EMACS" ]; then
PREFIX+=("-i=mi")
fi
if [ 0"$SGX" -gt 0 ]; then
PREFIX+=("-x" "$HOST_PAL_PATH/gdb_integration/graphene_sgx_gdb.py")
ENVS+=("LD_PRELOAD=$HOST_PAL_PATH/gdb_integration/sgx_gdb.so:$LD_PRELOAD")
else
PREFIX+=("-x" "$HOST_PAL_PATH/gdb_integration/graphene_gdb.py")
fi
if [ "$GDB_SCRIPT" != "" ]; then
# Run a script in batch mode, and without TTY (so that it can be piped, redirected etc.)
PREFIX+=("-x" "$GDB_SCRIPT" "-batch" "-tty=/dev/null")
fi
PREFIX+=("--args")
fi
if [ "$PERF" == "1" ]; then
PREFIX=(perf stat)
fi
while [ "$1" != "" ];
do
if [ "$MANIFEST" == "" ]; then
MANIFEST=$1
shift
continue
fi
break
done
if [ "$MANIFEST" == "" ]; then
echo "Usage: $0 [<application>] <args>..."
exit 1
fi
if [ ! -f "$PAL_CMD" ]; then
echo "$PAL_CMD not found"
exit 1
fi
CMD=("${ENVS[@]}")
CMD+=("${PREFIX[@]}")
CMD+=("$PAL_CMD" "$LIBPAL_PATH" init "$MANIFEST" "$@")
exec env "${CMD[@]}"