65 Commits
Author SHA1 Message Date
Wojtek Porczyk 9c98438b7c [CI] Add download mirror
We've experienced intermittent github.com outage, so add our own mirror.
2021-01-26 08:39:24 -08:00
Paweł Marczewski 5ef9bdc861 [Pal] Unify debug maps
- Use the same mechanism (debug_map) in Pal/Linux and Pal/Linux-SGX.
  Previously, Pal/Linux emulated the _r_debug structure, normally
  maintained by ld.so, but that cannot be done in SGX outer PAL,
  because it's loaded by ld.so already.
- Maintain the debug maps outside of SGX enclave. This allows
  initializing them before enclave start, and potentially makes
  them easier to use.
- Initialize PAL debug map before enclave start. Previously, this
  was done from inside the enclave, so you couldn't set a
  breakpoint too early (e.g. in pal_linux_main).
- Store only load address, without list of sections. This is to
  avoid parsing the list of sections just to report them to the
  debugger. Unfortunately, the GDB version that we support still
  needs these sections, but we can retrieve them in GDB plugin.
- Move Python GDB code related to debug maps to a common file.
2021-01-18 03:49:18 +01:00
Dmitrii KuvaiskiiandIsaku Yamahata 3cb2112b05 [LibOS,Pal] Use GCC's stack protector in LibOS and PAL functions
GCC (and other compilers, e.g. Clang) provide a stack protector
feature to detect stack corruptions. This is achieved by storing
a 64-bit canary value on the stack frame on function entry and
verifying this value on function exit. Previously, Graphene disabled
stack protector completely. This commit enables it in LibOS and PAL
code (only if `-mstack-protector` feature is supported by compiler).

The stack protector uses a random per-thread canary stored in the
TLS/TCB of each thread. Each PAL implementation must follow the
rule that TLS/TCB is accessed via the GS register and that the offset
of canary in TLS/TCB is 0x8. Since LibOS re-uses TLS/TCB of the PAL,
there is no need for additional enabling at the LibOS layer.

Since `-mstack-protector` feature is architecture-specific, it is
currently enabled only for x86-64 (and above rules on using gs:[0x8]
to access the canary apply only to x86-64).

Co-authored-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2021-01-07 05:19:14 -08:00
Paweł Marczewski 024f851424 [Pal/lib] Use the right make invocation for mbedtls
'make -jN' is not respected otherwise.
2020-11-13 15:19:58 +01:00
Dmitrii Kuvaiskii 8eee4a4742 [LibOS,Pal,Examples,GSC,Docs] Move manifest parsing to TOML
The manifest syntax stays exactly the same, including 0 and 1
integers to denote boolean values (this is done for ease of porting
and can be fixed in future commits). The only visible change is
surrounding strings in the manifest with quotes (requirement of
TOML). All manifests and Makefiles of our tests and example apps are
ported to the new TOML syntax. Documentation is updated.
2020-11-12 05:45:07 -08:00
Dmitrii Kuvaiskii 892bf70d58 [Pal/lib] Download and patch TOML-parser library tomlc99
This library will be used to parse Graphene manifest files written
in TOML syntax. We patch the library slightly to remove unsupported
toml_parse_file() and toml_rtod(), as well as errno() handling.
2020-11-03 05:07:03 -08:00
Dmitrii Kuvaiskii 28050d051e [Pal/lib] Add strtoll() and funcs from ctype.h for string manipulation
These functions are required by the TOML C source code, which will
be embedded into Graphene in a future commit.
2020-10-29 02:02:05 -07:00
Michał Kowalczyk 4e26fe7e32 [LibOS+Pal] Clean up string handling utilities 2020-10-16 16:18:43 +02:00
Dmitrii Kuvaiskii bd5d56b1a0 [Pal/lib] Add strncmp() and strspn() string manipulation funcs
These functions are required by the TOML C source code, which will be
embedded into Graphene in a future commit.
2020-10-15 08:27:43 -07:00
Rafał Wojdyła cf84489cd5 [Linux-SGX] Add protected files implementation
Protected files (PF) are a new type of file that can be specified in
the manifest (SGX only). They are encrypted on disk and transparently
decrypted when accessed by the Graphene payload.

