1007 Commits
Author SHA1 Message Date
Don Porter f50fd7e5c8 A bit more work on documenting the PAL ABI 2019-11-11 14:08:22 -05:00
Don Porter 7910b10b67 Try adding a define to the documentation 2019-10-28 14:15:23 -04:00
Don Porter 5c2efaa3ae Start documenting the PAL ABI 2019-10-28 12:10:46 -04:00
Krishnakumar, Sudha b80606505f [LibOS] Propagate error code on failures in shim_do_pipe2()/shim_do_socketpair() 2019-10-23 14:47:14 -07:00
Dmitrii Kuvaiskii d4e5b65860 [LibOS] test/apps: Fix Makefiles of TensorFlow example 2019-10-23 13:01:07 -07:00
Dmitrii Kuvaiskii fe7a603bf3 [Pal/Linux-SGX] Increase MAX_DBG_THREADS constant from 64 to 1024
An internal Graphene structure for GDB metadata limits the number of
enclave threads to MAX_DBG_THREADS. Previously, it was set to 64,
which was enough for typical platforms. However, powerful servers
have hundreds of logical cores. Graphene-SGX failed with error on such
servers. This commit increases the limit to 1024.
2019-10-23 12:00:12 -07:00
Dmitrii Kuvaiskii 8e3fe7a86f [LibOS] Use -O2 optimization level when building in non-debug mode
There was a bug in LibOS code which manifested in heisenbugs in our tests.
The bug happened because `shim_clone.c:clone_implementation_wrapper()` called
`object_wait_with_retry()/DkObjectClose()` before actually setting up a proper
in-enclave TCB. The root cause was:
1. The newly created thread has an in-enclave `FS segment register == 0`
   because Graphene-SGX doesn't set up SGX's `TCS.OFSBASGX`, so in-enclave FS
   register was equal to `%fs == TCS.OFSBASGX == 0`.
2. `object_wait_with_retry()` checks `PAL_NATIVE_ERRNO` which is implemented
   via TCB's `mov %fs:<offset>`.
3. However, `%fs == 0` at this point so there was a SIGBUS while executing
   `mov %fs:<offset>`.

The fix (in this commit) is to move `object_wait_with_retry()/DkObjectClose()`
after TCB set-up in `allocate_tls()`.
2019-10-23 12:00:12 -07:00
Dmitrii Kuvaiskii 54278f8286 [Pal/Linux-SGX] Rewrite link-intel-driver.py in Python3 2019-10-22 23:03:18 -07:00
Jia Zhang fd0c564cf9 [Pal] pal_loader: Detect PAL_HOST if make is unavailable
In certain cases (e.g, a container runtime for production), `make` and `gcc`
programs may be unavailable. In this case, detect `PAL_HOST` based on the
base name of libpal.
2019-10-22 19:32:55 -07:00
Wojtek Porczyk f265a21ce2 [CI] Ignore LTP results under SGX
Graphene with SGX is currently experiencing random segfaults and the
testsuite is unstable. For now, the tests are still run, but the
returncode is ignored.

Also fixes Jenkins-SGX-18.04 pipeline, which was apparently broken but
its results are ignored and this problem was missed.
2019-10-22 21:44:21 +02:00
borysp ef48e04a07 [Pal/Linux-SGX] Add path normalization to allowed files handling 2019-10-21 12:56:04 -07:00
Dmitrii Kuvaiskii 4379d74d8e [LibOS] test/apps: Add OpenVINO example 2019-10-18 19:38:48 -07:00
Jia Zhang 1f46a8a60c [Pal] Add assert in case zero is fed to IS_POWER_OF_2() 2019-10-18 18:11:35 -07:00
Jia Zhang e9b988136d [Pal/Linux-SGX] Implement new manifest option sgx.file_check_policy
The new option specifies the file check policy, determining how and which files
can be opened. Previously, there were only two strict options: sgx.trusted_files
and sgx.allowed_files, but they are not flexible enough (e.g., unknown files are
never allowed).

This commit introduces two policies:
- allow_all_but_log allows files other than trusted/allowed files to be opened
  but outputs a warning message. This is a convenient way to debug applications.
- strict disallows all files other than trusted/allowed files (just like the
  previous logic).
