Commit Graph
674 Commits
Author SHA1 Message Date
Isaku Yamahata 32a89d1d23 fixup! [LibOS] initialize fp state values and add helper functions 2020-02-03 19:24:39 -08:00
Isaku Yamahata e25d4cd5c6 fixup! [LibOS] use dedicated syscall stack and set signal frame on signal 2020-02-03 19:16:26 -08:00
Isaku Yamahata 996fe8c562 fixup! [LibOS] allocate stack dedicated for LibOS 2020-02-03 19:16:26 -08:00
Isaku Yamahata e2825c5ef2 fixup! [LibOS] allocate stack dedicated for LibOS 2020-02-03 15:36:40 -08:00
Isaku Yamahata 99e8f22c87 fixup! [LibOS] use dedicated syscall stack and set signal frame on signal 2020-02-03 14:20:27 -08:00
Isaku Yamahata 01076d0990 fixup! [LibOS] use dedicated syscall stack and set signal frame on signal 2020-01-31 21:50:20 -08:00
Isaku Yamahata 65c8daf010 fixup! [LibOS] allocate stack dedicated for LibOS 2020-01-31 21:38:30 -08:00
Isaku Yamahata 5011d2356a fixup! [LibOS] initialize fp state values and add helper functions 2020-01-31 21:38:30 -08:00
Isaku Yamahata 23a75af57e fixup! [LibOS] make sigreturn emulation nofp code 2020-01-31 21:38:29 -08:00
Isaku Yamahata f20698a5d8 fixup! [LibOS] initialize fp state values and add helper functions 2020-01-31 21:38:29 -08:00
Isaku Yamahata a90a6180ce [LibOS] use dedicated syscall stack and set signal frame on signal
For syscall emulation, use dedicated stack for it.
If application stack is small(e.g. go goroutines), stack overflow happens
and crash. Especially when pushing all the GP registers at the beginning
of syscalldb.
In order to avoid it, allocate dedicated stack area for syscall emulation
and switch them back and forth.

When LibOS emulates unix signal,
- If app is interrupted, setup signal frame directly and return.
- If Pal or LibOS is interrupted, it means app invoked system call and
  interrupt. Queue it and check if the signal is queue when LibOS returns to
  app and setup signal frame.
- implemented sigreturn and sigaltstack
So LibOS isn't re-entered by signal emulation because app signal handler
isn't triggered while Pal or LibOS is interrupted.
2020-01-30 17:34:58 -08:00
Isaku Yamahata 8759cb8e08 [LibOS] allocate stack dedicated for LibOS
Allocate dedicated stack for LibOS to use.
The actual use is done by the following patch.
2020-01-30 13:51:45 -08:00
Isaku Yamahata 708588420c [LibOS] initialize fp state values and add helper functions
To save/restore fp registers for signal emulation, introduce helper functions
and initialize on start up.
2020-01-30 13:51:45 -08:00
Isaku Yamahata 794a7f0de8 [LibOS] make sigreturn emulation nofp code
sigreturn needs to restore fp registers.
To avoid interferance to colobber fp registers, make the code path nofp code.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2020-01-29 23:49:14 -08:00
Isaku Yamahata 51d98ff8de [LibOS] add aligment to bkeep_unmapped{,_any}
enhance bkeep_unmapped{,_any} to support alignement.
It will be used later.
2020-01-29 23:49:14 -08:00
Isaku Yamahata 68cfef73b2 [LibOS] remove offset argument to bkeep_unmapped{,_any}
offset argument to bkeep_unampped{,_any} is useless. So remove it.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2020-01-29 23:49:14 -08:00
Isaku Yamahata 7daf9c37f0 [LibOS] export syscall_wrapper 2020-01-29 23:49:14 -08:00
Isaku Yamahata 509135491b add generated-cacert.h and glibc-build to .gitignore 2020-01-29 11:29:15 -08:00
Dmitrii Kuvaiskii 735f54d22c [LibOS,Pal/{lib,Linux-SGX}] Add TLS-PSK protection to process checkpoint IPC
Previously, Graphene-SGX did not protect send/recv of checkpoint from
parent to child. This leaked all memory contents of the parent process.

This commit adds TLS-PSK (TLS with Pre-Shared Key) wrapper for process
communication. Graphene-SGX already has the logic for SGX-based local
attestation and generation of the shared key for each parent <-> child
communication channel via Diffie–Hellman key exchange. This commit
uses this pre-shared key to create an mbedTLS-based session based on
UNIX domain socketpair (parent.process.stream <-> child.process.stream).

_DkStreamSecure{Init,Free,Read,Write} internal Linux-SGX PAL functions
are added and used during child process creation and sending of the
parent-generated checkpoint. These functions are backed by crypto-layer
lib_SSL{Init,Free,Read,Write} functions which in turn use mbedTLS.
Configuration of mbedTLS is expanded to support TLS-PSK; note that for
entropy source we use only rdrand instruction inside SGX enclave (i.e.,
no untrusted host-platform sources of entropy). The only ciphersuite
currently supported for IPC is MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256.

This commit adds protection only for checkpoint IPC. After the checkpoint
is sent/received, the parent/child processes downgrade their sockets to
plain non-secure ones (by disabling TLS). This is done because child
may spawn a grandchild that also wants to communicate with grandparent,
but it is impossible for multiple processes to share same TLS context.

