148 Commits

Author SHA1 Message Date
Michał Kowalczyk a402a2a8d9 [Pal/Linux-SGX] Add sgx.preheat_enclave manifest option
Signed-off-by: Michał Kowalczyk <mkow@invisiblethingslab.com>
2021-02-10 12:22:47 +01:00
Don Porter 79742f9029 [Docs] Add Developer Certificate of Origin (DCO)
Add a DCO and related text to CONTRIBUTING.rst.  Also add this documentation to rtdocs.

Signed-off-by: Don Porter <porter@cs.unc.edu>
2021-02-08 14:34:34 -05:00
borysp c24bddd5aa [LibOS] Rework signal handling and syscall emulation
Change log (most important only):
- unify CPU context structures - now we have only one version -
  `PAL_CONTEXT` - which is shared between LibOS and PALs and it should
  depend only on the host architecture (not OS),
- syscalls emulation changed:
  - dedicated LibOS stack is now used for syscalls emulation,
  - removed one indirection level in syscalls table - now it stores
    `shim_do_*` functions directly,
- signal handling - completely rewritten:
  - all signal queues use proper locking schemes now,
  - signals are handled *only* when returning to the user app from LibOS
    or PAL,
  - nested signals are now possible,
  - the app is allowed to jump out of signal handler with the same
    sematics as on normal Linux,
  - signal altstack is now fully supported,
  - syscall restarting is now supported,
  - doing a backtrace from the signal handler works properly,
- disallow injecting host-level signals, with one exception, see
  `sys.enable_sigterm_injection` manifest option for more details.
2021-02-05 14:11:21 +01:00
Dmitrii Kuvaiskii 0a4d5ce0e5 [GSC] Refactor GSC and make it work again
Commit "Introduce one, central manifest, zero-config children and
constant MRENCLAVE" broke GSC. This commit fixes GSC (mainly adjusts
it the single-manifest change in that commit). Also, significant
internal refactoring is done (no user-visible changes). Also, scripts
now explicitly use UTF-8 when reading/writing the manifest files because
they are written in TOML which forces UTF-8.
2021-02-03 23:10:29 -08:00
Michał Kowalczyk 2d27f1077e [Docs] Drop "Deprecated Code" sections
Seems that no one has used this feature since its deprecation 1.5 year
ago. Let's not clutter the main readme with it.
Also dropped a section from building instructions, as it was quite
useless.
2021-02-02 19:32:35 +01:00
Xiangping Ji c59a1438d5 [Pal/Linux-SGX] Recognize upstreamed Intel SGX driver
Intel SGX driver was upstreamed in Linux version 5.11. There, the SGX
device is exposed as `/dev/sgx_enclave` instead of `/dev/sgx/enclave`.
This commit updates link-intel-driver.py to recognize this new name.
2021-02-01 11:02:01 -08:00
Dmitrii Kuvaiskii bdc955e561 [Docs,Pal/Linux-SGX] Improve build and documentation on ISGX_DRIVER_PATH 2021-02-01 04:58:13 -08:00
Michał Kowalczyk d457420adf [Docs] Add missing build dependencies 2021-02-01 02:36:59 +01:00
Vijay Dhanraj ec4422d415 [Pal,LibOS] Add support for /sys pseudo filesystem
This commit also fixes `pseudo_name_ops::list_name()` function pointer
type: `size_t len` argument instead of `int len`.  It also adds a
regression test to exercise the newly supported /sys pseudo filesystem.
2021-01-28 23:28:29 -08:00
Paweł Marczewski ae8beba1a7 [Pal,Docs] Convert 'info' log level to 'warning'; add description
We seem to be using it for warnings, so it should be less confusing.
This change also adds a description of the levels to documentation.
2021-01-26 21:01:32 +01:00
Dmitrii Kuvaiskii e4c661b164 [LibOS] Add manifest option libos.check_invalid_pointers
Previously, LibOS always checked whether user-supplied buffers for
syscalls are invalid and generated EFAULT error codes if so. Since the
invalid-buffer check needed to touch memory/traverse VMAs, it could
affect performance of certain workloads. This commit adds a manifest
option that controls this behavior: most real-world applications never
supply invalid buffers in syscalls, so such checks can be disabled.
2021-01-26 10:48:52 -08:00
Paweł Marczewski 3388b211ae [Docs] Mention that pyelftools is needed for GDB 2021-01-25 11:43:36 -08:00
Paweł Marczewski 8ca27bd3c4 [Pal] Log to stderr, not stdout 2021-01-23 01:58:26 +01:00
Paweł Marczewski 17ab04db59 [Pal,LibOS] New logging system
Instead of 'loader.debug_type', introduce 'loader.log_level'
and 'loader.log_file', along with a set of definitions for
logging at a chosen level.

