Commit Graph
640 Commits
Author SHA1 Message Date
jack.wxz 99193dc1f7 [LibOS] Avoid gaps due to partial reads in iovecs in recvmsg()
Syscall recvmsg() accepts an array of buffers (iovecs). This buffers are
filled in array order. POSIX does not allow to fill e.g. iov[0] only
partially before proceeding to iov[1]. This commit makes recvmsg()
emulation compliant with this requirement.

Also, this commit fixes a small performance issue when recvmsg() would
overwrite the same received-address info over and over.
2020-01-10 19:19:33 -08:00
borysp 5cb7623e8d [Tests] Update tests submodule commit 2020-01-10 23:31:53 +01:00
borysp 599425ed07 [LibOS] Fix some bugs related to O_DIRECTORY handling 2020-01-10 23:31:53 +01:00
Michał Kowalczyk f1c334357c Reformat repository to our clang-format rules (2nd iteration) 2020-01-09 02:35:50 +01:00
Isaku Yamahata f8f6a0c42f [LibOS] Replace init_fs_base() with update_fs_base()
Now init_fs_base() is same to update_fs_base() except struct shim_thread
argument which is unused.
2020-01-08 01:20:26 +01:00
Isaku Yamahata 1902c3862b [LibOS] Use set_cur_thread() to associate shim_tcb_t and shim_thread
Uniformly use set_cur_thread() to associate shim_tcb_t to struct
shim_thread. Remove unnecessary logic from init_fs_base() and
update_fs_base().
2020-01-08 01:20:26 +01:00
Isaku Yamahata 29bd2bdf9c [LibOS] Use uint64_t intead of unsigned long for GP register type 2020-01-08 01:06:58 +01:00
Isaku Yamahata a7cb199b9a [LibOS] Optimize shim_get_tcb() and its variants
- apply SHIM_TCB_GET() and SHIM_TCB_SET()
- remove dead code
2020-01-08 01:06:52 +01:00
Dmitrii Kuvaiskii 1b10217cee [LibOS] test/apps: Enable select/pselect/poll/epoll tests in LTP 2020-01-07 13:57:45 -08:00
Dmitrii Kuvaiskii da2dd37dd8 [LibOS, Pal/{Linux,Linux-SGX}] Better emulation of polling
This commit improves the emulation of polling mechanisms (select,
pselect, poll, ppoll, epoll_wait) and cleans up the corresponding
code:
- New DkObjectsWaitEvents() PAL interface, replaces the inefficient
  DkObjectsWaitAny() interface. This interface closely resembles
  Linux/POSIX poll() in semantics.
- Improved shim_do_epoll_wait() implementation, now using the new
  DkObjectsWaitEvents() interface.
- Improved shim_do_poll() implementation, now using the new
  DkObjectsWaitEvents() interface.
- Small cleanups of polling code.
2020-01-07 12:11:00 -08:00
Dmitrii Kuvaiskii 56bc2b49ad [LibOS] Comprehensive cleanup of epoll_create()/epoll_ctl()/epoll_wait()
Accurate cleanup of shim_do_epoll_create1(), shim_do_epoll_ctl(),
shim_do_epoll_wait(), and other epoll helper functions. This cleanup
also adds error handling (missing previously).

The commit makes (most of) the corresponding LTP tests pass now.

Note that epoll semantics are still incorrect and inefficient: current
epoll_wait() emulation returns only one event to the user.
2020-01-07 12:11:00 -08:00
Dmitrii Kuvaiskii 3e2c8ed9d2 [LibOS] Comprehensive cleanup of poll()/ppoll()/select()/pselect()
Accurate cleanup of shim_do_poll(), shim_do_ppoll(), shim_do_select(),
and shim_do_pselect6(). This cleanup also adds error handling (missing
previously).

The commit adds four LibOS regression tests on poll, ppoll, select,
and pselect mechanisms. Also, the corresponding LTP tests pass now.
2020-01-07 12:11:00 -08:00
Thomas Knauth 15be96fbae [LibOS] Correctly release resources in str_close() 2020-01-07 03:52:31 +01:00
Dmitrii Kuvaiskii 36dfe1665e [LibOS] Disallow eventfd emulation by default
Eventfd emulation currently relies on the host, thus eventfd syscalls
are disallowed by default due to security concerns. To use them, they
must be explicitly allowed through "sys.allow_insecure_eventfd" in
the manifest.
2020-01-06 17:22:29 -08:00
borysp 1bf6423384 [LibOS/Pal] Replace hardcoded URI prefix strings 2020-01-06 16:17:26 -08:00
Michał Kowalczyk ea1a1d961c [LibOS] tests: Fix missing/wrong return values from main() 2020-01-06 03:49:23 +01:00
Isaku Yamahata af7a7c2f3a [LibOS] clone: Remove stale comment 2020-01-01 20:12:26 +01:00
Dmitrii Kuvaiskii 7d99d4788c [LibOS,Pal] Remove Graphene IPC completely
Graphene IPC (GIPC) was introduced to perform faster bulk IPC by sharing pages as copy-on-write
across processes. This feature became stale, and it was shown that recent Linux kernels (4.2+)
have zero-copy transfers over UNIX sockets and exhibit similar performance. GIPC is not built and
not tested in Jenkins. Also, GIPC does not work under SGX. This commit completely removes GIPC.
2019-12-30 12:17:51 -08:00
borysp 3d662b49cd [LibOS] Add futexes tests 2019-12-19 22:04:12 -08:00
borysp 6cfaf420b3 [LibOS] Rework futexes implementation
This commit completely rewrites futex implementation to (hopefully)
remove all races (both on memory access level and between waits and
wakes), make it compatible with actual Linux implementation and make
it more maintainable and readable.
2019-12-19 22:04:12 -08:00
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