Commit Graph
138 Commits
Author SHA1 Message Date
Michał Kowalczyk 44e186c503 Clean up asserts
- Make assert() a no-op in non-debug builds.
- Use static_assert for compile-time asserts.
- Fix assert() implementation (previous version didn't work for
  expressions with types larger than long, it also always printed
  `(value:0)`).
- Clean up calls to asserts.
2019-10-02 03:22:52 +02:00
Thomas Knauth c6a0151baf [LibOS] Fix and add a test case for resource leak on file close 2019-10-01 16:18:38 +02:00
Isaku Yamahata 55e0bb1c6a [LibOS] Force variable update on tcb.test_range.has_fault in test_user_memory()
In test_user_memory(), a memory range is tested via probing of each page
in the range. If the memory page was not allocated, it leads to a
segfault which is captured by the LibOS memfault_upcall() and reported
in the variable tcb.test_range.has_fault. However, the compiler may
optimize away accesses to this variable in test_user_memory(), believing
it is never updated anywhere else. This commit introduces a memory
barrier to prevent this compiler optimization (same for test_user_string()).
2019-09-30 20:56:18 -07:00
Michał Kowalczyk 6ba48bdf59 [LibOS] shim_profile: Simplify no-op macros 2019-10-01 00:48:00 +02:00
borysp 323be6717d [LibOS] Change minimal file descriptor number to be 0
Previously, set_new_fd_handle() started searching for the first free fd
from 1 not 0. This commit fixes this, plus refactors this function.
2019-09-30 15:49:32 -07:00
Michał Kowalczyk de42ebabe1 Reformat repository to our clang-format rules 2019-09-09 22:11:23 +02:00
Michał Kowalczyk 6356559e39 Fix header dependencies 2019-09-09 22:11:23 +02:00
borysp 289ac3af4d [LibOS] Fix get_new_dentry reference count semantics
If `get_new_dentry` returns successfully, it increases returned dentry's
reference counter by one, which matches other similar functions' behavior.
2019-09-03 21:52:55 +02:00
borysp e23684bc3d [LibOS] Rewrite rename* syscalls
Present implementation is utterly broken, does not work even
in simplest cases.
2019-09-03 21:52:55 +02:00
Chia-Che Tsai d875e2eba7 [LibOS] Disable the warning when GIPC is not supported 2019-08-26 23:10:09 +02:00
Isaku Yamahata 5f5bc5af56 [Pal, LibOS] Consolidate elf.h
There is no point in keeping the same elf.h in both Pal and LibOS.
2019-08-14 01:47:57 +02:00
borysp 004c2fe9a4 [LibOS] Remove opened reference counter from struct shim_handle
Inside `struct shim_handle` `opened` reference counter is used incorrectly.
Additionally at this moment it guards the same resource (handle) as `ref_counter`,
making it obsolete. This patch removes `opened` counter and moves `close_handle`
logic into `put_handle`.
2019-08-13 16:20:44 -07:00
Isaku Yamahata bc715c2081 [LibOS] Fix memory leak in shim_do_execve_rtld()
__libcc_tcb_t is leaked. It should be allocated from stack.
2019-08-13 20:47:34 +02:00
Chia-Che Tsai f2591790d7 [LibOS] Fix timeout resolution for epoll_wait()/epoll_pwait()
Internal LibOS and PAL interfaces use microseconds (us) for timeout
values. However, Linux epoll_wait/epoll_pwait syscalls use milliseconds
(ms) for timeout. Previously, there was a bug in timeout resolution
because epoll_wait() emulation did not convert from ms to us. This
commit fixes this bug and also adds suffixes "_ms" and "_us" to make the
time units used explicit.
2019-08-08 17:37:39 -07:00
Michał Kowalczyk 5ec5e2f24c Delete all reference monitor residues 2019-07-31 02:30:47 +02:00
Isaku Yamahata c7571408d6 [LibOS] Cleanup of shim_tls.h 2019-07-30 16:50:34 -07:00
Isaku Yamahata 5fe52e4a0d [LibOS] Use atomic operations for shim_context.preempt
enable_preempt(), disable_preempt(), and other functions operated on
shim_context.preempt using non-atomic operations. This commit replaces
the old broken implementation with atomic operations.
2019-07-30 16:50:34 -07:00
Chia-Che Tsai 0d89dda052 [LibOS] Fix the implementation of getrlimit/setrlimit syscalls
- Deprecate sys_stack_size and max_brk_size. Get the values directly from __rlim.cur.
- Add internal routines for setting and getting __rlim.cur.
- Implement prlimit64() and simplify getrlimit() and setrlimit().
2019-07-30 15:14:11 +02:00
Dmitrii Kuvaiskii 4b734addcd [LibOS] Turn on CPSTORE_DERANDOMIZATION to fix intermittent bugs on fork
Previously, a checkpoint on child's do_migration() was allocated at a
random address and could overlap with parent's VMAs, leading to
intermittent bugs on some apps (including Apache under SGX PAL). This
commit turns on CPSTORE_DERANDOMIZATION so that the child always maps
the checkpoint at the same address as the parent. Note that this is
a temporary solution because of memory fragmentation and security
issues. It also disallows the parent process to have less memory than
the child (relevant in SGX environment, e.g., to GCC regression test).
2019-07-29 16:56:17 -07:00
Chia-Che Tsai c295e5cd1d [LibOS] Do not wake up thread if arriving signal is ignored
When appending an arriving signal, LibOS must skip interrupting
the thread if the thread's signal handler is set to SIG_IGN.
2019-07-27 18:39:45 -07:00
Isaku Yamahata a45f3b8196 [LibOS] Implement newfstatat() system call 2019-07-24 14:58:13 -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
Michał Kowalczyk 52786e5f4d Fix a bunch of typos 2019-07-23 15:03:52 -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
Dmitrii Kuvaiskii 89a25d1377 [LibOS] Misc tiny bug fixes in IPC subsystem 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 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 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 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
Isaku Yamahata a771c171a2 [LibOS] Remove #ifdef __i386__ in shim_checkpoint.h 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
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
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
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 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 013c25cdb2 Fix compilation errors on Ubuntu 18.04 2019-06-30 18:51:06 +02:00
Don Porter 27213b18e0 [LibOS] Fix compilation errors with -Wunused-parameter flags 2019-06-26 18:47:13 -07:00
Isaku Yamahata bfa3efc4c5 [LibOS] Remove unused SHIM_TLS_CANARY for assembly 2019-06-26 16:22:12 -07:00
Isaku Yamahata 4b256bd1ca [LibOS] Correctly initialize TCB to shim_tcb in rs_running_thread() 2019-06-26 16:22:12 -07:00
Isaku Yamahata 326fc07933 [LibOS] Add noreturn function attribute where appropriate
Add noreturn function attribute to __shim_do_execve_rtld(),
execute_elf_object(), __shim_ipc_helper(), shim_ipc_helper_end()
2019-06-19 00:14:00 -07:00
Isaku Yamahata 573c865bc3 [LibOS] Introduce stack trampoline in shim_ipc_helper()
Previously, shim_ipc_helper() implementation was fragile because
it changed the stack in the middle of execution via switch_stack().
This commit introduces the stack trampoline to switch stack.
2019-06-19 00:14:00 -07:00
Isaku Yamahata 4dab5b94c7 [LibOS] Introduce stack trampoline in shim_do_execve_rtld()
Previously, shim_do_execve_rtld() implementation was fragile because
it changed the stack in the middle of execution via switch_stack().
It also used global vars (subject to race condition) to populate the
stack. This commit introduces the stack trampoline to switch stack and
eliminate global vars by passing a struct as function argument.
2019-06-19 00:14:00 -07:00
Isaku Yamahata 5564cb0a50 [LibOS] Reorganize fields in shim_context, shim_regs, and shim_tls
* move syscall_nr from shim_context to shim_regs::orig_rax

