331 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 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
borysp f71bd2ca84 [LibOS] Move helper threads' status checking after lock acquisition 2019-10-18 02:43:41 -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
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 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
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 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
Thomas Knauth c6a0151baf [LibOS] Fix and add a test case for resource leak on file close 2019-10-01 16:18:38 +02: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 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 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
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
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
Michał Kowalczyk de42ebabe1 Reformat repository to our clang-format rules 2019-09-09 22:11:23 +02:00
borysp 62ecb4bc79 [Makefile] Prevent gcc from generating trampolines 2019-09-04 03:10:33 +02:00
borysp 52b3525bab [LibOS] Fix nested function callbacks segfaulting 2019-09-04 03:10:33 +02:00
borysp 289ac3af4d [LibOS] Fix get_new_dentry reference count semantics
If `get_new_dentry` returns successfully, it increases returned dentry's
reference counter by one, which matches other similar functions' behavior.
2019-09-03 21:52:55 +02:00
borysp e23684bc3d [LibOS] Rewrite rename* syscalls
Present implementation is utterly broken, does not work even
in simplest cases.
2019-09-03 21:52:55 +02:00
Chia-Che Tsai d875e2eba7 [LibOS] Disable the warning when GIPC is not supported 2019-08-26 23:10:09 +02:00
Wojtek Porczyk 3928126a70 [Doc] Add Documentation/ stub 2019-08-21 18:30:16 +02:00
Isaku Yamahata 5f5bc5af56 [Pal, LibOS] Consolidate elf.h
There is no point in keeping the same elf.h in both Pal and LibOS.
2019-08-14 01:47:57 +02:00
Simon Gaiser 2c340b75d5 [Makefile] Check vdso.so only when it has been built 2019-08-14 00:50:29 +02:00
Simon Gaiser 517be2a241 [LibOS,Pal] Improve recursive Make calls
Do not declare the result of the recursive Make call as "phony" to avoid
unnecessary rebuilds. Due to the missing dependency information we of
course still need to always recurse.
2019-08-14 00:44:17 +02:00
Simon Gaiser 64e46adcc0 [Makefile] Use generated header dependencies
Fixes #189.
2019-08-14 00:44:17 +02:00
borysp 004c2fe9a4 [LibOS] Remove opened reference counter from struct shim_handle
Inside `struct shim_handle` `opened` reference counter is used incorrectly.
Additionally at this moment it guards the same resource (handle) as `ref_counter`,
making it obsolete. This patch removes `opened` counter and moves `close_handle`
logic into `put_handle`.
2019-08-13 16:20:44 -07:00
Isaku Yamahata a9681fd20c [LibOS] Do not queue unmasked SIG_IGN'ed signals to prevent memory leak
When signal is unmasked and its handler is SIG_IGN, this signal must not
be queued, otherwise such queued but unused signals result in memory leak.
Additionally, SIGCHLD signal can be discarded even if it is unmasked. For
reference, see Linux code (do_notify_parent() @ linux/kernel/signal.c).
2019-08-13 15:47:54 -07:00
Isaku Yamahata bc715c2081 [LibOS] Fix memory leak in shim_do_execve_rtld()
__libcc_tcb_t is leaked. It should be allocated from stack.
2019-08-13 20:47:34 +02:00
Isaku Yamahata 1e977ecc71 [LibOS] shim_do_execve_rtld(): defer disabling preemption
Defer disabling preemption until a point of no-return. Otherwise on
return path the function can return with preemption disabled.
2019-08-13 20:47:34 +02:00
Chia-Che Tsai f2591790d7 [LibOS] Fix timeout resolution for epoll_wait()/epoll_pwait()
Internal LibOS and PAL interfaces use microseconds (us) for timeout
values. However, Linux epoll_wait/epoll_pwait syscalls use milliseconds
(ms) for timeout. Previously, there was a bug in timeout resolution
because epoll_wait() emulation did not convert from ms to us. This
commit fixes this bug and also adds suffixes "_ms" and "_us" to make the
time units used explicit.
2019-08-08 17:37:39 -07:00
Isaku Yamahata 040dfb86a9 [LibOS] Make parse_clone_flags() show exit signal name for clone() 2019-08-02 13:31:09 -07:00
Isaku Yamahata 1ce3d545aa [LibOS/vDSO] Add new rule to Makefile to verify vDSO has no relocations 2019-08-02 12:41:57 -07:00