Commit Graph
604 Commits
Author SHA1 Message Date
Dmitrii Kuvaiskii 17b3997226 [Pal] Fix htonl/htons() byte-order macro to __BYTE_ORDER 2019-05-13 14:37:27 -07:00
Gary e0506e43aa [LibOS] Prevent memory leak during read_environs()
During initialization, LibOS parses the LD_PRELOAD environment variable
and allocates memory to store its entries. On error, this allocated
memory must be freed. This commit correctly frees memory on error.
2019-05-08 17:02:14 -07:00
Gary 07a021dbea [PAL] Fix an out of bounds read on generic.fds[]
MAX_FDS is defined as 3, fds[MAX_FDS] is a 3-element array.
While i in for loop looping from 0 to MAX_FDS, will cause out-of-boundry read for generaic.fds which is a 2-element array.
The generic.fds defiend in pal_host.h should be correctly sized to match with both fds[MAX_FDS] and accommodate for the for loop.
Also fixed another out-of-boundary access for pipeprv
2019-05-08 14:35:19 +02:00
Isaku Yamahata 6d31302e35 [LibOS] Fix sched_getaffinity to return byte size, not bit size
Fixes the following bugs:
* sched_getaffinity(2) should return # of bytes, not bits.
* It should honor `len` argument.
* Linux sched_getaffinity() aligns the result to sizeof(long).
2019-05-08 13:37:20 +02:00
Biao Lu 2c87e294fc [LibOS] Make /proc/cpuinfo output exactly like in Linux kernel
Some Linux applications get the number of CPU cores by querying
/proc/cpuinfo.  Before, such apps would be confused by a wrong
format of /proc/cpuinfo in Graphene. This commit updates format
to exactly the same as in Linux kernel.

This commit also adds a LibOS regression test for /proc/cpuinfo.
2019-05-07 18:59:37 -07:00
Isaku Yamahata b7907fa83d [LibOS] Make clone ABI match kernel and update glibc patch
glibc: remove unnecessary pushq/popq so that shim_clone can run without segv.
This is a preparation for later patch to clean up shim_clone() to
remove glibc modification.
libos: Currently child thread ret ip is taken from new child stack.
But it can be retrieved from parent's thread context, so such a hack
isn't needed.
Now the modification to clone.S is not needed anymore. So remove it.
2019-05-08 02:04:33 +02:00
Gary 4ae620f87b [PAL] Correct memory allocation in file_rename() and dir_rename()
Use strdup() to correctly copy a string with NULL termination.
Prevent memory leak by freeing {file,dir}.realpath when needed.
2019-05-07 16:41:53 -07:00
Isaku Yamahata 5992881c46 [Pal/Linux-SGX] Clear RFLAGS before calling _DkExceptionHandler
This is follow up of https://github.com/oscarlab/graphene/pull/643
RFLAGS.DF must be cleared when calling a C function.
2019-05-07 22:39:50 +02:00
Michał Kowalczyk 2bc2c04194 Remove trailing blanks 2019-05-07 16:32:16 +02:00
Isaku Yamahata 783304de6a [LibOS] Preserve rflags register on syscalldb()
Linux system calls preserve rflags; LibOS must do the same.
This commit adds rflags to shim_regs and saves/restores it
on syscalldb() entry/exit.
2019-05-07 00:31:31 -07:00
Michał Kowalczyk 640b7cc80f [Pal/Linux-SGX] Remove unused user_types.h 2019-05-06 21:42:48 -07:00
Michał Kowalczyk 281a05ce48 Fix camel case in DkStreamAttributes{Query,Set}ByHandle 2019-05-06 18:11:15 -07:00
Simon Gaiser 3f72eb69de [Pal/Linux-SGX] Rename .Lhandle_resume to .Lprepare_resume
This code path is called when the urts EENTERs to allow us to prepare
the SSA for the following ERESUME (i.e. inject the exception handler).
It is not for the ERESUME itself. So rename it to avoid confusion.
2019-05-07 01:24:32 +02:00
Simon Gaiser fcc1c3ee58 [Pal/Linux-SGX] Improve comments below enclave_entry
The comment about the register content is only true for EENTER. Also
usually* this code is reached only by EENTER. ERESUME restores the saved
state from the SSA.

*: It is reached if an async exit happens just after EENTER.

