Commit Graph
780 Commits
Author SHA1 Message Date
Isaku Yamahata efb19cfa24 [LibOS] support stack protector with compile time option
Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2019-07-24 17:46:59 -07:00
Isaku Yamahata e747b80b30 [Pal/Linux-SGX] enable stack protector
Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2019-07-24 17:46:30 -07:00
Isaku Yamahata cdff566051 [Pal/Linux] enable stack protector
enable stack protector for Pal/Linux.
for other Pal, enabling stack protector results in error.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2019-07-24 17:46:28 -07:00
Isaku Yamahata a45f3b8196 [LibOS] Implement newfstatat() system call 2019-07-24 14:58:13 -07:00
borysp 48156fc17f [LibOS] Add regression test for reading large directory 2019-07-24 12:36:14 -07:00
borysp 92f135ab86 [Pal/{Linux,Linux-SGX}] Fix Pal/host dir_read bugs
dir_read() never updated handle->dir.ptr and handle->dir.end which
effectively disallowed multipart responses. This commit rewrites
this function to handle multiple reads from one handle and also
use less memory.
2019-07-24 12:36:14 -07:00
borysp 7bfb250878 [LibOS] Enable readdir to list directories with many entries
chroot_readdir() tried to allocate a buffer big enough to hold all
entries, by calling DkStreamRead until it succeeded (increasing buffer
size otherwise). However, DkStreamRead could return partial results,
which was never handled (partial result means here it could return
just some objects, not a part of individual object). This commit fixes
this issue and refactors this function.
2019-07-24 12:27:54 -07:00
Chia-Che Tsai aa9743dbce [Regression] Update LTP tests to the upstream version 2019-07-23 18:31:37 -07:00
Michał Kowalczyk 52786e5f4d Fix a bunch of typos 2019-07-23 15:03:52 -07:00
Isaku Yamahata f0753437f5 [LibOS/Pal] Convert remaining python2 scripts to python3 2019-07-23 12:13:21 -07:00
Alex Merritt 95fce86545 [Pal/Linux-SGX] Fix typo DEAFULT* to DEFAULT* 2019-07-23 02:09:43 -07:00
Isaku Yamahata 12e9eb0c63 [LibOS] Omit field thread.dummy if ALIAS_VFORK_AS_FORK is defined 2019-07-23 01:03:51 -07:00
Kush Garg 536f6a1e90 [Docs] Update GSC readme 2019-07-21 03:59:06 +02:00
Isaku Yamahata ca64cb4b29 [.dir-locals.el] Add shell script mode 2019-07-20 17:18:27 -07:00
Isaku Yamahata 9a37c5cc36 [Pal/Linux-SGX] Force ocall_gettime() to loop on EINTR
SGX PAL-level functions like _DkSystemTimeQuery() assume that
ocall_gettime() does not return EINTR. Thus, this commit forces
this ocall to loop on EINTR.
2019-07-20 16:27:55 -07:00
Isaku Yamahata 22bc3c2f49 [LibOS] Remove abused goto in shim_init() 2019-07-20 14:35:24 -07:00
Isaku Yamahata 799dfe36db [LibOS] Remove abused goto in shim_ioctl.c 2019-07-20 14:35:24 -07:00
Isaku Yamahata 4bd9afd9e2 [LibOS] Remove abused goto in sys/shim_fs.c 2019-07-20 14:35:24 -07:00
Isaku Yamahata a26fa5e958 [Pal/Linux-SGX] Refactor get_reserved_pages() 2019-07-20 14:35:24 -07:00
Isaku Yamahata 96eeefbeda [LibOS] Disallow mapping outside user address range
Disallow user program to mmap outside the allowed user address range.
This is especially important for Linux-SGX PAL, since all user-program
memory must be allocated inside of the enclave range (ELRANGE). For
other PALs like Linux and FreeBSD, we probably should enhance PAL
interface (pal_control.user_address) to specify a more meaningful range
(currently the range is from minimal allowed address to address of the
code segment of the PAL library).
2019-07-19 19:51:15 -07:00
Don Porter 27ca6f0700 [Jenkins] Set up 18.04 CI jobs, fix one unit PAL unit test 2019-07-19 13:39:12 -04:00
Isaku Yamahata 29fdd5fe1e [Pal/{Linux,Linux-SGX}] Block async signals during vfork
To avoid vfork child from corrupting parent's memory, block async
signal before vfork(). Children unblock async signal after execve in
{sgx_}signal_setup().
2019-07-19 16:56:47 +02:00
Dmitrii Kuvaiskii 89a25d1377 [LibOS] Misc tiny bug fixes in IPC subsystem 2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii 479d833e72 [LibOS] Check for pending signals before sigsuspend/pause/nanosleep
Previously, sigsuspend(), pause(), and nanosleep() syscalls did not
check for pending signals before waiting on signals. This commit adds
this logic, similar to how this is implemented in Linux. This fixes data
races in regression tests relying on these syscalls (killXX in ltp).
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii ea234412c9 [LibOS] Emulate vfork() via fork()
Previous implementation of vfork() was both buggy (worked only in simple
cases) and not compatible with the new IPC implementation. We take a
shortcut for now and emulate vfork() via fork(); this is allowed by
POSIX. This commit also adds LibOS regression test for vfork().
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii f556a0676d [LibOS] Allow dyn loading of ELF binaries with OS ABI == ELFOSABI_LINUX
Sometimes apps are built with the ELF header containing OS ABI ==
ELFOSABI_LINUX (GCC is one example). Previously, LibOS dynamic loader
only allowed OS ABI == ELFOSABI_SYSV (most apps are built with it) and
failed on ELFOSABI_LINUX. This commit teaches LibOS loader to accept
ELFOSABI_LINUX binaries and removes some redundant checks on ELF header.
New implementation is now in line with dynamic loader of PAL.
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii b0619cb7a6 [LibOS] Rework of IPC subsystem's creation of processes
Previously, Graphene incorrectly treated execve() under SGX PAL:
Graphene would emulate execve() as fork + execve, and the new forked
process didn't try to "assume" the identity of its parent (which
violated execve specification "all process attributes are preserved").

