888 Commits
Author SHA1 Message Date
Michał Kowalczyk b789ed3a17 Remove partially-implemented static guard pages
It turns out that our guard pages were incorrectly handled (i.e. not re-
added to LibOS VMA list) on SGX when execve was optimized to re-use the
same enclave, which caused exec_same test to crash from time to time
(when ASLR put heap on a guard page).

Static guard pages aren't too useful and introduce unnecessary
complexity to our code, so we decided to just delete them in order to
fix this bug.
2020-07-21 13:48:18 +02:00
Dmitrii Kuvaiskii bd40e5cc84 [LibOS] Do not clean-up if LibOS was not initialized 2020-07-20 17:49:00 +00:00
Michał Kowalczyk 4a5dcb3d95 [LibOS] test/ltp: Try to deobfuscate Makefiles
Changes:
	- `make all` previously rebuilt everything each time, now it
	  doesn't.
	- Using out-of-tree build.
	- Unfortunately we have to build the whole LTP now (minus modules),
	  so the build is slower.
	- But: `make -jX` works, previously was broken because of missing
	  dependencies.
	- Not using symlinks as targets anymore - Make is broken and checks
	  the timestamp of the *destination*, not the symlink itself.
	  Previously the links were recreated on each `make` call.
	- `make regression` printed:
	      /bin/sh: 1: test: Illegal number:
	  and now it doesn't.
2020-07-20 13:03:02 +02:00
Dmitrii Kuvaiskii 0a06c898d4 [Pal/Linux-SGX] Provision wrap key for protected files at runtime
This commit adds the ability to provision the wrap (master) key for
protected files at runtime (in contrast to previous approach of
hard-coding `protected_files_key` in the manifest as a temporary
solution). This is achieved as follows:

- New PAL API `DkSetProtectedFilesKey()` is added.
- New writable pseudo-file `/dev/attestation/protected_files_key` is
  added. It calls `DkSetProtectedFilesKey()` after it was written to.
- New `SECRET_PROVISION_SET_PF_KEY` option is added to the Secret
  Provisioning library. If it is set, the library assumes that the
  first provisioned secret is the wrap key for PF and writes it into
  the new pseudo-file.

The Secret Provisioning example `ra-tls-secret-prov` is updated to
include the new protected-files client. This client receives the wrap
key for PF via secret provisioning and reads & outputs the protected
file `files/input.txt`.

*NOTE*: The current implementation of provisioning the wrap key does
not work for `loader.argv_src_file` and `loader.env_src_file` if they
point to protected files (because provisioning happens after setting
up arguments and environment variables).
2020-07-19 21:50:45 +00:00
Michał Kowalczyk ba5e2d2e03 Speed up all tests using sgx.zero_heap_on_demand 2020-07-17 15:10:30 +02:00
Stefan Berger 6b0ebcae39 [LibOS] Null-terminate buffer before printing in proc_common test 2020-07-15 12:46:30 -07:00
Stefan Berger 2298104c9e [LibOS] Build cpuid and attestation test cases only on x86 2020-07-15 11:20:09 -07:00
Dmitrii Kuvaiskii b845e6b1ea [Pal/Linux-SGX] Correctly emulate RDTSC and RDTSCP instructions
Under SGX PAL, if the CPU doesn't support RDTSC/RDTSCP inside SGX
enclave, Graphene uses trap-and-emulate on these instructions.
Previously, Graphene only emulated RDTSC and not RDTSCP. Moreover,
Graphene emulated RDTSC by simply returning zeros, which could lead
to faults in applications not expecting a zero value. This commit
emulates (imprecisely) both RDTSC and RDTSCP via gettime() syscall.
New LibOS test is added (SGX-only).
2020-07-14 01:10:14 +00:00
Michał Kowalczyk 7b0c160296 [Pal] Protect env from untrusted world 2020-07-13 22:05:04 +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
Michał Kowalczyk 2552cf0f35 [LibOS] glibc: Overwrite instead of appending to build.log 2020-07-13 14:28:36 +02:00
Gary 49e50e4aa4 [LibOS] Fix "errlist.c count 134" error during Glibc build
Previously, Glibc build produced the following message:
"*** errlist.c count 134 inflated to GLIBC_2.12 count 135 (old
errno.h?)". This message is *not* a Graphene build issue and
may confuse users, so this commit removes it.
2020-07-13 06:02:07 +00:00
Michał Kowalczyk e86eca9007 [LibOS] ltp: Raise select04 timeout
Default timeout is 30s but the test takes ~25s natively and ~26s under
Graphene, which caused it to spuriously cross the deadline on Jenkins.
2020-07-11 02:13:03 +02:00
Dmitrii Kuvaiskii e7f5600a5d [LibOS] Hide "ar: `u' modifier ignored ..." during Glibc build 2020-07-07 20:42:51 +00:00
Dmitrii Kuvaiskii 8ae949b478 [LibOS] Improve Glibc patches to contain complete index hashes
Previously, Glibc patches were generated with shortened index hashes.
This commit re-generates all Glibc patches with complete index
hashes using `--full-index` option.

