620 Commits
Author SHA1 Message Date
Wojtek Porczyk ec416115eb [LibOS] test/apps/ltp: Fix reporting of results 2019-12-18 12:14:38 +01:00
Dmitrii Kuvaiskii b8a955c826 [LibOS/regression] Add test for host root FS
Graphene supports a special "root FS" parameter in the manifest:
"fs.root". This commit adds a test that uses this parameter.
2019-12-18 02:59:02 -08:00
Dmitrii Kuvaiskii 05cc50945f [LibOS] Allow inaccessible files during getdents()
Previously, if user performed getdents() on a directory containing
inaccessible files (because user doesn't have permission), whole
getdents failed with -EACCES. This is incorrect behavior: files must
still be listed. This commit fixes the root cause of this bug by
marking inaccessible files as DENTRY_NEGATIVE.
2019-12-18 02:59:02 -08:00
Dmitrii Kuvaiskii 860e1083a2 [LibOS] test/regression: Enable exit_group test on SGX
Previously, exit_group test was disabled on Linux-SGX PAL. It was
disabled because the PAL incorrectly exited threads. The latest
commits fix this, and the test can be re-enabled.
2019-12-18 01:56:25 -08:00
Dmitrii Kuvaiskii 7c45430355 [LibOS] Remove the data race on thread::is_alive
Previously, there was a data race on thread::is_alive between one thread
checking whether it is the last thread alive via check_last_thread() and
another thread exiting via thread_exit(). The former checks if is_alive
is true, the latter sets it to false. However, the exiting thread will
truly exit only after it called DkThreadExit(), thus the race on is_alive
led to scenarios where two threads believe to be the last threads alive
and compete on terminating Async Helper/IPC threads and exiting the whole
process. This commit introduces cleanup_thread() called by Async Helper
to set is_alive to false and delete the thread, freeing its resources.
The data race is thus removed, and shim_thread object leak is prevented.
2019-12-18 01:56:25 -08:00
Dmitrii Kuvaiskii b4673dc171 [Jenkins] Add Redis test to all Jenkins pipelines
Redis is tested with select() syscall on 16.04 pipelines and with
epoll() on 18.04 pipelines.
2019-12-14 12:53:45 -08:00
Isaku Yamahata c6042ce762 [LibOS] test/apps: Enable ltp/kill12 2019-12-13 09:24:15 +01:00
Michał Kowalczyk 3072efe253 [LibOS] test/apps: Mention dependencies in cURL's readme 2019-12-11 05:01:32 +01:00
Isaku Yamahata 74ce0ae3e1 [LibOS] Copy signal handler's __kernel_sigaction in get_new_thread()
Previously, there was a bug in copy of the shim_thread::signal_handles[].action
due to sizeof on the wrong type (shim_signal_handle instead of __kernel_sigaction).
This led to incomplete action object in signal_handles[].
2019-12-10 14:29:22 -08:00
Dmitrii Kuvaiskii b194aa17fb [LibOS,Pal] Correctly emulate CLONE_CHILD_CLEARTID
When child thread exits, it wakes up its parent if CLONE_CHILD_CLEARTID was set
during clone() call. Previously, this was done by the child thread itself as
part of its own clean-up in release_clear_child_id(). But this child thread is
still alive at this point and uses some resources, most notably the stack (that
might have been provided by the parent) and the SGX TCS slot. Upon waking up,
the parent might decide to free that stack (as Pthreads do) or re-use the TCS
slot, causing data races.

This commit introduces a correct emulation of CLONE_CHILD_CLEARTID:
- A new argument `PAL_PTR clear_child_tid` is added to DkThreadExit();
  it points to internal Graphene memory that is erased on child exit to notify
  Async Helper thread.
- At PAL layer, when thread finally exits, it sets PAL-level *clear_child_tid = 0
  (corresponds to &clear_child_tid_val_pal at LibOS level);  this signals to LibOS
  layer that the thread stopped using resources.
- At LibOS layer, Async Helper thread is set up to wait for the signal from
  PAL; it is now the responsibility of Async Helper thread to call
  release_clear_child_id() to wake up the parent thread.
- Async Helper thread waits for clear_child_tid_val_pal == 0 and then sets
  the actual clear_child_tid to 0 and wakes up the waiting parent.

Note that for Linux-SGX PAL, clear_child_tid is set to 0 not immediately
but as part of handle_thread_reset, otherwise the TCS slot could be still
occupied when LibOS wakes up the parent.

As a side effect, the LibOS code for threads/process exit is cleaned up.

This commit also fixes all regression tests to use the new signature of
DkThreadExit() and increases the number of SGX threads slightly (to
accommodate the newly used Async Helper thread).
2019-12-03 21:19:07 -08:00
Dmitrii Kuvaiskii c245f303ad [LibOS/regression] Fix syscall arguments in futex test 2019-12-03 21:10:55 -08:00
Dmitrii Kuvaiskii ca4fdab7bc [LibOS] test/apps: Skip meaningless signal06 test in LTP
The LTP test signal06 is a regression test for some obscure bug in older
Linux kernels. It uses SIGHUP and SIGSEGV signals to test mprotect() of
altstack. Since SIGHUP is completely ignored by Graphene, and altstack is
not correctly emulated, and mprotect() doesn't work, this test never made
sense for Graphene. This commit disables it.
2019-12-03 17:34:27 -08:00
Chia-Che Tsai 5384141b97 [LibOS] test/apps: Rewrite LMBench 2.5 example 2019-12-03 16:36:13 -08:00
Dmitrii Kuvaiskii 99b744ef27 [LibOS] test/apps: Add Node.js example 2019-12-03 15:01:31 -08:00
Rafał Wojdyła baab561a75 [LibOS] Add tests for some typical FS use cases
These tests perform common FS operations in various ways:
- open/close
- read/write
- create/delete
- read/change size
- seek/tell
- memory-mapped read/write
- copy directory in different ways

Tests use both direct syscalls and stdio wrappers (FILE).

To run, call `make test` in `LibOS/shim/test/fs`.
2019-12-03 15:25:47 +01:00
Isaku Yamahata c40b333728 [LibOS] Trigger callbacks only after list traversal in Async Helper
In Async Helper thread, async_list is protected by async_list_lock.
Previously, this thread unlocked async_list_lock on each detected
triggered entry to perform a callback during traversal of async_list
(unlocking is needed because it is unknown how much time the callback
takes to execute). However, once we unlock, the list may become
unstable (install_async_event may delete/append an entry). Then, next
FOR_EACH_LIST_SAFE list entry may be freed while trigering callback,
and the next iteration may try to dereference this invalid pointer.
This commit alleviates this scenario by creating a temporal list of
triggered entries and performing all callbacks after list traversal.
2019-12-03 05:15:47 -08:00
Dmitrii Kuvaiskii ce7e029d9b [LibOS] test/apps: Improve README and Makefile of TensorFlow 2019-12-02 20:04:40 -08:00
borysp 807004c132 [LibOS] Allow for NULL pointers in memfault_upcall 2019-12-03 01:16:13 +01:00
borysp 1939b76502 [LibOS] Test user pointer in pipe parser (used for debugging) 2019-12-03 01:15:51 +01:00
Isaku Yamahata 250dcb7aea [LibOS] Fix gcc-9 warning
This patch removes __attribute__((packed)) to eliminate warnings gcc-9
generates. Example:

> warning: taking address of packed member of struct poll_handle may result in an unaligned pointer value [-Waddress-of-packed-member]

Packed attribute is used for structures using which Graphene processes
communicate with each other. We don't implement privilege separation, so
it's ok to leak data in struct paddings.

If the padding is really a concern, we could:
- Define two structures, a packed one for serialization and a non-packed
  one for code, and then explicitly (de)serialize.
- Define the structure fields with an explicit size (e.g. uint64_t
  instead of long), carefully add explicit padding and then zero it out
  before sending.
2019-12-02 23:55:48 +01:00
Isaku Yamahata 03f9e2cf1e [LibOS] Rename clone_args to shim_clone_args
Linux already defines `struct clone_args` for clone3. Rename LibOS one
to avoid name collision.
2019-12-02 23:53:29 +01:00
Jia Zhang 6b2e9bb9a2 [LibOS] Stop building tests after encountering an error 2019-12-02 23:02:53 +01:00
Jia Zhang 3e7397b173 [Makefiles] Don't include *.d files when cleaning 2019-12-02 23:02:44 +01:00
Wojtek Porczyk 101371683a [LibOS] Sanitize glibc build script
The academic-quality build script was supplanted by industry-grade
Makefile rule.

Also, glibc 2.19 is not supported, because it is not present in any
supported distro.
2019-12-02 18:50:13 +01:00
Dmitrii Kuvaiskii 295ef8ba6c [LibOS] test/apps/bash: Add trusted libraries required for Ubuntu 18.04 2019-12-02 04:29:18 +01:00
Krishnakumar, Sudha 80968492b8 [LibOS, Pal] Correctly migrate eventfd descriptors on fork() 2019-11-30 17:09:44 -08:00
Rafał Wojdyła 19f5433981 [LibOS] Call DkStreamFlush() when flushing chroot handles 2019-11-30 22:32:40 +01:00
Dmitrii Kuvaiskii e14bf7950f [LibOS] Allow Graphene-SGX to occupy the same process on execve()
The execve() syscall starts a new executable in the *same* process. Previously,
Graphene followed this convention *only* for non-SGX PALs. If PAL was Linux-SGX,
Graphene silently terminated the process and created a new one.

This deviation from standard execve() behavior resulted in the host shell
becoming detached from the Graphene-SGX process. In turn, this led to our
Bash example (on Ubuntu 18.04, bash version 4.4.19) "terminating" early
from the point of view of Jenkins, and SGX-18.04 pipeline failed.

This commit allows Graphene-SGX to execve() in the same process, but only if it
is the same executable (as in the Bash example). It is still impossible to
execve() in the same process for a different executable since this requires a
new SGX enclave measurement and thus demands a new process.
2019-11-29 15:18:56 -08:00
Dmitrii Kuvaiskii 73e9ed2e8a [Jenkins] Add Nginx test to all Jenkins pipelines 2019-11-28 19:41:17 -08:00
Dmitrii Kuvaiskii 63f1e0a2e6 [LibOS] test/apps: Rewrite Curl example
This commit also adds Curl to Jenkins tests.
2019-11-28 16:48:19 -08:00
Jia Zhang dc060bca3b [Makefiles] Link Graphene libraries in a fixed order
Previously, Graphene libraries were built using `wildcard` make function.
The output of this function (list of files) is non-deterministic (list items
can be in any order). This results in different SGX measurements on rebuilds.

In some build environments (e.g., a dedicated Graphene container), it is
important to keep these measurements deterministic. This commit achieves this
by removing wildcards and explicitly specifying required files.
2019-11-27 17:16:34 -08:00
Chia-Che Tsai ffe2366beb [LibOS] test/apps: Rewrite Python example
There are two Python3 examples now:
- python-simple contains simple and secure Python3 scripts;
- python-scipy-insecure contains SciPy and NumPy insecure Python3 scripts.

Both examples are tested in Jenkins.
2019-11-27 15:39:48 -08:00
Michał Kowalczyk bae8baa2dd [LibOS] Merge page size and allocation alignment
Those two values are currently (and we don't think this will ever
change) indistinguishable from each other from the LibOS perspective.
2019-11-27 00:31:35 -08:00
Isaku Yamahata 51b4714e2c [LibOS] Rename SHIM_TLS_CANARY -> SHIM_TCB_CANARY 2019-11-26 12:44:08 -08:00
Isaku Yamahata b42a8a9f0f [LibOS] Move shim_thread:fs_base to shim_context::fs_base
fs_base is now an opaque value of FS register. It belongs to shim_context.
2019-11-26 12:44:08 -08:00
Isaku Yamahata f53ea3a7cb [LibOS] Rename shim_tls.h to shim_tcb.h 2019-11-26 12:44:08 -08:00
Isaku Yamahata 3ec3c078fa [LibOS] Rename shim_tls_check_canary() to shim_tcb_check_canary() 2019-11-26 12:44:08 -08:00
Isaku Yamahata f5a8d8ac3c [LibOS] Remove IN_SHIM macro in shim_tls.h 2019-11-26 12:44:08 -08:00
Isaku Yamahata 2cb174cd8e [LibOS] Eliminate GLIBC_DISABLE_VDSO and remove vdso-related patch to Glibc 2019-11-25 17:29:58 -08:00
jack.wxz cea63a7101 [LibOS] Always unset SIGKILL and SIGSTOP in set_signal_mask()
POSIX guarantees that SIGKILL and SIGSTOP are silently ignored even if
supplied to sigprocmask() and co. This commit adds handling of this case.
2019-11-22 14:46:08 -08:00
Jia Zhang f52bc9e0f4 [LibOS/benchmark] Fix generation of SGX tokens 2019-11-19 15:41:14 -08:00
Dmitrii Kuvaiskii 186f41e65c [LibOS] Add dummy implementation of Linux-specific mbind()
This call is used by libnuma. Always returning success is currently enough.
2019-11-15 11:35:17 -08:00
Dmitrii Kuvaiskii fed201c622 [LibOS] test/apps: Force TensorFlow's Makefile to use GRAPHENE envvar 2019-11-14 12:26:36 -08:00
Isaku Yamahata ffbe62254e [LibOS/Glibc] Remove struct shim_tcb embedded in Glibc TCB
Previously, struct shim_tcb was embedded in Glibc's TCB but recent
commits to Graphene move shim_tcb to PAL's TCB. Thus, this commit
removes inserting shim_tcb from Glibc patches.
2019-11-12 22:14:53 -08:00
Isaku Yamahata d51f84f547 [LibOS] Rename shim_get_tls() to shim_get_tcb() for consistency 2019-11-12 19:46:54 -08:00
Isaku Yamahata e4f90b1eec [LibOS] Rename allocate_tls()/populate_tls() to init_fs_base()/update_fs_base() 2019-11-12 19:46:54 -08:00
Isaku Yamahata fde7cc1d6a [LibOS] Rename shim_thread::tcb to fs_base
Now, shim_thread::tcb is used only as an integer value for %fs_base,
and shim_thread::user_tcb is not needed anymore. This commit renames
shim_thread::tcb to shim_thread::fs_base and removes user_tcb.
2019-11-12 19:46:54 -08:00
Isaku Yamahata 0f0c64c4af [LibOS] Remove reserve argument from init_stack() 2019-11-12 19:46:54 -08:00
Isaku Yamahata 5f13f730e9 [LibOS] Use %gs register for LibOS TCB (shim_tcb)
For binaries statically linked against Glibc, %fs register cannot be
used for LibOS TCB (shim_tcb) because it is already used by Glibc.
Thus, this commit moves shim_tcb into PAL TCB. Also, now that LibOS
doesn't access Glibc TCB (__libc_tcb), we make it an opaque pointer
used only for clean up.
2019-11-12 19:46:54 -08:00
Isaku Yamahata dafdb1d47b [LibOS/regression] Multiple fixes for the futex test
- Loop on futex(WAKE) when no thread is awaken.
- Use pthread instead of raw clone() because clone() does not
  initialize Glibc TCB, thus any function call to Glibc results
  in SIGBUS.
2019-11-12 19:46:43 -08:00