Other features:
- data is integrity protected (tamper resistance)
- file swap protection (a PF can only be accessed when in a specific path)
- transparency (Graphene payload sees PFs as regular files, no need to modify
  the payload)

See Linux-SGX/protected-files directory for implementation. PF format is
based on protected files from the SGX SDK:
https://github.com/intel/linux-sgx/tree/master/sdk/protected_fs

The following new manifest elements are added:

sgx.protected_files_key = <16-byte hex value>
sgx.protected_files.<name> = file:<host path>

sgx.protected_files_key specifies the encryption key and is only a temporary
implementation. This key should be provisioned with local/remote attestation
in the future.

Paths specifying PF entries can be files or directories. If a directory is
specified, all files/directories within are registered as protected
recursively (and are expected to be encrypted in the PF format).

Linux-SGX/tools directory contains the pf_crypt utility that converts files
to/from the protected format.
2020-07-13 20:19:42 +02:00
Dmitrii Kuvaiskii 57bbbe321a [Pal/lib] Replace old memory-handling functions with simpler versions
Graphene used its own implementations of memory-handling functions like
memcmp(), memcpy(), etc. These implementations were copied from Glibc
and contained complicated code from year 2004. Modern HW and compilers
do better job at optimizing simple C implementations of these functions.
Thus, this commit replaces old implementations with simple ones taken
from Musl libc and adapted to our code style.

One particular optimization is made to memcpy() on x86-64. memcpy() is
heavily used in Linux-SGX PAL to copy data in/out of SGX enclave.
Experiments with Redis 5.0 show perf improvement of using "rep movsb" at
3-5% for 4KB payloads over the previous implementation based on Glibc.
2020-07-02 16:38:31 +00:00
Jörg Thalheim 929d3225de [Pal] Invoke mbedtls with perl directly
Although scripts/config.pl has a sane shebang `/usr/bin/env perl`,
we don't provide `/usr/bin/env` in the [nix](https://nixos.org) sandbox.
For other platforms this patch is not necessary; however, it should not
break anything.
2020-07-02 13:03:37 +02:00
Stefan Berger bf155c7bc9 [Pal/lib] Implement strstr() 2020-06-10 00:27:10 +00:00
Stefan Berger fff09c00af Add -Wmissing-prototypes to CFLAGS and deal with the fallout 2020-06-04 17:22:19 +02:00
Stefan Berger 81cc69e519 [Pal/lib] Add -mrdrnd to CFLAGS only on x86_64 2020-05-21 07:08:47 +00:00
Stefan Berger d49aa22c56 [Pal/lib] Create aesni.o only on x86_64 2020-05-21 07:08:56 +00:00
Stefan Berger e0ca25a413 [Pal] Move x86_64 syscall arch_prctl into Linux-specific pal_set_tcb()
Move the Linux x86_64 specific syscall arch_prctrl into a new inline function
pal_set_tcb located in include/arch/x86_64/Linux/pal_host-arch.h. The SGX and
Skeleton builds now also need a pal_host-arch.h file, empty for now.
2020-05-18 21:26:28 -07:00
Stefan Berger 74dc2ebfc3 [Pal] Move x86_64/Linux specifics from pal.h into arch/x86_64/pal-arch.h
Also, adapt the Makefiles to add the directory to the CFLAGS.
2020-05-09 14:43:17 +02:00
Dmitrii Kuvaiskii 069ac84bfc [Pal/lib] Makefile: add dependency on mbedTLS patch (.diff) 2020-04-20 13:41:42 -07:00
Dmitrii Kuvaiskii caf1263070 [Pal/Linux-SGX] Encrypt all pipes/socketpairs with TLS-PSK
Previously, Linux-SGX PAL did not encrypt pipe/socketpair
communication (only process checkpoint send/receive was encrypted).
This commit encrypts all pipe/socketpair IPC between threads of
the same enclave and between enclave processes. In particular, all
offsprings of the "first" enclave inherit the same master key and
derive IPC session keys from this master key based on pipe name.
When two pipe/socketpair endpoints are first created, they establish
a TLS-PSK session via intra-enclave handshake (requires a spawn of
an intermediate enclave thread). During clone/fork/exec, endpoints'
TLS contexts are serialized and sent to the child that deserializes
them (using mbedtls_ssl_context_{save,load} functions).

