Commit Graph
440 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 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 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
Isaku Yamahata 12e9eb0c63 [LibOS] Omit field thread.dummy if ALIAS_VFORK_AS_FORK is defined 2019-07-23 01:03:51 -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 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
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 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 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
Isaku Yamahata 246b9a6fad [LibOS] Fix data race between creation/deletion of async helper thread
Data race between creating and exiting the async helper thread: during
async helper thread breaking its while-loop and exiting, another thread
may call install_async_event() and read that the helper is alive, thus
skipping create_async_helper(). Therefore, the other thread installs the
event but there is no async helper thread to trigger it. This commit
fixes this data race by moving check-if-alive under the lock.
2019-07-15 13:43:53 -07:00
Dmitrii Kuvaiskii 0dc1ecf511 [LibOS] Remove unnecessary SIGNAL_DELAYED flag
This flag was used in tcb.context.preempt.
2019-07-14 18:52:11 +02:00
borysp 39a58957e2 [LibOS] Fix O_CREAT|O_EXCL flags checks in open() 2019-07-12 17:55:31 +02:00
Isaku Yamahata 204938ee35 [Makefiles] Drop %.e target
Commonly %.i or %.s is used for preprocessed files, not %.e. Drop it in
preference to %.i and %.s.
2019-07-11 07:04:33 +02:00
Isaku Yamahata 0e2384c747 [Makefiles] Drop %.asm rule
%.asm is not widely used in unix world and the rule seems hacky.
So drop %.asm rule.
2019-07-11 07:04:33 +02:00
Isaku Yamahata 4789a3a188 [{shim,Pal}] Refactor Makefiles to utilize Makefile.rules 2019-07-11 07:04:33 +02:00
Isaku Yamahata 7eade65b91 [Pal, LibOS] Fix vprintf signature to take va_list instead of its pointer 2019-07-09 12:34:50 -07:00
Dmitrii Kuvaiskii dab4c96853 [LibOS] Add special handling in open() syscall (EISDIR, O_TRUNC)
- Add error case: fail with EISDIR if directory is open()'ed with
  writable access.
- Add additional checks: O_TRUNC must work only on regular writable
  files (otherwise do not truncate).

The commit also improves LibOS regression test on FS corner cases and
fixes a tiny bug in DkStreamSetLength() with assert hanging Graphene.
2019-07-03 16:08:25 -07:00
Dmitrii Kuvaiskii 7327aa62ab [LibOS] Fix bug of long relative paths (more than 256B)
Previously, Graphene had a bug when dentry's rel_path was not initialized
to actual relative path if parent + filename length was longer than
256B. The problem was that rel_path was a shim_qstr which could contain
maximum 256 chars. This commit increases the limit to 4096B and adds
checks to fail explicitly if rel_path is still too large. Also, it adds
LibOS regression test.

Note that relative paths greater than 256 chars in length are not
uncommon. Most OSes impose the limit of 4096 chars or no limit at all.
2019-07-03 16:08:25 -07:00
Chia-Che Tsai 728d16aca6 [LibOS] Fix C++ tests support
This commit:
* Fixes compilation and execution errors for C++ programs in LibOS/shim/test/native.
* Adds a C++ regression test.
2019-07-01 14:42:32 +02:00
Dmitrii Kuvaiskii 84ec50a2aa [LibOS/regression] Add OpenMP simple for-loop test
Previously, OpenMP apps failed to run under Graphene-SGX because it did
not support raw system calls (used inside of OpenMP lib, in particular
the futex() syscall). Since recently, Graphene-SGX has support for raw
syscall execution. This commit adds a test showing that OpenMP works.
2019-06-30 23:37:21 +02:00
Chia-Che Tsai 013c25cdb2 Fix compilation errors on Ubuntu 18.04 2019-06-30 18:51:06 +02:00
Dmitrii Kuvaiskii cfb29f0db0 [LibOS] Fix memory leak of qstr->oflow string during checkpointing
During checkpointing, qstr->oflow was redirected to point to the memory
region in the checkpoint and the old memory region was not freed. We
cannot keep qstr->oflow pointing to the checkpoint memory area
because it will be freed after migration, leaving the parent with a
dangling pointer. Instead, keep parent's qstr->oflow intact but copy its
content inside the checkpoint and rebase accordingly in the child as
part of checkpoint restore.
2019-06-28 13:19:12 -07:00