Also remove redundant comments directly below.
2019-05-07 01:23:52 +02:00
Dmitrii Kuvaiskii f420037285 [LibOS] Remove unused errval from __map_elf_object() 2019-05-06 16:01:35 -07:00
Gary d19b266ed4 [LibOS] Fix memory leak in __map_elf_object()
Pointer l can point to a newly allocated object (via new_elf_object()).
Ensure l is freed on error (on call_lose code path).
2019-05-06 16:01:35 -07:00
Dmitrii Kuvaiskii 402020f8da [LibOS/regression] Add futex-timeout test
Before PR #554, futex() syscall incorrectly failed
if user-supplied timeout expired (also see PR #438).
This patch adds test on futex() with timeout.
2019-05-06 13:46:26 -07:00
Isaku Yamahata d4d7546de0 [Pal] Fix sign of a few PAL return values
Some PAL functions return positive error code accidentally.
2019-05-06 19:49:18 +02:00
Michał Kowalczyk d7b3d6074a Align stack to 16 when calling C from asm 2019-05-04 14:16:21 +02:00
Isaku Yamahata 5b3b69332a [Pal/Linux-SGX] Disallow nested signals at host-OS level
This commit ensures that TCS.CSSA == 1 while entering enclave
execution to handle a signal from host OS (recall that CSSA == 0 is for
normal enclave execution and CSSA == 1 is for signal-handling
enclave preparation). This effectively disallows nested signal handling
from a malicious OS. Disallowing nested signals simplifies our code.
Benign OS is prevented from nesting by blocking async signals during
signal handling.

Note that currently enclaves are always run with TCS.NSSA == 2, and SGX
hardware will disallow entering the enclave if TCS.CSSA > 1. Thus, this
commit serves as an assertion in case NSSA limit is changed in future.
2019-05-03 15:45:00 -07:00
Dmitrii Kuvaiskii 76fa183257 [Pal/Linux-SGX] Fix UDP bug with connect() in sgx_ocall_sock_connect()
Before, connect() host-OS syscall was issued unconditionally in
sgx_ocall_sock_connect(). However, UDP clients do not strictly need to
issue connect() before sending packets to UDP server. In this case, addr
is NULL, and sgx_ocall_sock_connect() must not issue connect().
2019-05-03 12:50:03 -07:00
Dmitrii Kuvaiskii 121fc9bf1d [Pal/{Linux, Linux-SGX}] Initialize addrlen's to zeros in socket_parse_uri() 2019-05-03 12:50:03 -07:00
Isaku Yamahata 0a8f97af5a [Pal/{Linux, Linux-SGX}] Add NULL check in udp_connect/sgx_ocall_sock_connect
This patch also adds a UDP LibOS regression test.
2019-05-03 12:50:03 -07:00
smherwig 5c42c026c6 [LibOS] Ignore POLLERR and POLLHUP in events in poll()
See #389.

Per the manpage, POLLERR and POLLUP are returned in `revents` and
ignored in `events`.  Indeed, programs should not be setting, and
typically don't set -- `events` with these values.

The effect of this bug is, among others, that a process will never get a
disconnect event from a peer socket.
2019-05-03 03:36:14 +02:00
Dmitrii Kuvaiskii 40fc490fcd [Pal/Linux-SGX] OCALL security hardening
- Time-Of-Check-To-Time-Of-Use (TOCTOU) vulnerability is closed
    by first copying untrusted values inside enclave and then
    operating on these copied values; see sgx_copy_to_enclave().
  - Pointer/integer overflow is closed by comparing against a
    trusted maximum value in sgx_copy_to_enclave().
  - Untrusted stack overflows in sgx_alloc_on_ustack()/sgx_copy_to_ustack()
    are closed by checking for NULL return values.

These vulnerabilities were independently discovered and disclosed
by David Oswald, Jo van Bulck, and others.
2019-05-02 14:12:34 -07:00
Isaku Yamahata 47acfc32bc [Pal] Use := to get correct dir in Makefile.Test 2019-05-02 00:10:30 -07:00
Chia-Che Tsai 09ad502c3a [LibOS] Use the C11 standard instead of GNU99 2019-05-01 20:43:04 -05:00
Isaku Yamahata 2167a349c9 [Pal/Linux-SGX] Remove unnecessary __alloca()
Replace abuses of __alloca() with normal stack variables.
2019-05-02 02:05:13 +02:00
Isaku Yamahata 8dd311a353 [Pal/Linux-SGX] Add format check to pal_printf
Add __attribute__((format(printf))) check to pal_printf and
fix corresponding format errors.
2019-05-01 15:50:12 -07:00
Don Porter e62a021fd8 Add an open method to /proc and some subdirectories
This addresses issue #461.
2019-05-01 09:04:51 -04:00
Isaku Yamahata c29bcc8c5b [Pal, LibOS] Add missing clobbered "cc" to inline asm 2019-05-01 13:21:30 +02:00
Isaku Yamahata 8890b325b4 [Pal, LibOS] Clear RFLAGS on program entry
SYSV x86-64 ABI requires RFLAGS to be cleared in initial register state.
2019-05-01 13:21:30 +02:00
Isaku Yamahata 2de42097fe [Pal/Linux-SGX] Clear RFLAGS.DF on enclave entry
SYSV x86-64 ABI requires RFLAGS.DF to be cleared when entering a function (other flags are
undefined) and we can't trust non-SGX side to do this.
2019-05-01 13:19:31 +02:00
Simon Gaiser 917356119c [Pal/Linux-SGX] Don't get heap min/max from urts
Instead pass them through the measured TLS.

Part of issue #509.
2019-04-30 21:55:19 -07:00
Simon Gaiser 63d4f01194 [Pal/Linux-SGX] Don't get exec addr/size from urts
Instead pass them through the measured TLS.

Part of issue #509.
2019-05-01 03:44:23 +02:00
Simon Gaiser 33433459c7 [Pal/Linux-SGX] Document usage of TLS 2019-05-01 02:49:47 +02:00
Simon Gaiser 7ffc287314 [Pal/Linux-SGX] Don't get manifest addr/size from urts
Instead we use the fact that the manifest is always placed at the top of
the enclave address range. The manifest size is stored inside the TLS
like we have already done for the enclave size.

Part of issue #509.
2019-05-01 02:49:47 +02:00
Isaku Yamahata f72cd48ee5 [LibOS] Emulate pause() by sleeping for a very long time
Before, pause() was emulated by sleeping for 1s in a loop until
signal interrupted it. If signal arrived in-between these invocations
then pause() could never return. Also, pause() incorrectly returned 0
instead of -1 and errno=EINTR.

This patch emulates pause() by sleeping for a very long time (years).
Also, it correctly returns EINTR.
2019-04-30 17:07:51 -07:00
Michał Kowalczyk 382a1ec394 Cleanup .gitignore files 2019-04-30 23:16:38 +02:00
Michał Kowalczyk 29f44c836b [PAL] Document [_]DkRandomBitsRead 2019-04-30 22:26:08 +02:00
Michał Kowalczyk 17102eab9d Change DkRandomBitsRead interface and fix error checking
Now it returns 0 on success and -PAL_* on error.
2019-04-30 22:26:08 +02:00
Michał Kowalczyk 57749eb973 [LibOS] Don't use insecure random 2019-04-30 22:23:04 +02:00
Isaku Yamahata ec4a3f7bb5 [LibOS] Emulate clone(CLONE_VFORK | CLONE_VM | SIGCHLD) as vfork()
Some runtimes use clone(CLONE_VFORK | CLONE_VM | SIGCHLD) for vfork().
2019-04-30 15:45:37 +02:00
Dmitrii Kuvaiskii bd72b968ee [*/regression] Increase timeout of regression tests
On weaker machines (Intel NUCs and SGX-enabled laptops),
SGX regression tests take longer than 5 seconds because
Graphene measures/zeroes all enclave memory at startup.
Increase the timeout for SGX regression tests to 20 sec.
2019-04-29 18:10:32 -07:00
Simon Gaiser 63b8ef41cf [Pal/regression] Test timeout handling when waiting for events 2019-04-30 01:11:31 +02:00
Isaku Yamahata 86897c7049 [LibOS] Align stack on 16B during user executable start
x86-64 ABI requires 16B alignment of stack on function calls.
To conform to ABI, align stack when jumping to the entry point
of the user executable.
2019-04-29 15:28:22 -07:00
Simon Gaiser ab29483bbe [Pal/regression] Increase 'Process' test timeout a bit
On SGX spawning processes got slower since we measure/zero all memory.
So the timeout is slightly missed.
2019-04-29 21:31:59 +02:00
Simon Gaiser 014a938767 [Pal/Linux-SGX] Measure all memory except the heap
Before this change some important memory areas, for example TCS and TLS
were not measured. With this change all mapped enclave memory is
measured with one exception. Since the EEXTEND hashing is rather slow
the heap is not measured. Instead it gets zeroed on enclave startup.

Closes #505.
2019-04-29 21:31:15 +02:00
Simon Gaiser 838c14022b [Pal/Linux-SGX] Use autogenerated constants in pal-sgx-sign 2019-04-29 21:30:59 +02:00
Simon Gaiser 402fce72ba Autogenerate offsets for Python
This makes the offset generator more generic to generate a python module
in addition to a header for assembly.
2019-04-29 21:30:09 +02:00