Commit Graph
786 Commits
Author SHA1 Message Date
Dmitrii Kuvaiskii 46d21eccaf [LibOS,Pal] Add MSG_DONTWAIT and SCM_RIGHTS for recvmsg/sendmsg
This commit improves the emulation of recvfrom/sendfrom,
recvmsg/sendmsg, and recvmmsg/sendmmsg system calls. In particular,
MSG_DONTWAIT flag is allowed though not really emulated (benign in
most cases). Also, it is possible now to send/receive FDs via
SCM_RIGHTS on a UNIX domain socket (only send/recv of pipes and UNIX
domain sockets is currently supported). Corresponding LibOS test
is added.
2020-05-15 23:36:11 +00:00
Michał Kowalczyk 297b959bcb Use proper integer types in socket-related syscalls and ocalls
This contains two socket-related changes, which would be hard to factor
out into two commits: (because of compilation warnings)

	- Making ocalls use size_t in their interface. It's not the same as
	  Linux syscall interface anyway, so why not make it sane?
	- Fixing sycalls arguments types to match the ones use by kernel.
	  Note: there's no such type as "socklen_t" in the kernel, so it got
	  removed.
2020-05-14 12:21:20 +02:00
borysp f78c67cc47 [LibOS] Remove simple threads
They are not really used anywhere and have broken refcounting.
2020-05-13 19:42:40 +02:00
borysp 71ac707487 [LibOS] Small cleanup of shim_thread.c 2020-05-13 19:42:40 +02:00
Stefan Berger 4a53659df1 [LibOS] Move dl-machine-x86_64.h to arch-specific dir
Move the shim's dl-machine-x86_64.h to include/arch/x86_64/shim_dl-machine.h.
Rename the file to avoid name clashes with Pal's dl-machine.h.
2020-05-13 14:53:09 +02:00
Stefan Berger da54b0d413 [LibOS] Move shim's ldsodefs.h to include/elf/ldsodefs.h
As a preparatory step for the next patch, move the shim's ldsodefs.h
to include/elf/ldsodefs.h.
2020-05-13 14:53:09 +02:00
Stefan Berger 9952790ce3 [LibOS] Remove special mapping of PAL_ERROR_CONNFAILED to EPIPE
Now we have a separate PAL error code for EPIPE failures
(PAL_ERROR_CONNFAILED_PIPE).
2020-05-12 13:18:07 +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
borysp 2bc5247394 [LibOS] Remove unused checkpointing function all_running_threads 2020-05-12 01:35:25 +02:00
borysp 743cc2dba1 [LibOS] Remove what's left of checkpointing to files
PR #1424 partially removed checkpointing to files, this commit removes
the rest.
2020-05-12 01:19:38 +02:00
Stefan Berger cceeed21cc [LibOS] Remove unnecessary include of asm/prctl.h where possible
The x86_64 specific include asm/prctl.h is not needed in any of the
files where it is removed.
2020-05-11 17:05:59 +00:00
Dmitrii Kuvaiskii d1fe5ec273 [LibOS] Remove DkSynchronizationObjectWait() from wait_event()
LibOS events create_event() / set_event() / wait_event() are emulated
as reads/writes on a private pipe. On the other hand, PAL API
DkSynchronizationObjectWait() works only on event/mutex objects, not
on pipes. So wait_event(), which previously used this API, failed
on assert because it provided a pipe object. This bug manifests
only in rare circumstances (I found it with Erlang workload) because
wait_event() is called very rarely, on data-race path of epoll wait.
This commit simply removes DkSynchronizationObjectWait() call, so
that the event is awaited via reading from the pipe.
2020-05-10 00:15:58 +02:00
Dmitrii Kuvaiskii d9f5418d10 [LibOS] Force select(0, NULL, NULL, NULL, NULL) to sleep indefinitely
Previously, Graphene returned -EINVAL for select() with all zeroes.
This behavior was chosen due to man page of select: "Some code calls
select() with all three sets empty, nfds zero, and a non-NULL
timeout" (notice "non-NULL timeout"). In reality, Linux allows to
specify timeout as NULL, which leads to indefinite sleep, same as
pause(). This commit forces select() with all zeroes to perform
shim_do_pause() to comply with Linux behavior.
2020-05-10 00:15:58 +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
Dmitrii Kuvaiskii 159270a584 [LibOS/test] LTP: enable mknod/mknodat tests 2020-05-08 16:09:51 -07:00
Dmitrii Kuvaiskii 32695531dc [LibOS] Add support for FIFOs (named pipes)
This commit adds support for FIFOs and the corresponding syscalls
mknod() and mknodat(). Internally, FIFOs are emulated as pseudo-
files in chroot mount points (not visible in host FS). FIFOs'
read/write operations are emulated via pipes at PAL level (this
means that they are transparently encrypted under SGX PAL).
Generally, emulation of FIFOs is similar to emulation of named
UNIX domain sockets, i.e., they are "ephemeral" and only allow
communication between two related processes.