For now, the call sites keep using the legacy macros (SGX_DBG and
debug()), because converting them all will conflict with other
big changes in the code base. The existing LibOS calls are
assumed to be at 'info' level.
2021-01-20 17:27:29 +01: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 Kuvaiskii ef5259a86f [Docs,LibOS] Move helloworld example from native/ to regression/
Applications under native/ cannot be run after commit "Introduce one,
central manifest, zero-config children and constant MRENCLAVE". Instead
of fixing native/, this commit simply moves helloworld and all its
mentions under regression/.
2021-01-16 12:38:29 -08:00
Dmitrii Kuvaiskii ae6e933a91 [Pal/Linux-SGX] Add Intel PKRU to XFRM reg and XSAVE state 2021-01-13 04:07:41 -08:00
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
borysp 05ed29f52d [Pal] Remove empty DkExceptionReturn function
This function was empty and it is responsibility of the caller (Pal
level) of specific exception handling function (LibOS level) to return
from the exception.
2021-01-04 10:00:43 +01:00
Dmitrii Kuvaiskii 60a49c4853 [Pal/Linux-SGX] Add enclave loading time if sgx.enable_stats = 1
This commit also removes the macro PRINT_ENCLAVE_STAT (now user must
use `sgx.enable_stats = 1`) and moves all logic to untrusted PAL.
2020-12-23 06:05:43 -08:00
Wojtek Porczyk 5a89720071 [Pal] Linux-SGX: remove sgx-driver submodule
And all mentions thereof.
2020-12-23 14:30:25 +01:00
Paweł Marczewski b3b0d65968 [Pal/Linux-SGX] SGX perf: Add a profiling system
The profiling system instruments the asynchronous enclave exit
(AEX). Depending on configuration, we either snapshot the IP
value, or dump registers and (portion of) stack. The 'perf report'
tool can be used to generate a report from the samples.
2020-12-22 11:35:37 +01:00
borysp 989dac6fc8 [Pal] Fix semantics of DkSegmentRegister
On x64 DkSegmentRegister had weird semantics which also disabled some
usages like `0` as fsbase.
2020-12-17 16:18:26 +01:00
Michał Kowalczyk 7ce2c46dd4 [Pal] Remove unused and not implemented DkGetHostId 2020-12-09 14:32:56 +01:00
Michał Kowalczyk d53729b201 [Pal] Rework manifest loading
This is a major refactor of the way manifests are loaded and handled,
which will be followed by a complete rework of the loader code (which
will include e.g. centralized config).

Changes/fixes:
- Huge part of manifest handling was refactored and untangled.
- Starting without a manifest is now disallowed. This was actually
  accidentally broken for some time and no one complained. It also makes
  little sense in practice and in Graphene's overall design, e.g. it
  conflicts with protected argv.
- Now we only allow starting by giving the executable, not manifest (the
  magic resolution logic was removed).
- Now manifests are sent over pipes between parent and children, instead
  of children finding and loading them on their own. This is a
  preparation for the upcoming centralized manifests change.
