Commit Graph
59 Commits
Author SHA1 Message Date
Stefan Berger f781cc9192 [Pal] Move Linux elf-x86_64.h to include/arch/x86_64/Linux/elf-arch.h
Also, adapt #includes where needed. Avoid the name elf.h to avoid
clashes. We do not touch the Linux-SGX/elf-x86_64.h file since it is
slightly different.
2020-05-13 14:53:09 +02:00
Stefan Berger a179c79e3c [Pal] Factor out arch-specific TCB part to pal-arch.h 2020-05-12 21:22:04 +02:00
Stefan Berger 14db27c34a [Pal] Define PAGE_SIZE in pal-arch.h and use in regression test
Define the typically used PAGE_SIZE in pal-arch.h and use it in the
File.c regression test that maps memory of one page.
2020-05-12 18:31:35 +02:00
Stefan Berger 2e3e7c526c [Pal] Move PRESET_PAGESIZE into arch/x86_64/pal-arch.h 2020-05-12 18:31:35 +02:00
Stefan Berger ffbc41ba55 [Pal] Fix wrong error code from Pal when pipe is broken
Introduce PAL_ERROR_CONNFAILED_PIPE and treat EPIPE separately
from ECONNRESET.

The effects of this patch on LTP are:

from:
	writev01.c:139: FAIL: write to closed pipe, expected: -1 (EPIPE), got: -1 (ECONNRESET)
to:
	writev01.c:139: PASS: write to closed pipe, expected: -1 (EPIPE), got: -1 (EPIPE)

AND:

from:
	write05.c:82: FAIL: write() failed unexpectedly, expected EPIPE: ECONNRESET
to:
	write05.c:87: FAIL: sigpipe_cnt = 0

writev01 now works correctly, so this commit enables it.
2020-05-12 13:18:07 +02:00
Stefan Berger 98187f6b93 [Pal] Move Linux x86_64 specific ucontext.h to arch/x86_64/Linux
Move the Linux x86_64 specific ucontext.h to arch/x86_64/Linux.
The SGX and non-SGX files are identical.
2020-05-12 06:17:41 +00:00
Stefan Berger ea2c54d39c [Pal] Move x86-64 sigcontext.h and sigset.h to arch/x86_64/Linux
Move the x86-64-specific sigcontext header files to arch/x86_64/Linux.
The SGX and non-SGX files are identical.

We are also moving sigset.h since on ppc64 the following defines are
different:

x86_64: #define _SIGSET_NWORDS (64 / (8 * sizeof(unsigned long int)))
ppc64:  #define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
2020-05-12 03:08:15 +02:00
Stefan Berger 31b752a335 [Pal] Separately declare struct PAL_CONTEXT_ for Doxygen
This is required to cleanly pass the Doxygen build on Ubuntu 18.04.
2020-05-09 14:43:17 +02:00
Stefan Berger 8bbe609bb9 [Pal] Move x86_64/Linux sysdep-x86_64.h to arch/x86_64/Linux/
Also, adapt the Makefiles to add the arch specific directory to the CFLAGS.
The Linux-SGX sysdep-x86_64.h was identical and could therefore be removed.
2020-05-09 14:43:17 +02:00
Stefan Berger 74dc2ebfc3 [Pal] Move x86_64/Linux specifics from pal.h into arch/x86_64/pal-arch.h
Also, adapt the Makefiles to add the directory to the CFLAGS.
2020-05-09 14:43:17 +02:00
Stefan Berger c0163a6036 [Pal] Move x86_64-specific atomic.h to Pal/include/lib/x86_64
Also, adapt the Makefiles to include the new directory in CFLAGS.
2020-05-09 14:43:17 +02:00
Stefan Berger 5354f12a17 [Pal] Move host-generic dl-machine-x86_64.h to Pal/include/arch/x86_64
Also, adapt the Makefiles and INPUT paths in Doxyfile-pal to include the
new directory.
2020-05-09 14:43:17 +02:00
borysp c9742cb9cd Add READ_ONCE and WRITE_ONCE macros
Sometimes we need to prevent the compiler from reading or writing to
a memory location twice to prevent certain TOCTOU bugs. This can now
be achieved by using the introduced macros and this commit does so in
enclave_ocalls.c for Linux-SGX.
2020-05-08 01:43:12 +02:00
borysp 6cb111b6d1 [LibOS] Completely rework LibOS VMA bookkeeping
This commit completely reworks VMA subsystem along with its usages.
New version should be: cleaner (easier to maintain), faster and allow
for bookkeeping requests from Pal.
It also fixes some bugs and inconsistencies found in the process and
changes brk and mmap/munmap implementations (at least partially).
2020-05-02 16:22:00 +02:00
Michał Kowalczyk e39ee4767f Convert flags between PAL API and host syscalls
Currently various flags in file and memory syscalls work mostly by an
accident, because values of some of them align with corresponding Linux
syscall flags. Some APIs weren't that lucky though - e.g.
DkStreamOpen(..., /*options=*/PAL_OPTION_CLOEXEC) deletes file contents
(sic!) intead of opening it with O_CLOEXEC. This is because
PAL_OPTION_CLOEXEC == O_TRUNC.