2019-10-18 13:51:56 -07:00
Jia Zhang ab917d969d [Pal/Linux-SGX] Makefile: Fix build failure in a clean build 2019-10-18 03:40:40 -07:00
Jia Zhang 4ca3c39cf2 [PAL/Linux-SGX] Makefile: Let make clean work for sgx-driver 2019-10-18 03:40:40 -07:00
borysp f71bd2ca84 [LibOS] Move helper threads' status checking after lock acquisition 2019-10-18 02:43:41 -07:00
Wojtek Porczyk 6866bdb2c6 [LibOS, Jenkins] parse LTP test results 2019-10-18 09:10:31 +02:00
Jia Zhang 1b8c2de9ce [Doc] Fix installation instructions for python3-protobuf for Graphene-SGX build 2019-10-17 12:24:03 -07:00
Yunjong Jeong 5c3b6929df [LibOS] Reorder argv in initial user stack
Even though the SysV ABI does not specify the order of argv strings,
some applications (notably Node.js's libuv) assume the compact
encoding of argv where (1) all strings are located adjacently and
(2) in increasing order. This commit reorders argv strings in the
initial user stack in this way.
2019-10-17 03:02:06 -07:00
Dmitrii Kuvaiskii 560da76252 [Pal/Linux-SGX] enclave_entry.S: Reset FXSAVE extended state on EENTER
Previously, the FXSAVE extended state (ST, XMM, MXCSR registers) was not
cleared on EENTER (i.e., enclave-thread enter). This could lead to
maliciously crafted ST/XMM registers propagating into the enclave and
subverting execution. This commit resets FXSAVE on every EENTER to a
default mostly zero-byte state.

Note that this commit does not reset XSAVE state (YMM, ZMM registers).
This will be fixed in a future commit.
2019-10-16 18:24:01 -07:00
Dmitrii Kuvaiskii 1315b54b5d [Pal/Linux-SGX] enclave_entry.S: Fix offset of MXCSR "reset" XSAVE area
Before EEXIT, Graphene-SGX resets the extended state (XSAVE) area to the
default state (of mostly zero bytes). This prevents the leakage of
x87/SSE/AVX/MPX register values inside the enclave. However, the
previous default state had an incorrectly calculated offset of MXCSR. This
commit fixes the offset of MXCSR. (This particular error manifested in
spurious "Numeric underflow (#U)" SSE hardware exceptions on OpenVINO.)
2019-10-16 18:24:01 -07:00
Chia-Che Tsai c8a352553b [Pal/Linux-SGX] Change manifest option sgx.enable_[avx|avx512|mpx] to sgx.require_[avx|avx512|mpx]
This commit allows setting the AVX, AVX512, and MPX bits in SIGSTRUCT.xfrms
dynamically unless the features are specifically enabled in the manifest via
sgx.require_[avx|avx512|mpx]=1 options. If the bits are set in SIGSTRUCT.xfrms
but the CPU feature(s) are not available on the platform, the enclave
initialization (EINIT) should fail. In addition, the xfrms and xfrmmask fields
in the EINITTOKEN must match with SIGSTRUCT.
2019-10-16 13:53:24 -07:00
Dmitrii Kuvaiskii a17b28a656 [Pal/Linux-SGX] Do not overwrite sgx.static_address in manifest
Previously, the "sgx.static_address" field was overwritten by the
pal-sgx-sign tool in the manifest, even if the manifest author
explicitly specified it as 0 or 1. Sometimes, it is important to keep
sgx.static_address as the manifest author intended. This commit adds a
check to overwrite sgx.static_address only if not specified in manifest.
2019-10-15 17:26:11 -07:00
Isaku Yamahata aac7a83037 [LibOS] Remove lingering warnings
- regression/large_dir_read.c: Wformat-overflow
- shim_rtld.c: __load_elf_object(): Wmaybe-uninitialized
- shim_parser.c: parse_syscall_after(): Wmaybe-uninitialized
- shim_msgget.c: get_sysv_msg(): Wmaybe-uninitialized
- shim_semget.c: __add_sem_handle(): Wmaybe-uninitialized
- shim_checkpoint.c: do_migrate_process(): Wmaybe-uninitialized
- fs/proc/thread.c: proc_thread_maps_open(): Wmaybe-uninitialized
- shim_ipc_sysv.c: ipc_sysv_semctl_callback(): Wstrict-aliasing
- shim_socket.c: inet_save_addr(): Wstrict-aliasing
2019-10-14 12:57:17 -07:00
Dmitrii Kuvaiskii 85e950170f [LibOS] test/apps: Rewrite Bash example 2019-10-11 12:00:56 -07:00
Dmitrii Kuvaiskii d5e477fa47 [Pal/Linux-SGX] Remove "unmap TCS..." output message 2019-10-10 17:55:28 -07:00
Dmitrii Kuvaiskii b1ce2f1bed [LibOS] Add regression test for sgx.allow_file_creation 2019-10-10 16:15:01 -07:00
Dmitrii Kuvaiskii 488ab93d56 [Documentation] Add entry on sgx.allow_file_creation to old Wiki 2019-10-10 16:12:04 -07:00
Dmitrii Kuvaiskii 822b5a4475 [Pal/Linux-SGX] load_trusted_file(): fix uninitialized pointer
Previously, *stubptr was not initialized to NULL in the corner case of a
file created from inside of the SGX enclave. This led to a subsequent
failure in logic which tried to mmap an empty file (because it observed
that *stubptr contained some value).
2019-10-10 16:12:04 -07:00
Dmitrii Kuvaiskii efbd1d30a4 [LibOS] Return ENOENT on open_namei(path = "")
Applications like OpenVINO sometimes do open("") and expect ENOENT.
This corner case is correctly handled by Linux, so Graphene must have
the exact same semantics. Previously, open("") under Graphene resulted
in success, and subsequent read() failed.
2019-10-10 15:25:17 -07:00
borysp 7bb9ac7813 [LibOS] Do not delete futex_waiter from waiters list twice on FUTEX_WAIT 2019-10-10 13:02:25 -07:00
borysp a971a5c0b6 [LibOS] Add missing put_thread() calls
There were some places where put_thread() calls were missing. This
caused reference counter to never reach 0, so that the shim_thread
struct was never freed, thus leaking memory.
2019-10-10 13:02:25 -07:00
Michał Kowalczyk 2cf1b3cdc7 Remove __builtin_expect usages
We don't need this micro-optimization which just obfuscates the sources
for negligible performance gains. (Un)likeliness of branches in almost
all cases should be derived from profiling, not from hand-written hints,
using profile-guided optimization.
2019-10-10 14:44:52 +02:00
jack.wxz d702477503 [LibOS, Pal/{Linux,Linux-SGX}] Add EAFNOSUPPORT error code
Some hosts do not support IPv6 (e.g., Docker can be configured without
it). In this case, socket() host syscall will return EAFNOSUPPORT.
Some applications rely on this error code (e.g., Redis), so Graphene must
propagate this error code all the way to the application. This commit
makes LibOS and Linux/Linux-SGX PALs aware of this error code.
2019-10-09 19:07:57 -07:00
Thomas Knauth 9baa40eaa2 [LibOS] Rework checking of supported clone() flags 2019-10-09 02:35:42 +02:00
Don Porter 20ed9b14d2 Polish the top-level README 2019-10-08 18:42:20 -07:00
Chia-Che Tsai c1049a66a0 [LibOS] test/apps: Rewrite Lighttpd example 2019-10-08 16:21:16 -07:00
Thomas Knauth 59a0fee5ab [LibOS] Fix return code on exit due to signal
Previously, exit due to signal produced a return code of 0. This commit
correctly propagates the return code on exiting due to a signal. This
commit also adds two tests and updates graphene-tests submodule to
disable clone02 (this fix exposed an exotic unsupported combination of
clone flags).
2019-10-07 13:24:25 -07:00
Michał Kowalczyk bc0beaa253 Refactor alignment macros 2019-10-04 22:31:52 +02:00
Michał Kowalczyk b699fd7afd Introduce IS_POWER_OF_2 macro 2019-10-04 21:05:13 +02:00
Michał Kowalczyk 99677cdf72 Introduce ARRAY_SIZE macro 2019-10-04 21:05:13 +02:00
Michał Kowalczyk 0264cf6635 [Pal-SGX] Fix incorrect calculations in free_pages() 2019-10-04 21:05:13 +02:00
Michał Kowalczyk 817f516fce [Pal] Fix off-by-one in DkSetExceptionHandler 2019-10-04 21:05:13 +02:00
Rafał Wojdyła a04e71c7fa [Pal] Fix errors returned from mbedTLS crypto adapter
Most errors returned from mbedTLS functions were not converted to PAL errors.
This commit adds a separate PAL-error code block for crypto errors.
2019-10-03 16:42:50 -07:00
Isaku Yamahata eeb2daa2bf [Pal/Linux] _DkSystemTimeQuery() returns REALTIME instead of MONOTONIC now
_DkSystemTimeQuery() should return real time (CLOCK_REALTIME). The previously used
CLOCK_MONOTONIC returns time elapsed from an unspecified starting point
and is thus incorrect to use for system time.
2019-10-03 14:45:44 -07:00
Rafał Wojdyła 5dd8b60326 [Pal/Linux-SGX] Rework SGX types to be identical to the SGX SDK ones
Adopt public type definitions from the SGX SDK when possible. This will help
share code with SDK-using tools in the future when needed.
2019-10-02 19:33:14 -07:00
Michał Kowalczyk 5383e825a3 Rename strpartcmp_static to strstartswith_static 2019-10-02 22:22:05 +02:00
Michał Kowalczyk df6c52dff8 Fix strcmp_static semantics to match the standard strcmp 2019-10-02 22:21:11 +02:00
Michał Kowalczyk 0612bab52b Fix multiple bugs in string comparisons 2019-10-02 22:20:24 +02:00