- Previously manifests were parsed 2 times on Linux and 3 times on
  Linux-SGX (by untrusted PAL, trusted PAL and LibOS). This is now
  fixed.
- The common `pal_main()` now requires that the backend-specific PAL
  loader loads the manifest before calling it. SGX code already has to
  do it (for proper initialization), so let's unify this interface for
  all PALs.
- Fix for a PAL crash when manifest size was divisible by page size
  (sic!). NULL termination was missing, but most of the time the padding
  to page size saved Graphene from crashing.
2020-12-05 01:46:03 +01:00
Wojtek Porczyk 75ba2bc739 [Docs] Ignore toml_table_t from external library 2020-12-05 01:46:03 +01:00
Paweł Marczewski b063a2ba1b [Pal,LibOS] Introduce human-readable PERM_* macros
Instead of using S_I* flags, or hardcoded octal literals, use
helpers such as PERM_rwxrwxr_x. These are proposed in a Linux patch
by Ingo Molnar: https://lwn.net/Articles/696231/
2020-11-19 14:24:59 +01:00
Paweł Marczewski 38bf50c4c5 [Pal,LibOS] Fix loader.debug_type = file
Logging to file was broken, because the PAL file write operation
required the user to provide an absolute offset, and LibOS always
provided an offset of 0. This worked when logging to stdout, but
in case of a regular file, it kept overwriting the beginning of
file.

To fix that, we introduce a a special DkDebugLog call. This is a
better solution than tracking the file offset manually, because
the offset would need to be synchronized across different threads
and processes, and debug logs should be as simple as possible. At
the same time, we don't want PAL to provide a generic "append to
a file" mechanism, because it makes I/O less deterministic.
2020-11-17 23:56:28 +01:00
Dmitrii Kuvaiskii 4760c004a9 [Docs] Add descriptions of "fs.root" and "fs.start_dir" manifest entries 2020-11-16 10:40:47 -08: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
Paweł Marczewski fc6ffb9f8f [Docs] Describe using perf and other profiling tools
Add some notes on building perf, and using it for profiling.

Also mentions other tools that might be useful.
2020-11-07 16:35:24 +01:00
Paweł Marczewski 16e85939b5 [Docs] Move perf-practices to devel/ 2020-11-07 16:35:20 +01:00
Vijay Dhanraj 3fa93cc86f [LibOS,Pal] Add sched_setaffinity/sched_getaffinity syscall support
This patch adds syscall support for setting/getting cpu affinity
of threads.

Co-authored-by: Gary <gordon.king@intel.com>
2020-11-06 22:28:32 +01:00
Wojtek Porczyk a004123d92 [Docs] Add stub documentation for benchmarks 2020-11-05 05:59:04 -08:00
Dmitrii Kuvaiskii eb0e726625 [Pal/Linux-SGX] Allow EPID attestation even with DCAP SGX driver
Previously, Graphene assumed that if it was built with the DCAP
SGX driver or in-kernel SGX driver, then it should use DCAP/ECDSA
based attestation. In fact, the SGX driver has nothing to do with
the attestation scheme. This commit allows to use EPID based
attestation even when Graphene is built with the DCAP SGX driver.
2020-11-03 06:24:02 -08:00
Michał Kowalczyk 55aea29d50 [Pal] Disallow starting without an executable
Previously, it was possible to use Graphene without the main executable
(e.g. having only preloaded libraries). We aren't aware of anyone using
this weird option, but worse, it led to a very bad UX when the user made
mistakes - e.g. having a typo in the manifest or executable name could
lead to Graphene starting without errors, but doing nothing.
2020-10-27 04:21:30 -07:00
Michał Kowalczyk e587869e13 [LibOS+Pal] manifest: Remove support for loader.exec and sgx.sigfile
Supporting these options complicates the design of Graphene and loading
logic significantly, providing little useful functionality:
- loader.exec:
    - the main user of it were our tests
    - worked only for the first process spawned inside Graphene, as it
      was a unidirectional manifest->binary mapping, so the child
      process didn't know about the corresponding manifest.
