561 Commits
Author SHA1 Message Date
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 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 4379d74d8e [LibOS] test/apps: Add OpenVINO example 2019-10-18 19:38:48 -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
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
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
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 b1ce2f1bed [LibOS] Add regression test for sgx.allow_file_creation 2019-10-10 16:15:01 -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
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
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
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
Michał Kowalczyk a0a996904d [LibOS] Fix a typo in large_dir_read test 2019-10-02 03:23:33 +02:00
Michał Kowalczyk 44e186c503 Clean up asserts
- Make assert() a no-op in non-debug builds.
- Use static_assert for compile-time asserts.
- Fix assert() implementation (previous version didn't work for
  expressions with types larger than long, it also always printed
  `(value:0)`).
- Clean up calls to asserts.
2019-10-02 03:22:52 +02:00
Michał Kowalczyk a6e1524e6e Clean up handle_ops and PAL_HANDLE usage 2019-10-02 03:22:28 +02:00
Dmitrii Kuvaiskii da21b2e000 [LibOS] test/apps: Move benchmark-http.sh to common_tools
This commit concerns web-server examples: Apache, Nginx, and Lighttpd.
Previously, benchmark-http.sh bash script was located under lighttpd
directory, and Apache and Nginx had symbolic links to it. This is
unintuitive. This commit moves benchmark-http.sh to a newly created
common_tools directory, and all web-server examples have symbolic links
to this new dir.
2019-10-01 19:28:20 -07:00
Thomas Knauth c6a0151baf [LibOS] Fix and add a test case for resource leak on file close 2019-10-01 16:18:38 +02:00
Dmitrii Kuvaiskii b81c808589 [LibOS] test/apps: Rewrite Nginx example 2019-09-30 21:53:48 -07:00
Isaku Yamahata 55e0bb1c6a [LibOS] Force variable update on tcb.test_range.has_fault in test_user_memory()
In test_user_memory(), a memory range is tested via probing of each page
in the range. If the memory page was not allocated, it leads to a
segfault which is captured by the LibOS memfault_upcall() and reported
in the variable tcb.test_range.has_fault. However, the compiler may
optimize away accesses to this variable in test_user_memory(), believing
it is never updated anywhere else. This commit introduces a memory
barrier to prevent this compiler optimization (same for test_user_string()).
2019-09-30 20:56:18 -07:00
Michał Kowalczyk 6e67342ba8 [LibOS] Fix incorrectly git-ignored glibc-patches dir 2019-10-01 00:48:00 +02:00
Michał Kowalczyk 6ba48bdf59 [LibOS] shim_profile: Simplify no-op macros 2019-10-01 00:48:00 +02:00
Michał Kowalczyk 62cbf79603 Fix a bunch of typos 2019-10-01 00:48:00 +02:00
borysp 323be6717d [LibOS] Change minimal file descriptor number to be 0
Previously, set_new_fd_handle() started searching for the first free fd
from 1 not 0. This commit fixes this, plus refactors this function.
2019-09-30 15:49:32 -07:00
Dmitrii Kuvaiskii 0b6809fc19 [LibOS] Do not get/put handles when adding/removing from epoll
Previously, Graphene explicitly incremented refcount of a handle added
to/removed from epoll, in epoll_ctl(EPOLL_CTL_ADD/EPOLL_CTL_DEL).
However, according to epoll(7), closing a file descriptor causes the
FD (handle) to be removed from all epoll sets. In other words,
adding/removing a handle to/from epoll must not count towards refcount
of the handle. Otherwise the handle remains dangling in the epoll set
even if it was close()'d (this particular case led to Nginx segfault).
This commit removes get/put of handle during epoll add/remove.
2019-09-28 15:31:41 +02:00
Dmitrii Kuvaiskii 1645e3435f [LibOS] Allow repeated listen() on the same socket
Typically, listen() is called only once by the application, to mark the
socket as passive for listening for client connections. Thus, LibOS had
a state machine that forbade performing repeated listen() syscalls on
the same socket. However, at least Nginx issues repeated listen's to
adjust the backlog parameter. This commit allows such corner cases.
2019-09-28 15:31:41 +02:00
Simon Gaiser 2d29f7aaeb [Makefile] Drop SGX_RUN
For detection of SGX/non-SGX (for example in regression tests) always
use the SGX environment variable. To generate launch/EINIT tokens use
the new 'sgx-tokens' Make target.
2019-09-27 12:38:14 +02:00
Simon Gaiser 13cac1df92 [Makefile] Fix missing cleans 2019-09-27 03:45:21 +02:00
Simon Gaiser 7ce7278121 [Pal/Linux-SGX] Add memory gap around 'exec' area
For this also add the user_address_hole memory range to pal_control.
This is needed to communicate (in a not SGX specific way) the reserved
memory range for the memory gaps around the exec area which can be
inside of the user_address range.
2019-09-26 02:39:03 +02:00
Chia-Che Tsai ee3619df4f [LibOS] test/apps: Rewrite Apache example 2019-09-25 15:03:34 -07:00
borysp 9cd6b34747 [Pal] Change the way argv[0] is handled
Before argv[0] was treated specially and was changed to a value
from manifest file. Now this happens only if binary was run as
a manifest i.e. `./pal_loader path_to_manifest_file`.
2019-09-25 19:16:48 +02:00
Isaku Yamahata 6e3c45c8e3 [Pal/Linux-SGX] pal-sgx-get-token, pal-sgx-sign: move to Python3 and cleanup
This commit rewrites pal-sgx-get-token and pal-sgx-sign in Python3 and
performs a comprehensive cleanup of the code:
- Outputs are sent to separate files (otherwise they were intermixed
  during parallel build)
- aesm_pb2.py is re-generated to Python3
- Numeric constants are replaced with symbolic ones
- Using argparse instead of home-grown argument parsing
- Replacing home-grown helper funcs int_to_bytes(), bytes_to_int(), etc.
  with standard functions
2019-09-24 00:24:26 -07:00
Dmitrii Kuvaiskii 57d9e3347d [LibOS] Fix typo in handle_copy() which led to failed sendfile() 2019-09-18 17:14:12 -07:00
Dmitrii Kuvaiskii 07f0e25ff2 [LibOS] shim_parser.c: Additionally specify string as "const char*"
The parser logic checks the arguments of syscalls and prints strings in
debug output. Previously, our code base only contained "const char *" as
strings. Recently, we started migration to "const char*" (no-space) style.
This broke the parser logic, so this commit adds an additional check on
what it means for a C type to be a string.
2019-09-18 15:36:11 -07:00
Isaku Yamahata 4e1d892891 [LibOS] Add missing memory barrier in regression/mmap-file.c
Previously, the test could fail if the compiler changed the order of
variable assignments (`message` vs `a[4096]`).
2019-09-18 21:55:42 +02:00
Dmitrii Kuvaiskii 5602cec15b [LibOS] fs/proc/fs.c: Remove gotos and redundant vars in proc_match_name() 2019-09-18 04:41:09 +02:00
Dmitrii Kuvaiskii 05fa2ba8c0 [LibOS] fs/proc/fs.c: Use proc_dir.size instead of proc_dir.name == NULL
Previously, there was a bug in proc_match_name(): iteration over a
proc_dir array relied on proc_dir.name == proc_dir.nm_ops == NULL.
However, there is no sentinel NULL item in actual arrays, which led to
undefined behavior. This commit changes the for-loop condition to
check proc_dir.size and not rely on the NULL item.
2019-09-18 04:41:09 +02:00