This commit reworks the implementations of clone/fork and execve. In
particular, the IPC subsystem clearly distinguishes between the two
cases: clone/fork works as before whereas execve forks new "real"
process (which starts executing the requested program) and silently
exits the now-useless "temporary" process. New "real" process assumes
the identity of "temporary" process by inheriting its VMID (ID of
process for IPC purposes) and IPC-info objects with their PAL handles.

This commit also cleans up initialization of four IPC-info objects: self
(creates process-unique server pipe for IPC), parent (holds pipe for IPC
with parent process), and two namespace leaders (hold pipes for IPC with
leader processes). To correctly identify new-process server pipe, the
implementation of create_pipe() now allows to create VMID-based pipe URI.
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii b5465d7b57 [Pal/Linux-SGX] Distinguish between DkProcessExit() and DkThreadExit()
Previously, both DkProcessExit() and DkThreadExit() used SGX OCALL
ocall_exit(exitcode), which finally issued exit() syscall. This is
incorrect because DkProcessExit() must exit the whole process and not
just a single thread. This led to abandoned IPC/Async helper threads
in some Graphene-SGX corner cases. This commit forces DkProcessExit()
to result in exit_group() syscall, achieved by adding a new argument
to ocall_exit(exitcode, is_exitgroup).
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii 0b244f67df [LibOS] Add core-dump info on default signal dispositions
This commit adds default signal dispositions (as per Linux) to all 32
standard signals. It also adds WCOREDUMP bit to correctly inform wait4()
status word.

