Commit Graph
1499 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
Stefan Berger 14353a628f [Pal] Fix IPv6-related failures by using sockaddr_storage
Fix IPv6 failures by increasing the sockaddr size by using
sockaddr_storage for all addresses that can be IPv6.

This now allows us to run this test here:

    ./pal_loader busybox telnet ::1 22

    SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3

    Protocol mismatch.

    Connection closed by foreign host
    Connected to ::1
2020-05-13 21:55:31 +02:00
Stefan Berger 020e81a6bb [Pal] Check size of sockaddr pointed by addr before using it
Extend inet_parse_uri to check the size of the sockaddr before using it,
thus requiring callers to pass in the size of the structure. Adapt all
direct and indirect callers.

This now fails a TCP/IPv6 test since it would cause stack buffer
overwrites otherwise:

    ./pal_loader busybox telnet ::1 22
2020-05-13 21:55:31 +02:00
Stefan Berger e7b88274b5 [Pal-SGX] Import some more Linux types related to sockets 2020-05-13 21:55:31 +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 f6f4e327f5 [Pal] Rename pal.lds to pal-x86_64.lds
Only in Linux and Skeleton, because Linux-SGX uses a different loader
script.
2020-05-13 14:53:09 +02:00
Stefan Berger e9af21f0ac [Pal] Rename user_start.S to user_start-x86_64.S 2020-05-13 14:53:09 +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 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 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
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
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 fe73ea1811 [Pal] Properly calculate address of futex variable
Rather than passing the mutex_handle's address, which happens to have the
futex variable as its first member, properly calculate the address of the
futex.
2020-05-11 18:21:15 +00: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 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 76a6a2e706 [Pal] Modify Makefile to build clone-x86_64.o using clone-$(ARCH).o 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
Dmitrii Kuvaiskii 159270a584 [LibOS/test] LTP: enable mknod/mknodat tests 2020-05-08 16:09:51 -07:00
Dmitrii Kuvaiskii 4087cdbe2a [Pal/lib] Return PAL_ERROR_TRYAGAIN on try-again read/write errors in mbedTLS
Previously, lib_SSLRead() and lib_SSLWrite() returned PAL_ERROR_DENIED
on any error, even on benign try-again errors from mbedTLS. This led
to LibOS returning EACCES to the application which doesn't expect such
error code. This commit converts benign try-again errors into
corresponding PAL_ERROR_TRYAGAIN errors.
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
Dmitrii Kuvaiskii 165e932144 [Pal/Linux-SGX] Add support for DCAP SGX driver versions 1.6+
The DCAP SGX driver v1.6+ closely follows the in-kernel SGX driver
v28+. This version changes the driver path to /dev/sgx/enclave and
changes argument struct of the SGX_IOC_ENCLAVE_ADD_PAGE ioctl.
2020-05-08 12:49:26 -07:00
borysp 7101095e7c [LibOS] Add checks of user address in mmap with MAP_FIXED 2020-05-08 16:21:53 +02:00
Stefan Berger 9a9add06a2 [Examples] python-simple: Remove apt_pkg.cpython... library from PY_LIBS if SGX=0
It isn't needed and this allows it to run the test on Fedora as well.
2020-05-08 04:02:43 +02:00
borysp 4acf9caac2 [LibOS] Disable reinitialization of brk after fork 2020-05-08 02:56:17 +02:00
borysp fa29ca1e9a [Pal/Linux-SGX] Sanitize return values of ocalls
When doing an ocall, untrusted part could return an invalid value for
example `write` could return size bigger than passed to it. This commit
adds checks for such invalid values.
2020-05-08 01:43:12 +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 b8dc3c5a13 [Examples/lmbench] Add more lmbench download urls
The one lmbench download source we have is very unstable and downloading
often fails. This commit adds more urls that will be iteratively
fetched.
2020-05-07 21:24:55 +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
Emil Hemdal f25510a259 [Examples] Support SGX_SIGNER_KEY in all Makefiles
The documentation currently specifies SGX_SIGNER_KEY as the parameter to
enable Graphene to find your keys.

Some examples don't use an environment parameter at all for the key to
sign the enclave, this commit fixes that.
2020-05-07 12:33:10 +02:00
Emil Hemdal 22b35e0cb2 [Examples] Use SGX_SIGNER_KEY in Makefiles
The documentation currently specifies SGX_SIGNER_KEY as the parameter to
enable Graphene to find your keys.

Some examples don't use this environment parameter, this commit fixes
that.
2020-05-07 00:21:18 +02:00
Stefan Berger 244a559c48 [Examples] pytorch: Only fail the build if Ubuntu is not used for SGX
The pytorch example can also run on Fedora, so only fail the build
if Ubuntu is not used but the build is for SGX.
2020-05-06 01:19:35 +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