Additionally, this commit sanitizes "process" PAL handles during send-
handle checkpoint send (via DkSendHandle): shared key and TLS context
are zeroed out.
2020-01-28 13:05:48 -08:00
Michał Kowalczyk e09ac87321 [LibOS] test_libos.py: Simplify test_001_strict_fail 2020-01-28 17:03:32 +01:00
Isaku Yamahata 621b6a34b9 pylint: Eliminate pylint warnings in test_{pal,libos}.py 2020-01-28 03:45:04 +01:00
Dmitrii Kuvaiskii a1c340b60b [LibOS] Add EINVAL and EFAULT checks for {get,set}sockopt() 2020-01-25 22:39:56 +01:00
Dmitrii Kuvaiskii eb4849d23a [LibOS] Allow all getsockopt() before bind()
Previously in Graphene, some getsockopt() syscalls, e.g. TCP_NODELAY,
failed because an underlying PAL handle was't created for the LibOS
handle until bind() was called. Thus, a sequence of accept() and
getsockopt() failed. This commit fixes this by returning default
socket options (possibly augmented with setsockopt values). Test
case is also provided.
2020-01-25 22:39:56 +01:00
Yunjong Jeong 9df502b4ab [Pal/Linux-SGX] Add manifest option sgx.enclave_pal_file
Path to enclave file had been a fixed string that is determined at
build time. Therefore Runtime binares were not allowed to move
their location. This commit adds sgx.enclave_pal_file manifest
option to specify the uri of libpal-Linux-SGX.so.
2020-01-26 01:54:46 +09:00
Dmitrii Kuvaiskii 5784d97375 [LibOS] Allow MSG_PEEK on recv()
Previously, Graphene failed if recv() contained MSG_PEEK flag. This
resulted in many TLS-based applications failing, including Nginx,
Apache, and Lighttpd in SSL/TLS mode. This commit adds emulation of
MSG_PEEK at LibOS level. A simple TCP test case is provided.
2020-01-25 02:26:59 +01:00
Dmitrii Kuvaiskii 3def3a6ba6 [LibOS] Allow poll/ppoll/select/pselect on regular and dev files
Previously, Graphene incorrectly handled poll/ppoll/select/pselect
of regular and dev files like `/dev/urandom`: it tried to perform
an actual host-OS poll on these files. However, poll of such files
must be emulated completely inside LibOS. This commit adds this
special case to poll/ppoll/select/pselect. A test case is supplied.
2020-01-25 02:26:59 +01:00
Dmitrii Kuvaiskii 4485f5af98 [LibOS] Allow LibOS handles without backing PAL handles in epoll
Previously, Graphene failed with -EPERM on epoll_ctl(EPOLL_CTL_ADD)
of a LibOS shim handle without a backing PAL handle. However, it is
possible for a LibOS socket handle to not have a PAL handle: if
user app first creates the handle via socket(), then adds it to epoll
via epoll_ctl(), and only then performs bind() at which point PAL
handle is finally created. This commit removes this restriction.
2020-01-25 02:26:59 +01:00
borysp 2ddd53b102 [LibOS] Add spinlocks asserts to futexes 2020-01-21 22:45:57 +01:00
borysp 6a6a852fb6 [LibOS] Add error handling to helper threads 2020-01-20 18:32:02 -08:00
Michał Kowalczyk 716029400b [LibOS] test/apps: Remove workarounds for allowed_files bug 2020-01-20 19:21:24 +01:00
borysp 12efb484f3 [LibOS] Add VMA_TAINTED in mprotect 2020-01-18 18:33:42 +01:00
Dmitrii Kuvaiskii 57f1bdd47f [LibOS] Fix type of checkpoint's total memory size variable
Checkpoint's total memory size is stored in shim_cp_store::mem_size
field. Previously, this field was of type `int`. When a process
allocates more than 2GB of memory and then tries to spawn a child,
the checkpoint send/receive fails due to int overflow of mem_size.
This commit simply changes mem_size type to `size_t`. This is enough
to make the bug go away on e.g. a huge Python app with TensorFlow.
2020-01-17 17:36:07 -08:00
Dmitrii Kuvaiskii 40c08ff75a [LibOS, Pal/{Linux,Linux-SGX}] Remove DkObjectsWaitAny()
Now Graphene supports an improved version of DkObjectsWaitAny() with
correct polling semantics -- DkObjectsWaitEvents(). This makes
DkObjectsWaitAny() obsolete. This commit removes DkObjectsWaitAny()
and replaces it with:
- DkSynchronizationObjectWait() to wait on a single synchronization
  object like mutex or event.
- DkStreamsWaitEvents() to wait on stream-like objects (this is the
  renamed DkObjectsWaitEvents()).

The corresponding tests are fixed to use the new PAL interfaces.
Also, IPC helper and Async helper threads are significantly refactored
to make better use of DkStreamsWaitEvents().
2020-01-14 20:31:40 -08:00
jack.wxz c6b9ea1baf [LibOS] Add more cases to update inode number and file size
This commit adds more cases to the chroot FS to update file metadata:
- update inode number immediately after creating a new file;
- update file size after writing a non-mmapped file.

This commit also adds corresponding LibOS tests.
2020-01-13 20:26:18 -08:00
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