This commit updates graphene-tests submodules to enable new killXX LTP
regression tests, as well as fix the waitpid05 LTP test. It is important
to update this submodule reference in this commit because otherwise
waitpid05 tests will fail Graphene's CI.
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii 9dea9384ee [LibOS] Handle corner-cases during {send,receive}_ipc_message
This commit adds additional logic around DkStreamWrite() and
DkStreamRead() in send_ipc_message() and receive_ipc_message()
respectively: interrupts and partial reads/writes are handled correctly.
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii 61be1b2e40 [LibOS] Instruct thread_exit() to send IPC_CLD_EXIT only once
Previously, when a thread exited via thread_exit(), it could send two
identical IPC_CLD_EXIT messages under certain conditions. This commit
fixes this bug and forces thread_exit() to send IPC_CLD_EXIT at most once.
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii e7147f7ad2 [LibOS] Change IPC subsystem to send IPC_PID_KILL without ack
Previously, the IPC subsystem incorrectly sent IPC_PID_KILL message
(generated as part of kill() syscall) as a duplex message, i.e., the
sender thread (the one issuing kill()) was paused until the receiving
child process handled IPC_PID_KILL callback and sent the acknowledgement
reply message back to sender.

This incorrect logic created a data race between the IPC_PID_KILL ack
message and the exiting child process. In particular, the child could
exit and all its resources (including IPC port to communicate with
parent) could be reclaimed by host OS. This could lead to IPC_PID_KILL
ack message being lost (because of the closed IPC port), and the paused
parent thread would wake up with -ECONNRESET instead of the ack message.
This would lead the kill() implementation to believe that child process
never existed in the first place and to return -ESRCH.

The fix to this data race is to send IPC_PID_KILL without waiting for
acknowledgement. Specification of kill() syscall does not require it to
be synchronous (indeed it is not on Linux), so this fix is correct. This
fix also enabled to merge broadcast_signal() into ipc_pid_kill_send().
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii 5dd10ea66e [LibOS] Force current process to become leader if failed to send FINDNS
Previously, there was an incorrect corner case during discovering of the
current namespace leader. If the parent process would exit before the
child, the child process would fail on sending FINDNS message to the
parent (because of closed parent socket). The previous code logic would
assume that since NS_LEADER is set to some value, the leader process
exists. In reality, the child loses the only source of information about
the leader process (note that FINDNS is sent only to the parent), so the
only meaningful action is to set myself as the new leader.
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii 71fce53546 [LibOS] Comprehensive cleanup of parent-child IPC (shim_ipc_child.c)
- Removed unused IPC_CLD_JOIN and corresponding functions
  ipc_cld_join_send/ipc_cld_join_callback.
- Renamed poorly named ipc_child_exit to ipc_port_with_child_fini.
- Added thread locking during child_sthread_exit/child_thread_exit.
- Added extensive comments.
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii b84cea1b76 [LibOS] Comprehensive cleanup of basic IPC (shim_ipc.c)
- Changed type of shim_ipc_msg.size from int to size_t.
- Renamed shim_ipc_msg_obj to shim_ipc_msg_duplex for readability.
- Simplified function signatures and changed to better names.
- Removed unused IPC_FINDURI & IPC_TELLURI and corresponding functions.
- Replaced macros IPC_MSG_SIZE & IPC_MSGOBJ_SIZE with inline functions.
- Removed dangerous create_xxx_on_stack() functions and changed all
  invocations to have explicit __alloca's. Those functions relied on
  being inlined in the callers otherwise their created objects would
  become corrupted. Explicit __alloca's avoid this brittle
  implementation and make object ownership clear.
- Removed unnecessary wrapper function do_ipc_duplex(), replacing it
  with send_ipc_message_duplex().
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii 48a01df574 [LibOS] Comprehensive cleanup of IPC helper thread (shim_ipc_helper.c)
- Removed unnecessary macros (IPC_PORT_IFPOLL, DEBUG_REF, etc).
- Simplified function signatures and changed to better names.
- Removed unused functions (del_ipc_port, del_ipc_port_by_id).
- Malloc instead of huge stack allocations.
- Removed complex logic of exit_with_ipc_helper(), now IPC thread exits
  similarly to Async helper thread.