New LibOS test is added: multi-process `mkfifo`.
2020-05-08 16:09:51 -07:00
borysp 7101095e7c [LibOS] Add checks of user address in mmap with MAP_FIXED 2020-05-08 16:21:53 +02:00
borysp 4acf9caac2 [LibOS] Disable reinitialization of brk after fork 2020-05-08 02:56:17 +02:00
Michał Kowalczyk 0848aadc0d [LibOS] Fix a bunch of crashes found by socket-related LTP tests 2020-05-07 18:35:25 +02:00
Michał Kowalczyk 7bcd7fd0d1 [LibOS] Describe bug in shim_do_msgsnd found by LTP's msgsnd05 2020-05-07 18:35:25 +02:00
borysp d9ed743a6d [LibOS] Add flags checking in wait4 syscall 2020-05-05 19:34:19 +00:00
borysp a9bc8c75ff [LibOS] Remove special handling of stack VMAs 2020-05-02 16:22:47 +02:00
borysp 04ec16c30a [LibOS] Add removing of unmapped VMAs when reexecuting the same binary 2020-05-02 16:22:47 +02:00
borysp a6b50967a6 [LibOS] Add a missing check for stack guard page when removing VMAs 2020-05-02 16:22:47 +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
Dmitrii Kuvaiskii b79940aada [Makefiles] Make Graphene build on Clear Linux
Clear Linux ships with Glibc built with `-Wp,-DFORTIFY_SOURCE=2`.
This overwrites Graphene's `-UFORTIFY_SOURCE` because of the quirk
in how GCC applies arguments (first without Wp, then with Wp).
This commit updates Makefiles to use `-Wp,-UFORTIFY_SOURCE`.
2020-05-01 23:35:49 +00:00
Dmitrii Kuvaiskii 301587065a [LibOS,Pal] Make Graphene build with GCC 9.3
GCC 9.3 adds more static checks on C headers and sources. This
commit fixes all detected issues (mainly possible NULL pointer
dereferences and VLAs on stack).
2020-05-01 23:15:30 +00:00
Stefan Berger 206eb81eec [Makefiles] Get arch and distro specific vars from Makefile.configs
Extend Makefile.configs and define several variables for make to use
derived from 'gcc -dumpmachine'. In particular:
- ARCH as the architecture, e.g., x86_64
- ARCH_LONG as the long version of the architecture, e.g., x86_64-linux-gnu
- ARCH_LIBDIR as the directory where libraries are located,
  e.g., /lib/x86_64-linux-gnu

In Makefiles and manifest templates, replace the hard-coded
x86_64-linux_gnu and /lib/x86_64-linux-gnu through these variables.
Extend the already existing sed scripts to replace the necessary
variables.
2020-05-01 20:54:04 +00:00
Michał Kowalczyk 12bedb08a7 [LibOS] Rename SHIM_SYSCALL_PASSTHROUGH to SHIM_SYSCALL_RETURN_ENOSYS 2020-05-01 13:31:09 +02:00
Michał Kowalczyk 1cb090d6dd [LibOS] ltp: Revise open() tests 2020-04-27 19:54:55 +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 9aa4370084 [LibOS] test/regression: Make test names consistent 2020-04-25 03:00:53 +02:00
Dmitrii Kuvaiskii f1c65d92df [LibOS] Add attestation pseudo-filesystem under /dev/attestation
This commit adds a new subdirectory in the /dev pseudo-FS and
new pseudo-files to allow applications and helper libraries on
top of Graphene to perform attestation. The currently exposed
primitives are tailored to the Intel SGX local and remote EPID
attestation. App developer writes attestation logic against
this pseudo-FS interface by opening and reading/writing the
following files:
- /dev/attestation/user_report_data: write user-provided report
  data used in `report` and `quote` pseudo-files
- /dev/attestation/target_info: write target info used in
  `report` and `quote` pseudo-files
- /dev/attestation/my_target_info: read this enclave's target info
- /dev/attestation/report: read report (for local attestation)
- /dev/attestation/quote: read quote (for remote attestation)

This commit also adds a corresponding LibOS test `attestation`.
2020-04-21 19:30:58 -07:00
borysp 63cdcd33e4 [LibOS/test/fs] Remove invalid mmap on file opened write-only 2020-04-20 11:18:24 -07:00
Dmitrii Kuvaiskii 90585e0d07 [LibOS/test] Fix incorrect options arg for waitpid() in udp.c and tcp.c 2020-04-17 15:39:29 -07:00
Michał Kowalczyk 5a0fa0ed72 [LibOS] Remove half-implemented checkpointing to files
Current implementation isn't finished, doesn't have a single test and
has quite bad code quality. If we decide we want to implement this
feature, it will be easier to just implement it from scratch.
2020-04-14 21:03:49 +02:00
Rafał Wojdyła 4658dfc2bf [LibOS] Fix read/write return check in FS tests 2020-04-14 01:36:32 +02:00
Rafał Wojdyła 9542cc8e90 [LibOS] Make open_close FS test more modular 2020-04-14 01:36:32 +02:00
Rafał Wojdyła 3fca261d76 [LibOS] Add size checks to seek_tell FS test 2020-04-14 01:36:32 +02:00
Rafał Wojdyła c6afb19ea6 [LibOS] Add open_flags FS test 2020-04-14 01:36:32 +02: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 5a05e53730 Remove unused hash functions 2020-04-13 18:59:03 +02:00
Stefan Berger c51f7b1bb8 [LibOS] Account for cleanup events when walking list of events
This patch fixes occasional hangs at termination of programs with threads.
These hangs occurred since the async helper thread did not properly account
for installed cleanup events but exited instead due to its idle counter
reaching the limit. This happened occasionally.

When the cleanup function wasn't called, a thread's clear_tid pointer
wasn't reset and the futex wasn't WAKE'ed and then the main thread would
end up WAITing on the futex (which still had the original thread id as its
value) and then never received the WAKE.

This patch addresses github issue 1416:

    https://github.com/oscarlab/graphene/issues/1416
2020-04-11 03:26:07 +02:00
Michał Kowalczyk 8f2958a3b7 [LibOS] Kill Graphene after internal fault 2020-04-10 19:23:42 -07: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
Michał Kowalczyk ee594256cd [LibOS] Fix handling of O_CLOEXEC in dup* syscalls 2020-04-09 20:45:26 +02:00