Note that multicast pipes (with more than two communicating entities)
are not supported since TLS protocol doesn't support it.

This commit modifies the PAL `SendHandle` test to correctly test
pipe communication, as well as adds the LibOS `pipe` test.
2020-04-13 16:18:58 -07:00
Chihyun SongandDmitrii Kuvaiskii b4d3cbccc6 [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.

Co-authored-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
2020-04-07 11:12:17 -07:00
Dmitrii Kuvaiskii bbb5340c7e [Pal/lib] Build in-Graphene mbedTLS crypto lib with minimal config
Graphene now moved to mbedTLS version 2.21.0. This new version
decouples the crypto functionality in a separate lib (libmbedcrypto).
This separate lib has its C code and headers under mbedtls/crypto
subdirectory. Previously, we forgot to copy our in-Graphene minimal
config `config.h` into this new subdirectory. This meant that the
crypto lib was built with a default and bloated configuration, not
needed for our Graphene purposes. This commit fixes this.
2020-04-03 11:45:51 -07:00
borysp 5f1e6ca317 [Pal/lib] Add generic trees (AVL) 2020-04-01 02:46:33 +02:00
Rafał Wojdyła 8372248543 [SGX] Add standalone SGX utilities
- is_sgx_available: check the environment for SGX compatibility
- quote_dump: display internal SGX quote structure
- ias_request: send IAS requests (SigRL retrieval and quote verification)
- verify_ias_report: verify IAS attestation reports (and quote contents)
- libsgx_util.so shared library with functionality of these tools (see .h files)
2020-03-27 11:42:51 +01:00
Dmitrii Kuvaiskii 3e06d28d97 [Pal/lib] Update mbedTLS to version 2.21.0
Previous version of mbedTLS used in Graphene (v2.16.3) is old and
does not have TLS-context serialization functionality. This commit
updates mbedTLS to v2.21.0 (released February 2020); this version
has mbedtls_ssl_session_save() and mbedtls_ssl_session_load() for
TLS context serialization. These functions will be needed for IPC
encryption.
2020-03-20 13:26:16 +01:00
Dmitrii Kuvaiskii 8d76f9d3fb [Pal/Linux-SGX] Remove remote attestation functionality
Previously, Graphene with SGX performed self-remote attestation
by retrieving the SGX quote from the Quoting Enclave, sending it
to the Intel Attestation Service via Curl (in an HTTPS request),
and parsing the received from IAS remote-attestation certificate.

This self-attestation functionality is meaningless and is removed.
Moreover, since EPID-based remote attestation requires client key
(Ocp-Apim-Subscription-Key), and this key must be kept secret,
specifying it in the Graphene manifest (as was done previously) is
insecure. Therefore, the whole remote attestation functionality is
moved out of Graphene and to another trusted party (or to the app
on top of Graphene). Only the SGX quote retrieval from the Quoting
Enclave is kept in Graphene.
2020-03-19 18:08:37 +00:00
Isaku Yamahata b25bd2aed5 [Make] List object files in plain manner
The current Makefiles are unnecessarily too smart in avoiding
duplication (which is small, I think). As a result, it's hard to
understand what files are listed. Use plain, explicit listing instead.

Also, append .o to objs variables. Usually obj means .o file, not the
base name of file. It was confusing.
2020-02-12 17:09:24 +01:00
Isaku Yamahata df358b8ba8 [Make] Consistently use $(RM) instead of rm -f 2020-02-12 01:09:21 +01:00
Isaku Yamahata 0a7e3dd127 [LibOS,Pal] Move header files from Pal/lib/ under Pal/include/ 2020-02-05 23:21:06 -08:00
Isaku Yamahata 05e42acbc6 [Pal] Move header files under include/ and adjust the include directive 2020-02-05 23:21:06 -08:00
Isaku Yamahata 8d65898d91 [LibOS,Pal] Eliminate creation of host_endian.h symlink
This file should be included via include path, not via a symlink.
2020-02-05 23:21:06 -08:00
Isaku Yamahata 29d907a573 [LibOS,Pal] Consolidate DEBUG, WERROR, PROFILE in Makefile.configs 2020-02-05 23:21:05 -08:00
Isaku Yamahata b7e336e15e [Pal/lib] Remove useless setting of CFLAGS in Makefile
Makefile.am overwrites CFLAGS, so setting CFLAGS before including
Makefile.am is useles.
2020-02-05 23:21:05 -08:00
Isaku Yamahata 50bdec8a23 [LibOS,Pal] Move Makefile.Host under Scripts/ 2020-02-05 23:21:05 -08:00
Isaku Yamahata dd086816b5 [LibOS,Pal] Define AR and ARFLAGS properly 2020-02-05 23:21:05 -08:00
Isaku Yamahata 732712e23e [LibOS,Pal] Move makefile libraries under Scripts/
This commit moves Makefile.configs, Makefile.rules, and Makefile.Test
under Scripts/ and adjusts their includes.
2020-02-05 23:21:04 -08:00
Simon Gaiser 9052837dfc [Make] Improve download handling
Instead of implementing downloading of external resources in every
Makefile again, use one script. This script adds the following
features:

 - Always check the download against a known SHA-256 hash.

 - Support caching of downloaded resources (set DL_CACHE=/some/dir).

 - Allow offline builds if all files are cached. If DL_OFFLINE=true the
   build will never attempt to download anything.
2020-02-05 00:41:10 +01:00
Simon Gaiser 7377a787bc [Makefile] Add distclean target
Before, there was no target that cleaned up downloaded sources. This
commit adds a distclean target to match the 'apps' Makefiles.
2020-02-04 01:15:08 +01:00
Dmitrii Kuvaiskii 14868809a9 [Makefile] Remove mbedtls's config.h on first build in lib/Makefile
Previous commit fixed the dependency on crypto/config.h (it must be
copied into mbedtls include directory). However, config.h with
default and incorrect settings already exists in mbedtls include
dir after its download, and Graphene needs to replace it with our
version of configuration. This commit simply removes default config.h
on first build of mbedTLS to force the dependency introduced in
the previous commit.
2020-01-29 19:30:07 -08:00
borysp 947fa3531f [Makefile] Fix lack of config.h dependency in lib/Makefile 2020-01-30 00:40:07 +01:00
Dmitrii Kuvaiskii 735f54d22c [LibOS,Pal/{lib,Linux-SGX}] Add TLS-PSK protection to process checkpoint IPC
Previously, Graphene-SGX did not protect send/recv of checkpoint from
parent to child. This leaked all memory contents of the parent process.

This commit adds TLS-PSK (TLS with Pre-Shared Key) wrapper for process
communication. Graphene-SGX already has the logic for SGX-based local
attestation and generation of the shared key for each parent <-> child
communication channel via Diffie–Hellman key exchange. This commit
uses this pre-shared key to create an mbedTLS-based session based on
UNIX domain socketpair (parent.process.stream <-> child.process.stream).

_DkStreamSecure{Init,Free,Read,Write} internal Linux-SGX PAL functions
are added and used during child process creation and sending of the
parent-generated checkpoint. These functions are backed by crypto-layer
lib_SSL{Init,Free,Read,Write} functions which in turn use mbedTLS.
Configuration of mbedTLS is expanded to support TLS-PSK; note that for
entropy source we use only rdrand instruction inside SGX enclave (i.e.,
no untrusted host-platform sources of entropy). The only ciphersuite
currently supported for IPC is MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256.

This commit adds protection only for checkpoint IPC. After the checkpoint
is sent/received, the parent/child processes downgrade their sockets to
plain non-secure ones (by disabling TLS). This is done because child
may spawn a grandchild that also wants to communicate with grandparent,
but it is impossible for multiple processes to share same TLS context.

Additionally, this commit sanitizes "process" PAL handles during send-
handle checkpoint send (via DkSendHandle): shared key and TLS context
are zeroed out.
2020-01-28 13:05:48 -08:00
Thomas Knauth 0f0eb95732 [Pal/lib] Fetch and build mbedtls 2.16.3 from official repo 2019-12-19 21:03:56 -08:00
Dmitrii Kuvaiskii 99dad080ef [Pal/lib] Remove lingering mentions of WolfSSL
Graphene moved to mbedTLS due to licensing issues, and all WolfSSL files
were deleted from the repo long time ago.
2019-12-02 19:12:37 -08:00
Jia Zhang 3e7397b173 [Makefiles] Don't include *.d files when cleaning 2019-12-02 23:02:44 +01:00
Jia Zhang dc060bca3b [Makefiles] Link Graphene libraries in a fixed order
Previously, Graphene libraries were built using `wildcard` make function.
The output of this function (list of files) is non-deterministic (list items
can be in any order). This results in different SGX measurements on rebuilds.

In some build environments (e.g., a dedicated Graphene container), it is
important to keep these measurements deterministic. This commit achieves this
by removing wildcards and explicitly specifying required files.
2019-11-27 17:16:34 -08:00
Chia-Che Tsai 6c4f21cba2 [Pal/Linux-SGX] Simple remote attestation framework
This is the minimalistic implementation of the remote attestation
framework. The framework conducts the following steps during
start-up to verify the authenticity of the SGX platform:

1. Connect to aesmd service to retrieve platform info (targetinfo)
   of the Quoting Enclave (QE) before enclave creation.
2. Prepare the SGX report inside enclave (during initialization):
   - Read SPID (service provider ID) from sgx.ra_client_spid in
     manifest.
   - Get an SGX report for local attestation to QE.
   - Generate a random 16-byte nonce for freshness.
   - Perform an OCALL for retrieving the quote.
3. Gather attestation data (QE report, QE quote, IAS report, signature,
   certificate chain) outside of enclave:
   - Connect to aesmd to retrieve the QE quote; aesmd also returns
     QE report.
   - Connect to Intel Attestation Service using curl. A client
     subscription key (specified via sgx.ra_client_key in manifest)
     is required to authenticate the HTTPS connection.
   - Get the IAS report, signature, and certificate chain from IAS.
     Print out the attestation result.
   - Return all this attestation data back to the enclave.
2019-09-10 21:00:49 -07:00
Simon Gaiser 64e46adcc0 [Makefile] Use generated header dependencies
Fixes #189.
2019-08-14 00:44:17 +02:00
Isaku Yamahata 4789a3a188 [{shim,Pal}] Refactor Makefiles to utilize Makefile.rules 2019-07-11 07:04:33 +02:00
Isaku Yamahata 08b535f759 [Makefiles] Introduce Makefile.configs for configuration
Introduce Makefile.configs as a single place to allow override
of configuration variables CC, AS, AR, and LD.
2019-06-20 16:21:17 -07:00
Isaku Yamahata a12b8c0149 [Pal] Enable -Wnull-dereference 2019-05-30 19:05:17 -07:00