- Removed ipc_port_pool hash list (used as perf optimization but
  providing no tangible benefit at the cost of high complexity).
- Simplified IPC helper thread states to only ALIVE & NOTALIVE.
- Removed unused broadcast_port.
- Reworked IPC helper thread's while-loop similarly to Async helper
  thread; removed perf optimization of keeping the same list of ports to
  listen on DkObjectsWaitAny(), instead simply repopulate this list
  every time (may become too slow if lots of IPC on hundreds of ports).
2019-07-19 01:03:41 -07:00
Dmitrii Kuvaiskii 601f17724a [Jenkins-SGX] Increase timeout on LibOS tests to 15 minutes
Also increases timeout on LibOS's "udp" test to 50 seconds. It seems to
timeout frequently otherwise.
2019-07-19 01:03:41 -07:00
Isaku Yamahata 8afbe0f82f [LibOS] Remove nonsense check in shim_namei.c:eat_slashes() 2019-07-18 19:34:53 -07:00
Isaku Yamahata fde333e968 [LibOS] Remove redundant check in find_mount_from_uri() 2019-07-18 19:34:53 -07:00
Isaku Yamahata dee669b84f [LibOS] Allow __path_lookup(start != NULL, abspath)
__path_lookupat(start!=NULL, path=absolute) incorrectly handled
lookup at start dir. Resolution should start directly at the root
of the thread.
2019-07-18 19:34:53 -07:00
Isaku Yamahata a771c171a2 [LibOS] Remove #ifdef __i386__ in shim_checkpoint.h 2019-07-18 18:18:56 -07:00
Isaku Yamahata 1a6f863695 [LibOS] Remove warning cast-function-type with GCC8
Compilation of bookkeep/shim_signal.c:__handle_one_signal() under GCC8
failed with cast-function-type error on k_sa_handler assignment to
handler. This commit fixes this error via cast to void*.
2019-07-18 18:18:56 -07:00
Isaku Yamahata 0809e5a5e1 [LibOS] Add support for vDSO
This commit adds vDSO support: creates vDSO memory region which contains
necessary symbols __vdso_{gettimeofday, clock_getime, time, getcpu} with
wrappers to call function pointers with actual LibOS implementation.
On startup, function pointers are setup to point to actual functions.

With this commit, the Glibc modification to not use vDSO can be removed.
2019-07-18 17:19:21 -07:00
Isaku Yamahata 427051bc97 [Pal/Linux-SGX] Remove deadcode in sgx_graphene.c: _DkEventSet & _DkEventWait 2019-07-18 15:55:51 -07:00
Isaku Yamahata 8a45977484 [Pal/Linux-SGX] Return -ERRNO instead of -PAL_ERROR_XXX in OCALLs
OCALL functions should return -ERRNO on errors:
- on signals/interrupts, return -EINTR instead of -PAL_ERROR_INTERRUPTED;
- on host-OS syscalls, return -ERRNO(ret) instead of -PAL_ERROR_DENIED;
- on no-available-threads, return -EINVAL instead of -PAL_ERROR_INVAL.
2019-07-18 15:55:51 -07:00
Isaku Yamahata 2e4fb94a1e [LibOS] Drop exec bit from source files 2019-07-17 04:11:55 +02:00
Chia-Che Tsai a0803a22b4 [LibOS] Add a regression test for fstat() on a directory 2019-07-16 22:22:25 +02:00
Chia-Che Tsai f98966265d [LibOS] Fix an ambiguous intepretation of a shim handle
It's interpreted both as a chroot file handle and as a directory handle.
2019-07-16 22:22:25 +02:00
Isaku Yamahata c8d6f8cafd [LibOS] Make signal_alarm static 2019-07-16 21:02:58 +02:00
borysp d17c7f78af [LibOS] Fix memory leak in __map_elf_object 2019-07-16 14:32:55 +02:00