Commit Graph

78 Commits

Author SHA1 Message Date
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
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
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
Paweł Marczewski 1d25612006 [CI] Enable pylint unconditionally, fix violations
Pylint output was filtered so that many files with existing pylint
violations were allowed to stay broken.

I made sure all files pass pylint, but whitelisted some rules that
we commonly disable:

* missing docstrings: most of the code is tests/internal anyway
* invalid-name: too many violations, and we commonly use one- or
  two-character names (like "a, b" or "t1, t2") which is
  disallowed by this rule; we could tweak it and then fix
  remaining violations such as camel-case or lowercase constants
* fixme: we leave TODOs as a matter of practice, same as in C
* high-level style rules like too-few-* and too-many-*,
  no-self-use

Hopefully that will make using pylint less annoying, while also
catching serious issues (such as unused variables or imports).
2020-11-17 13:45:09 -08:00
Wojtek Porczyk 179d7774af [CI] Fix Jenkins discovery in Scripts/clean-check* 2020-11-04 15:34:14 +01: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
Paweł Marczewski 5c2f33ee49 [Scripts] Create a helper script for running pytest
Running a subset of regression tests, or a single test, is
currently rather annoying, as you cannot simply run 'pytest':
you need to override PYTHONPATH and specify several environment
variables.

Instead, move the whole boilerplate to a wrapper script that
allows running pytest with any command line options. Use it in
Makefiles as well, so that it doesn't go out of sync with CI.
2020-10-12 23:38:32 -07:00
Paweł Marczewski dace80ce08 Add a regression test for GDB integration 2020-10-13 01:56:27 +02:00
Paweł Marczewski 53d71a344f Add debug info when compiling assembly files 2020-10-13 01:56:27 +02:00
Paweł Marczewski 5402d9f229 [Make] Fix SYS determination for clang 2020-09-28 13:22:12 +02:00
Michał Kowalczyk f1940ca614 Fix Bash scripts and remove unused ones 2020-09-15 19:21:13 +02:00
Paweł Marczewski 7b73f0e086 [Pal,LibOS] Make the offset generation compatible with clang 2020-09-10 16:27:45 +02:00
borysp 0f7a4e3fe5 Remove hardcoded paths to internal files
Graphene had some paths to internal files generated at compile time and
hardcoded into the output binary, which disallowed e.g. moving the
Graphene directory after compilation.
2020-08-03 20:19:28 +02:00
borysp 420a56b402 Make symlinks in Runtime directory relative 2020-07-29 20:45:01 +02: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
Stefan Berger fd22ef2fa3 [Pal] Build DkSegmentRegister() only on x86_64 and adapt Symbols test 2020-06-26 03:24:55 +00:00
Jörg Thalheim 82caa0683d [Scripts] Make bash shebangs portable
Unlike /usr/bin/env which is a Posix standard, there is no guarentee
that /bin/bash exists. This is the case for operating systems such
as FreeBSD, NixOS and Guix. By using /usr/bin/env we also give
the user the option to provide their own bash in a different path
by setting the $PATH environemnt variable.
Distributions usually provide their own packaging wrappers
to fixup shebangs upon installation, however those are not convienent
to use when developing in the source tree.

See also other upstream discussions about the topic:

- https://github.com/systemd/systemd/pull/5816
2020-06-24 19:51:55 +02:00
Michał Kowalczyk fcf0a01d7d Remove shebangs from autogenerated manifests
We don't use it in tests, plus it didn't work on SGX - there was a
warning about autogeneration inserted before the autogenerated shebang.