This commit also removes mentions of removed old Glibc 2.19 and the
unused Gold ld patch.
2020-07-07 20:42:51 +00:00
Michał Kowalczyk 5b8a648d3d [LibOS] regression: Fix test_201_exec_same to work in debug mode 2020-07-06 21:58:13 +00:00
Michał Kowalczyk db48178ae1 [LibOS] Fix shim_do_open to return -ENOENT for empty paths 2020-07-06 21:58:13 +00:00
Michał Kowalczyk cb7d430655 Remove always_inline where not needed 2020-07-05 17:24:06 +02:00
Stefan Berger c7912c2d0b [LibOS] Print missing MAP_XYZ flags in debug message 2020-07-04 00:46:49 +00:00
Stefan Berger 3323d21444 [LibOS] shim_parser: Display PROT_SEM flag 2020-07-03 15:15:54 +02:00
borysp be6af35cb9 [LibOS] Add support for PROT_GROWSDOWN 2020-07-02 20:09:18 +00:00
Stefan Berger 91709ac2fe [LibOS,Pal] Set weak parameter in atomics operations to false
The `weak` parameter has no influence on x86, but on ppc64 it causes
spurious faults due to a missing check on flags (missing `bne`
instruction).
2020-07-01 22:08:52 +00:00
Michał Kowalczyk 08e217786f [LibOS] Drop broken BOOKKEEP_INTERNAL_OBJ
Enabling this macro breaks the build due to two typos, both in just a
single line (sic!; OBJECT_INTERNVAL and VMA_INTERVAL).

git blame points to "The first official release" commit, which means
that no one used it since at least 2014. We can safely get rid of it.
2020-07-01 01:47:55 +02:00
Dmitrii Kuvaiskii 9092a649b7 [Pal/Linux-SGX] Enable TCS.FLAGS.DBGOPTIN for HW perf monitoring
This commit renames manifest option `sgx.print_stats` into
`sgx.enable_stats` and adds enabling TCS.FLAGS.DBGOPTIN for all
enclave threads when this manifest option is set. This allows to
collect performance counters and generally enable debug and profiling
features of enclaves (built in debug SGX mode).
2020-06-30 20:12:42 +00:00
Stefan Berger ee5acd1642 [LibOS] ltp: Determine COREUTILS_LIBDIR to access libstdbuf.so 2020-06-30 13:50:38 +02:00
Stefan Berger d599ced08b [LibOS] ltp: Use printf in Makefile rather than echo to escape '\n' 2020-06-30 13:50:38 +02:00
Stefan Berger 5b4c15b596 [LibOS] Initialize shim->pal_context to avoid crashes of LTP on ppc64
Crashes happened when SIGALARM fired in the getcwd04 test case:

__handle_one_signal(shim_tcb_t* tcb, struct shim_signal* signal) {
    struct shim_thread* thread = (struct shim_thread*)tcb->tp;
[...]
    if (signal->pal_context)   <---- bad pointer
        ucontext_to_pal_context(signal->pal_context, &signal->context);
}
2020-06-29 20:03:30 +00:00
Dmitrii Kuvaiskii ac7b5a2517 [Pal] Return POLLHUP on closed FDs in _DkStreamsWaitEvents() 2020-06-29 16:53:14 +00:00
Stefan Berger ab4f14df33 [Pal+LibOS] Drop wrappers from atomic.h
This is the first step in removing this obsolete header.
Additionally, AtomicMath test is removed, as it became obsolete after
these changes (and was relying on undefined behaviors anyway).
2020-06-26 14:31:23 +02:00
Don Porter ec3f56d594 [LibOS] ltp: Only build the part required for testing 2020-06-25 20:30:51 +00:00
Dmitrii Kuvaiskii 7d0c307bf8 [LibOS] Hide arguments from host OS and send them in checkpoint
Previously, Graphene sent arguments to a child process (spawned via
execve() syscall) in the clear. This was insecure. This commit fixes
it by always spawning a new child process without arguments and then
sending the arguments in the checkpoint (which is securely encrypted
on Linux-SGX PAL). The new logic is the same as with environ.
2020-06-25 17:47:56 +00:00
Dmitrii Kuvaiskii a4304b365f [LibOS] Refactor stack initialization on new process and on execve 2020-06-25 17:47:56 +00:00
Dmitrii Kuvaiskii a955effd88 [LibOS] ltp: Enable lseek02 test and remove non-existing lseek* tests 2020-06-25 16:22:20 +00:00
Stefan Berger 14e54c4382 [LibOS] Surround x86_64-specific parts in tests with #if defined(__x86_64__) 2020-06-25 14:46:33 +02:00
Stefan Berger 3c1493f0da [LibOS] ltp: Skip socketcall04 test for unbound socket
This test is noped-out with #ifdefs on x86_64. The current code does
not allow to listen on a socket that is not bound, so this test fails
when it actually runs (verified on PPC64).
2020-06-25 14:46:33 +02:00
Stefan Berger 940e5dc1ec [LibOS] Implement arch-specific tls_to_fs_base() 2020-06-25 14:46:33 +02:00
Stefan Berger 29e2f796f2 [LibOS] Implement arch-specific shim_regs_get_ip() 2020-06-25 14:46:33 +02:00
Stefan Berger ecf93f79a3 [LibOS] Define LIBOS_SYSCALL_BOUND in terms of LIBOS_SYSCALL_BASE 2020-06-25 14:46:30 +02:00
Stefan Berger df6cd09d0d [LibOS] Define vDSO filename as arch-specific constant 2020-06-24 20:52:41 +00:00
Stefan Berger ba0303a232 [LibOS] Move arch-specific part out of update_fs_base 2020-06-22 20:43:28 +02:00
Dmitrii Kuvaiskii 14b9edbbf5 [LibOS] Refactor checkpointing code
This commit still leaves checkpointing macros as-is; this will be
fixed in a folow-up commit.
2020-06-19 00:28:03 +00:00
Dmitrii Kuvaiskii d07c00de5a [LibOS,Pal] Add "loader.insecure__use_cmdline_argv" to more manifests
As part of argv protection, Graphene now requires an explicit
manifest option to pass command-line arguments, either
"loader.argv_src_file" or "loader.insecure__use_cmdline_argv". As
part of that change, most manifests were updated to include these
options, but not all. This commit fixes this for the rest of
manifests.
2020-06-18 12:54:51 +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
Michał Kowalczyk 324b248852 Rename loader.execname to loader.argv0_override in manifests 2020-06-18 00:44:30 +02:00
Michał Kowalczyk 8d239ea6ef [LibOS] Remove unused check_stack_hook() 2020-06-17 19:46:07 +02:00
Michał Kowalczyk e214acc934 [LibOS] Stop PAL_{NATIVE_,}ERRNO from pretending they're consts 2020-06-17 19:45:40 +02:00
Michał Kowalczyk 2551649399 [LibOS] Fix UB in VMA checkpointing
Pointer comparison is legal in C only if both pointers point to the same
array or its end, plus it's UB to decrement a pointer pointing to
array's first element.
2020-06-17 19:45:40 +02:00
Stefan Berger 2540c63d21 [LibOS] Move inline assembly to macro in shim_internal-arch.h 2020-06-17 17:58:52 +02:00
Stefan Berger 5181b073b2 [LibOS] Use current_stack() to get current stack pointer 2020-06-17 17:58:52 +02:00
Stefan Berger 4ee3e8242b [LibOS,Pal] Implement arch-specific pal_context_has_user_pagefault() 2020-06-16 19:55:04 +00:00