This commit fixes all this mess and also adds asserts to check validity
of flags passed to Dk* handlers.
2020-04-27 19:54:55 +02:00
Michał Kowalczyk 5e2eee0086 [Pal] Remove likely/unlikely macros 2020-04-20 22:00:58 +02:00
Dmitrii Kuvaiskii 8d9f9f567f [Pal/Linux-SGX] Put TLS-context init logic in critical section
mbedTLS configuration used in Graphene is not thread-safe (because
this would require the use of a threading library like pthread which
is not possible in the LibOS/Pal layers). However, some mbedTLS
functions use shared state, in particular TLS context initialization
functions. This led to data races during encrypted-pipe creation,
since it requires two threads performing a TLS handshake. This commit
refactors TLS init into SSLInit (not thread-safe) and SSLHandshake
(thread-safe) and adds spinlocks around SSLInit to protect the racy
mbedTLS logic.
2020-04-17 01:30:00 -07:00
Michał Kowalczyk 964fd17910 [Docs] Misc rewordings 2020-04-15 23:35:12 +02:00
borysp bbc2387d76 [Pal/lib] Add missing root node update to avl_tree_swap_node 2020-04-15 12:20:29 +02:00
Dmitrii Kuvaiskii 77c86fbae3 [Pal] Introduce DkAttestationReport() API for local report retrieval
New DkAttestationReport() API retrieves the attestation report (local)
from the local attestation mechanism. Currently, it is implemented
only for Linux-SGX PAL and stubbed for all other PALs. The Linux-SGX
implementation retrieves the SGX report via EREPORT instruction.
The caller of this new API may learn sizes of report_data, target_info,
and report structs. The caller may also obtain current target info.
Finally, the caller may obtain the report for use in local attestation.
A simple test case is added to PAL tests.
2020-04-13 20:09:50 -07:00
Dmitrii Kuvaiskii caf1263070 [Pal/Linux-SGX] Encrypt all pipes/socketpairs with TLS-PSK
Previously, Linux-SGX PAL did not encrypt pipe/socketpair
communication (only process checkpoint send/receive was encrypted).
This commit encrypts all pipe/socketpair IPC between threads of
the same enclave and between enclave processes. In particular, all
offsprings of the "first" enclave inherit the same master key and
derive IPC session keys from this master key based on pipe name.
When two pipe/socketpair endpoints are first created, they establish
a TLS-PSK session via intra-enclave handshake (requires a spawn of
an intermediate enclave thread). During clone/fork/exec, endpoints'
TLS contexts are serialized and sent to the child that deserializes
them (using mbedtls_ssl_context_{save,load} functions).

Note that multicast pipes (with more than two communicating entities)
are not supported since TLS protocol doesn't support it.

This commit modifies the PAL `SendHandle` test to correctly test
pipe communication, as well as adds the LibOS `pipe` test.
2020-04-13 16:18:58 -07:00
Michał Kowalczyk a783fa2f4b Remove unused profiling system 2020-04-13 18:59:03 +02:00
Michał Kowalczyk 2b4e50c9bb [LibOS] Clean up PAUSE macros 2020-04-10 19:23:42 -07:00
Dmitrii Kuvaiskii 7e20a8044c [LibOS,Pal] Replace 32-bit pipeid with 256-bit pipe name
Previously, Graphene used the notation "pipe:<uint32_t>" to emulate
pipes, socketpairs, and UNIX domain sockets. In particular, pipes
and socketpairs received random integer IDs, and sockets received
deterministic integer IDs. However, 32-bit randomly generated IDs
may collide quite often. Since pipe IDs/names should *not* repeat
(otherwise e.g. derived crypto keys will be reused), this commit
changes pipe IDs (pipeid) from uint32_t to char[96], and pipe IDs
(names) become 256-bit random sequences.
2020-04-10 17:39:11 -07:00
borysp bf6be81310 [Pal/lib] Add avl_tree_first and avl_tree_last 2020-04-10 23:11:01 +02:00
Michał Kowalczyk e58933a971 [Pal/lib] Simplify static_str* macros 2020-04-02 01:46:48 +02:00
Michał Kowalczyk ff10af30ce Remove redundant parentheses 2020-04-02 01:46:48 +02:00
Michał Kowalczyk 727c2ab049 Fix typos 2020-04-02 01:46:48 +02:00
borysp 5f1e6ca317 [Pal/lib] Add generic trees (AVL) 2020-04-01 02:46:33 +02:00
borysp 6fd54058d5 [LibOS] Disable signals in critical section in shim_futex.c 2020-04-01 01:01:54 +02:00
Dmitrii Kuvaiskii 80030b1157 [Pal] Introduce DkAttestationQuote() API for quote retrieval
New DkAttestationQuote() API retrieves the attestation quote from the
underlying host-OS attestation mechanism. Currently, it is implemented
only for Linux-SGX PAL and stubbed for all other PALs. The Linux-SGX
implementation retrieves the SGX quote via sgx_get_quote() which
communicates with the Quoting Enclave via AESM service. The caller of
this new API may forward the obtained quote to the remote user for
remote attestation.
2020-03-24 22:03:35 -07:00
Dmitrii Kuvaiskii c43214523c [Pal/lib] spinlock.h: Add features for our own mutex implementation
Our implementation of mutexes for Exitless Syscalls requires three-state
spinlocks and spinlocks with timeouts (see Futexes are Tricky).
2020-03-24 00:34:45 -07:00
Wojtek Porczyk 7404d657a1 [Docs, Pal] Add missing references
Those features are yet to be documented, for now only create references
to silence Sphinx warnings.
2020-03-22 00:20:21 +01:00
Wojtek Porczyk 3fc67d6de2 [Docs] reSTify oldwiki/PAL-Host-ABI.md
Most of this document was moved to pal.h as Doxygen comments.
2020-03-22 00:20:21 +01:00
Dmitrii Kuvaiskii 8d76f9d3fb [Pal/Linux-SGX] Remove remote attestation functionality
Previously, Graphene with SGX performed self-remote attestation
by retrieving the SGX quote from the Quoting Enclave, sending it
to the Intel Attestation Service via Curl (in an HTTPS request),
and parsing the received from IAS remote-attestation certificate.