Also, test_106_manifest_with_shebang didn't actually test the shebang
but ran the binary through the loader, so it was meaningless. We'll need
to fix it and implement again after cleaning up Graphene invocation.
2020-06-18 00:44:30 +02:00
Stefan Berger fff09c00af Add -Wmissing-prototypes to CFLAGS and deal with the fallout 2020-06-04 17:22:19 +02:00
Stefan Berger 06ec21be32 [Scripts] Set PAL_HOST to Linux if 'linux' is found in $(SYS)
Also check for unsupported architecture in Makefile.configs.
2020-05-21 07:08:47 +00:00
Stefan Berger 17b1245270 [Examples] Python: adapt Python constants for Fedora
Adapt the python constants so that python-simple also works on
Fedora 31. python-scipy-insecure misses some shared libraries on
Fedora 31, so it does not work there yet.
2020-05-01 20:54:04 +00:00
Stefan Berger 741f5f7cd4 [Examples] Python: move Python constants to Scripts/Makefile.python 2020-05-01 20:54:04 +00:00
Stefan Berger f7f89c2ed2 [Makefiles] Make Graphene compileable and testable on Fedora
Adapt Scripts/Makefile.configs so that we can build and test on
Fedora. Most of the tests in Examples are now also runable on
Fedora. Also add a dependency installation target for Fedora to
TensorFlow example.
2020-05-01 20:54:04 +00:00
Stefan Berger 206eb81eec [Makefiles] Get arch and distro specific vars from Makefile.configs
Extend Makefile.configs and define several variables for make to use
derived from 'gcc -dumpmachine'. In particular:
- ARCH as the architecture, e.g., x86_64
- ARCH_LONG as the long version of the architecture, e.g., x86_64-linux-gnu
- ARCH_LIBDIR as the directory where libraries are located,
  e.g., /lib/x86_64-linux-gnu

In Makefiles and manifest templates, replace the hard-coded
x86_64-linux_gnu and /lib/x86_64-linux-gnu through these variables.
Extend the already existing sed scripts to replace the necessary
variables.
2020-05-01 20:54:04 +00:00
Michał Kowalczyk 4f57ada563 [Pal] Clean up argv handling and PAL invocation
This is a preparation for even more clean-ups and bugfixes, which are
required by protected argv+envp implementation.
2020-04-20 22:00:58 +02:00
Michał Kowalczyk a783fa2f4b Remove unused profiling system 2020-04-13 18:59:03 +02:00
Isaku Yamahata e0dc66bcf6 [Make] Fix Makefile.Host message when run with SGX_RUN=1
Remove leading tab to fix the following error:

> Scripts//Makefile.Host:16: *** recipe commences before first target. Stop.
2020-02-29 02:54:48 +01:00
borysp f2b1d194a1 [Make] Remove std=gnu99 from tests 2020-02-14 05:16:50 +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 07722756e5 [Scripts] Include dependency file for .c in Makefile.Test 2020-02-05 23:21:06 -08:00
Isaku Yamahata cff1146892 [LibOS,Pal] Modify Makefiles' logic to simplify checks on SYS
The goal of `$(SYS)` check in Makefiles is to skip all targets on
unsupported systems. This commit defines a default goal `all` as
a no-op for simplicity.
2020-02-05 23:21:06 -08:00
Isaku Yamahata fc0b5c4012 [LibOS,Pal] remove unnecessary .PHONY: default in Makefiles 2020-02-05 23:21:05 -08:00
Isaku Yamahata 647a8f3953 [LibOS,Pal] Consolidate common CFLAGS in Makefile.configs 2020-02-05 23:21:05 -08:00
Isaku Yamahata 72ddedc065 [Scripts] Remove PAL_LOADER variable from Makefile.test 2020-02-05 23:21:05 -08:00
Isaku Yamahata 29d907a573 [LibOS,Pal] Consolidate DEBUG, WERROR, PROFILE in Makefile.configs 2020-02-05 23:21:05 -08:00
Isaku Yamahata 88ea5164d6 [LibOS,Pal] Makefiles: use += instead of = in CFLAGS/LDFLAGS/etc 2020-02-05 23:21:05 -08:00
Isaku Yamahata 86afe662f3 [Pal/Linux-SGX] Add rule cmulti to build executable from multiple .o files 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 419b5c5a11 [Pal] Introduce common Makefile.manifest and remove Pal/src/Makefile.Test 2020-02-05 23:21:05 -08:00
Isaku Yamahata 08ae3a241c [Pal] Use expand_target_to_{sig,sgx,token} instead of expand_target() 2020-02-05 23:21:05 -08:00
Isaku Yamahata 35dd8c9423 [LibOS,Pal] Consolidate export DEBUG in Makefile.configs 2020-02-05 23:21:05 -08:00
Isaku Yamahata 0912f20ccf [LibOS,Pal] Unify the setting of CC and remove raw gcc invocations 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 9ef2251d66 [LibOS,Pal,Scripts] Add and use recipe to create manifest from template 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 0daeed847f [Jenkins] Check for missing gitignores and fix found issues 2020-02-05 02:46:13 +01: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 75619fe760 [Scripts/clean-check] Ignore git repos
Newer git versions update some cache in .git/index even on read-only
calls (like git status). So ignore any changes in .git when checking
make clean.
2020-02-04 01:15:59 -08:00