* move ret_ip from shim_tls to shim_context as clean up

* move sp from shim_context to shim_regs

* context->regs == NULL doesn't make sense for restore_context() because
  it doesn't work correctly. It tries to execute 0 address and probably
  results in SEGV or something bad.
  plus some code clean up and simplification.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2019-06-18 15:26:18 -04:00
Isaku Yamahata 87a4d4768b [LibOS] Cleanup of shim_async.c
A comprehensive rewrite of the Async helper thread functionality. This
thread is responsible for installment and delivery of two kinds of async
events: async IO (SIGIO) and alarms/timers (alarm/setitimer).
2019-06-18 13:59:07 -04:00
Zhang Chen 18eb57832e [LibOS] Add supplementary groups support: set{get}groups()
This commit adds emulation of setgroups() and getgroups() syscalls.
These syscalls are dummies, they do not consult host OS. Instead, they
initialize a per-process array of suppl group IDs to a single entry of
getgid() and allow to set any group IDs.
2019-06-14 15:51:28 -07:00
Isaku Yamahata ba3da57092 [LibOS,Pal/lib] Add atomic_inc_return, atomic_add_return
Some parts of LibOS used the combination of atomic_inc/add() + atomic_read()
which is not atomic. This commit introduces atomic_inc/add_return() to
make those parts atomic.
2019-06-13 16:20:43 -07:00
Dmitrii Kuvaiskii b871a962dd [LibOS] Take into account adjacent VMAs on correct-memory check
Previously the check on correct memory region under Linux-SGX
(called is_in_one_vma()) only checked that the whole memory region fits
into one VMA. In some cases (e.g. DATA and BSS sections), memory regions
can span several adjacent VMAs. This commit refines the check and
renames it to is_in_adjacent_vmas(). It also adds a LibOS test.
2019-06-13 12:06:25 -07:00
Chia-Che Tsai d314707d4c [LibOS] Fix all warnings with -Wsign-compare
Signed-off-by: Chia-Che Tsai <chiache@tamu.edu>
2019-06-12 20:08:38 -05:00