This self-attestation functionality is meaningless and is removed.
Moreover, since EPID-based remote attestation requires client key
(Ocp-Apim-Subscription-Key), and this key must be kept secret,
specifying it in the Graphene manifest (as was done previously) is
insecure. Therefore, the whole remote attestation functionality is
moved out of Graphene and to another trusted party (or to the app
on top of Graphene). Only the SGX quote retrieval from the Quoting
Enclave is kept in Graphene.
2020-03-19 18:08:37 +00:00
Dmitrii Kuvaiskii 9f59f62917 [LibOS,Pal] Force intermediate process to wait for child after execve()
Previously, Graphene in execve() emulation silently terminated the
intermediate process after sending all necessary metadata. For example,
`bash -c ls` would spawn (host clone+execve) a new Graphene process with
`ls` and exit the "intermediate" process (`bash`) immediately, without
waiting for `ls` to finish. This deviation from standard execve()
behavior resulted in the host shell becoming detached from the Graphene
process.

This commit simply forces this intermediate process to wait() until
the child terminates. This way the host shell stays attached, and
all timings and pipes behave correctly.
2020-03-18 17:57:11 +01:00
Dmitrii Kuvaiskii 95bfd8aeb5 [Pal/Linux-SGX] Refactor memory management of enclave pages
Previously, Linux-SGX logic of allocating/freeing enclave pages was
complicated and hard to read. This commit refactors this code for
readability, without changes in functionality.
2020-03-04 08:41:28 -08:00
Isaku Yamahata 551b32a036 [Pal/Linux-SGX] Fix ocall_{read,write,recv,send} to return ssize_t
Also, all users of these OCALLs are modified to operate on ssize_t
return values, including LIB_SSL_CONTEXT/mbedTLS callbacks.
2020-03-02 17:36:07 -08:00
borysp b40862a59c [LibOS,Pal/{Linux, Linux-SGX}] Add bogomips to /proc/cpuinfo 2020-03-02 21:48:55 +01:00
Isaku Yamahata 1738f698e7 [Pal/lib] Fix slabmgr initialization
STARTUP_SIZE constant was used (incorrectly) instead of alignment-aware
`size`.
2020-02-16 17:58:26 +01:00
Isaku Yamahata 0a7e3dd127 [LibOS,Pal] Move header files from Pal/lib/ under Pal/include/ 2020-02-05 23:21:06 -08:00
Isaku Yamahata 05e42acbc6 [Pal] Move header files under include/ and adjust the include directive 2020-02-05 23:21:06 -08:00
Michał Kowalczyk de42ebabe1 Reformat repository to our clang-format rules 2019-09-09 22:11:23 +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
Michał Kowalczyk 16d90cfe12 Fix parenthesizing and formatting of C macros 2019-05-23 19:14:23 +02:00
Michał Kowalczyk d773479b8c [PAL] Remove unused stdarg.h 2019-05-23 19:14:23 +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
Isaku Yamahata 745ab4a478 [Pal/Linux-SGX] Generate asm offsets and use them
This patch auto-generates asm offsets for Pal/Linux-SGX and uses them.
Also to share the generation logic among Pal and LibOS, header file for
it is created under Pal.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2019-04-13 00:54:12 +02:00
Chia-Che Tsai 48f330c88b [Linux/SGX PAL] Use the C11 standard instead of GNU99
Signed-off-by: Chia-Che Tsai <chiache@tamu.edu>
2019-02-10 13:52:18 -06:00
Isaku Yamahata bfbed330a6 remove unnecessary file Pal/include/pal/.gdb_history.
The file, Pal/include/pal/.gdb_history, seems committed accidentally.
So remove it.
2018-11-10 14:53:42 -08:00