- sgx.sigfile:
    - probably all existing usages of it were completely redundant
    - was resolved relatively to CWD instead of the executable location,
      which made it mostly useless

From now on, the correct location of the files is:
- either place the manifest and sigfile next to the binary, with a
  matching name, or
- create a symlink to the binary in the folder where manifests are
  stored and launch it through this symlink
2020-10-23 00:06:46 +02:00
Michał Kowalczyk 91600ce3c4 [LibOS] Remove outdated syscalls documentation 2020-10-14 20:01:13 +02:00
Dmitrii Kuvaiskii 3bcab01a0c [Pal/Linux-SGX] Remove "sgx.allow_file_creation" and always allow it
The manifest option "sgx.allow_file_creation" is useless (most
real-world apps will set it to "1" anyway). So this commit simply
removes this option and always allows to create files.
2020-10-06 00:20:22 -07:00
Don Porter 98b97c968c [Docs] Update building requirements 2020-10-06 00:24:10 +02:00
Anjo Vahldiek-Oberwagner fcb8a6529a [Docs] Update Azure Confidential Compute VM deployment description 2020-09-30 23:18:01 -07:00
Dmitrii Kuvaiskii 70c7264f03 [Pal/Linux-SGX] Add manifest option loader.pal_internal_mem_size
Previously, Graphene preallocated 64MB for PAL internal metadata
like trusted/protected files metadata, handles metadata, etc.
If this limit was depleted, Graphene loudly failed, and the user
had no option but to change constant in source code and rebuild
Graphene. This commit adds the manifest option
`loader.pal_internal_mem_size` to allow increasing this limit.
2020-09-30 08:14:38 -07:00
Anjo Vahldiek-Oberwagner f94c72b8f5 [GSC] Fix link to AKS guide in cloud deployment documentation 2020-09-22 11:25:24 -07:00
Anjo Vahldiek-Oberwagner 1cbdf3225a [GSC] Add prebuilt image and documentation for AKS 2020-09-22 14:14:31 +02:00
Michał Kowalczyk 471eb8ec60 [LibOS] Remove unused code
This commit removes some unused code from LibOS, the biggest part of
which being the support for "inline" binaries linked directly against
LibOS.

This allows us to remove e.g. POINTER_TYPE() macro, which was supposed
to check if a type is a pointer type, but implemented the check based
only on the first 2 characters of the type name (?!?).
2020-09-18 19:48:37 +02:00
Dayeol Lee ed609d99a8 [Docs] Change requirements.txt and elaborate the build instruction 2020-09-17 03:22:01 +02:00
Michał Kowalczyk ad477ec7bf Reformat repository to our C formatting rules (final iteration) 2020-09-15 02:00:54 +02:00
Anjo Vahldiek-Oberwagner 34b8eb1ec2 [GSC] Add an option to pre-build Graphene-only image
Previous iterations of GSC always built the Graphene runtime as part of
the `gsc build` command. This commit adds an option to extract the
compilation of the Graphene runtime from the GSC build command into a
separate command called `gsc build-graphene`. Using `gsc build-graphene`,
one can prepare a Docker image that includes the required runtime files
for a `gsc build` command.

The purpose of this separation is to publish Graphene Docker images for
special environments such as cloud environments. This simplifies the
configuration parameters for the user, since they only have to specify
the Graphene Docker image name instead of the Graphene repository and
Driver details.
2020-09-10 01:40:13 +02:00
Lu Ken 54bc4985bf [GSC] Support build-time variables via --build-arg
When building graphenized Docker image, some build-time variables
like http_proxy, https_proxy, no_proxy must be specified (for
private network behind proxy). This commit adds `--build-arg` via
GSC_BUILD_FLAGS.
2020-08-27 15:35:51 +00:00
Dayeol Lee 2b5b946f16 [Docs] Add PyTorch end-to-end Tutorial 2020-08-25 15:01:05 -07:00