2126 Commits

Author SHA1 Message Date
Stefan Berger fb42d39c94 [LibOS] Replace EM_X86_64 with SHIM_ELF_HOST_MACHINE
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
2021-02-19 22:40:54 +01:00
Paweł Marczewski 347cdab962 [Pal/Linux-SGX] Fix stack unwinding on enclave exit
A previous change in LibOS started storing fake syscall return
address in R14. This broke stack unwinding when the stack
contained both LibOS syscall and SGX OCALL, because we had no CFI
directives for recovering register values except for RBP, RSP and
RIP, and the value of R14 was lost.

This change adds proper CFI to enclave exit code, by making sure
callee-saved registers can be recovered.

Signed-off-by: Paweł Marczewski <pawel@invisiblethingslab.com>
2021-02-19 20:40:50 +01:00
Borys Popławski 5492d808a7 [PAL] Remove unused and empty DkInstructionCacheFlush
Signed-off-by: Borys Popławski <borysp@invisiblethingslab.com>
2021-02-18 23:36:58 +01:00
Paweł Marczewski 2cfdd510dc [LibOS] Remove dynamic linking
After this change, LibOS will no longer perform dynamic linking.
The ELF loading code executes load commands and passes control to
interpreter (ld.so), which handles necessary relocations and
loading additional libraries. In this way, the code resembles what
Linux kernel does when executing a new program.

Before, dynamic linking was necessary for making LibOS entry point
(syscalldb function) available for applications. However, that meant
duplicating the work already done by ld.so, and introduced a lot of
unnecessary complexity. After changing LibOS entry API to use the
GS register, it's possible to omit dynamic linking entirely.

The main function (__load_elf_object()) still needs cleanup and
possibly rewriting from scratch. However, this change prepares
ground for that rewrite.

Summary of changes:

- Remove dynamic relocation step (DO_DYNAMIC_RELOCATE()).
- Don't call __load_elf_object() again for ELFs reported
  via register_library(). We only need to notify GDB about these.
- Remove fields related to dynamic linking from link_map (dynamic
  section address, hashes, etc.), and setup for these fields.
- need_interp(): To check if we need an interpreter, check only if
  the binary requests one (PT_INTERP), instead of traversing the
  dynamic section (before, we ignored dynamic dependencies on LibOS
  itself, but now there shouldn't be any).
- RELOCATE(): always adjust addresses, instead of checking if
  they're already inside the mapped range. I think the previous
  behaviour was a workaround to make repeated relocations work.
- Get rid of load modes that are no longer used (OBJECT_REMAP,
  OBJECT_USER).
- Remove the workaround for repeated relocation in glibc patches
  (R_X86_64_NONE).

Signed-off-by: Paweł Marczewski <pawel@invisiblethingslab.com>
2021-02-18 02:48:02 +01:00
Borys Popławski abfa778a6f [Pal/Linux] Change ADDR_IN_PAL to ADDR_IN_PAL_OR_VDSO
When an async exception triggers, LibOS needs to know whether it
happened while inside PAL code. Since Linux-PAL sometimes call VDSO
functions, they need to be accounted for as well.

Signed-off-by: Borys Popławski <borysp@invisiblethingslab.com>
2021-02-17 20:17:56 +01:00
Stefan Berger 36ccd3ea4c [LibOS] Rename vdso.c to vdso-x86_64.c
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
2021-02-16 23:20:28 +01:00
Michał Kowalczyk 94caf7987e [Examples] Don't use unsupported "Rules with Grouped Targets" in Make
This commit is a result of debugging a rare race condition during build
of some of our examples, which resulted in "enclave EINIT failed -
Invalid measurement" error.

It turns out that Make in versions that doesn't support the `&:`
operator ("Rules with Grouped Targets") silently ignores it and calls
the recipe for each target separately, without even a warning.

Signed-off-by: Michał Kowalczyk <mkow@invisiblethingslab.com>
2021-02-16 17:28:44 +01:00
Michał Kowalczyk 81b96f4178 [Examples] Make Redis work on Ubuntu 20.04
Signed-off-by: Michał Kowalczyk <mkow@invisiblethingslab.com>
2021-02-16 17:28:44 +01:00
Dmitrii Kuvaiskii 31f08ab11c [GSC] Always use absolute paths inside the Docker container
Previously, some GSC templates and scripts that execute inside Docker
containers contained relative file paths. This led to failures if
a base Docker image contained WORKDIR different from root (`/`),
since all GSC scripts put Graphene-related files under root dir.

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
2021-02-15 22:44:36 -08:00
Vijay Dhanraj aa9ded3c42 [LibOS] regression: Fix sysfs regression test
Current implementation incorrectly uses `_SC_ULONG_MAX` to check the max
ulong (instead of ULONG_MAX). This patch addresses the issue.

Note: `_SC_ULONG_MAX` is intended to be used with sysconf() to inquire
about the maximum value which can be stored in a variable of type
`unsigned long` and is defined to 117.

Signed-off-by: Vijay Dhanraj <vijay.dhanraj@intel.com>
2021-02-16 00:25:40 +01:00
Vijay Dhanraj a57dcf6f38 [LibOS] Fix /sys/devices/system/{cpu,node}/ path resolution
Current implementation of sysfs will fail for paths such as
/sys/devices/system/{cpu,node}/online which doesn't have a numeric
value. This patch fixes this issue. This patch also adds 2 test cases as
part of the sysfs regression test.

Signed-off-by: Vijay Dhanraj <vijay.dhanraj@intel.com>
2021-02-16 00:25:40 +01:00
Paweł Marczewski 6ea8e951f0 [LibOS] Use GS register for syscalls
Instead of depending on dynamic linking for LibOS entry point
(syscalldb), we pass a pointer in the shim_tcb structure, so that
the patched code can enter syscall using 'jmp *%gs:<offset>'.

The same applies to the vDSO syscall code that previously needed
an up-to-date pointer to syscalldb function. Now, there is no
need to adjust the values inside the vDSO page.

In addition, this change removes the other two instances where we
import a symbol directly from LibOS: register_library (can be also
done through GS register) and glibc_version (not important because
we build Graphene and glibc together).

This simplifies things because the dynamic linking necessary to
make the syscalldb function available had to be performed by LibOS
itself (in many cases, effectively doing a second pass of dynamic
linking after ld.so). After this change, there will be no need for
LibOS to perform dynamic linking, and the ELF loading code can be
simplified.

Signed-off-by: Paweł Marczewski <pawel@invisiblethingslab.com>
2021-02-15 22:19:28 +01:00
Michał Kowalczyk a402a2a8d9 [Pal/Linux-SGX] Add sgx.preheat_enclave manifest option
Signed-off-by: Michał Kowalczyk <mkow@invisiblethingslab.com>
2021-02-10 12:22:47 +01:00
Paweł Marczewski a06b93d8dc [LibOS] Drop support for glibc 2.23
Signed-off-by: Paweł Marczewski <pawel@invisiblethingslab.com>
2021-02-09 16:34:22 +01:00
borysp 3e60a09454 [PAL] Remove empty ENTER_PAL_CALL/LEAVE_PAL_CALL macros
These macros were empty and not used anymore. Additionally there was
a bug: `LEAVE_PAL_CALL` actually did not perform `return` and the
execution continued after it.

Signed-off-by: borysp <borysp@invisiblethingslab.com>
2021-02-09 06:25:22 -08:00
Dmitrii Kuvaiskii f2f83aa2b5 [Pal/Linux-SGX] Use hard-coded SSA frame size equal to 4 pages
Previously, the SGX-signing Python script had a hard-coded value of
1 page. However, the Linux-SGX runtime calculated the SSA frame size
based on the information from CPUID and XFRM. The SSA frame size is
a total of XSAVE area size + GPRs + MISC region, and on feature-rich
CPUs may exceed 1 page. Thus, the SSA frame size in the SIGSTRUCT
(during SGX signing) and in the SECS (during runtime) may mismatch on
such CPUs, and EINIT fails with SGX_INVALID_MEASUREMENT. This commit
simply hard-codes SSA frame size to overapproximated value of 4 pages.

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
2021-02-09 02:56:52 -08:00
borysp bb6206822a [Makefile] Use MAKEFILE_LIST before any includes
`Scripts/Makefile.rules` used MAKEFILE_LIST to obtain the current
makefile path, but it did so after including some other file, so it got
the included file path instead.

Signed-off-by: borysp <borysp@invisiblethingslab.com>
2021-02-09 00:26:42 +01:00
Don Porter 79742f9029 [Docs] Add Developer Certificate of Origin (DCO)
Add a DCO and related text to CONTRIBUTING.rst.  Also add this documentation to rtdocs.

Signed-off-by: Don Porter <porter@cs.unc.edu>
2021-02-08 14:34:34 -05:00
borysp c24bddd5aa [LibOS] Rework signal handling and syscall emulation
Change log (most important only):
- unify CPU context structures - now we have only one version -
  `PAL_CONTEXT` - which is shared between LibOS and PALs and it should
  depend only on the host architecture (not OS),
- syscalls emulation changed:
  - dedicated LibOS stack is now used for syscalls emulation,
  - removed one indirection level in syscalls table - now it stores
    `shim_do_*` functions directly,
- signal handling - completely rewritten:
  - all signal queues use proper locking schemes now,
  - signals are handled *only* when returning to the user app from LibOS
    or PAL,
  - nested signals are now possible,
  - the app is allowed to jump out of signal handler with the same
    sematics as on normal Linux,
  - signal altstack is now fully supported,
  - syscall restarting is now supported,
  - doing a backtrace from the signal handler works properly,
- disallow injecting host-level signals, with one exception, see
  `sys.enable_sigterm_injection` manifest option for more details.
2021-02-05 14:11:21 +01:00
borysp bec1d9b4ec [LibOS] Fix LibOS code range checks in shim_signal.c
The old version did not consider e.g. PLT as code.
2021-02-05 14:00:05 +01:00
Dmitrii Kuvaiskii 439524b941 [Pal/Linux-SGX] Allow CPUID leaves 0x40000000 - 0x4FFFFFFF
These CPUID leaves are used by virtualization software (Hyper-V, KVM,
etc.) and are zeroed out on bare metal. Some runtimes (e.g. JVM) query
them to detect underlying virtualization software. This commit makes
these leaves return zeroes ("no virtualization").
2021-02-05 03:22:12 +01:00
Dmitrii Kuvaiskii 0a4d5ce0e5 [GSC] Refactor GSC and make it work again
Commit "Introduce one, central manifest, zero-config children and
constant MRENCLAVE" broke GSC. This commit fixes GSC (mainly adjusts
it the single-manifest change in that commit). Also, significant
internal refactoring is done (no user-visible changes). Also, scripts
now explicitly use UTF-8 when reading/writing the manifest files because
they are written in TOML which forces UTF-8.
2021-02-03 23:10:29 -08:00
borysp e0f6ac9116 [LibOS] Make poll and epoll_wait pass errors from DkStreamsWaitEvents 2021-02-03 16:39:48 +01:00
Vijay Dhanraj 91253d1778 [Pal/Linux-SGX] Increase number of cache sets sanity limit
On certain servers the number of cache sets can be greater than
`1 << 16`. This patch increases the sanity check limit to `1 << 30`
to validate against such large number of cache sets.
2021-02-03 13:36:13 +01:00
Li, Xun 1ddfd0e36f [LibOS] Allow but ignore MSG_WAITALL flag in recv 2021-02-03 01:16:43 +01:00
Michał Kowalczyk 2d27f1077e [Docs] Drop "Deprecated Code" sections
Seems that no one has used this feature since its deprecation 1.5 year
ago. Let's not clutter the main readme with it.
Also dropped a section from building instructions, as it was quite
useless.
2021-02-02 19:32:35 +01:00
Paweł Marczewski 09c6307631 [Pal] Clean up GDB configuration
- Extract parts that are common for all hosts
- Remove some outdated/unnecessary options, we should now be
  closer to default configuration
- Disable libthread_db loading (does not work and crashes GDB 9.2)
- Disable pagination when loading debug maps
2021-02-01 22:37:53 +01:00
Xiangping Ji c59a1438d5 [Pal/Linux-SGX] Recognize upstreamed Intel SGX driver
Intel SGX driver was upstreamed in Linux version 5.11. There, the SGX
device is exposed as `/dev/sgx_enclave` instead of `/dev/sgx/enclave`.
This commit updates link-intel-driver.py to recognize this new name.
2021-02-01 11:02:01 -08:00
Dmitrii Kuvaiskii bdc955e561 [Docs,Pal/Linux-SGX] Improve build and documentation on ISGX_DRIVER_PATH 2021-02-01 04:58:13 -08:00
Michał Kowalczyk c4ec05da98 [Pal] Fix comment formatting in pal_internal.h 2021-02-01 02:36:59 +01:00
Michał Kowalczyk d457420adf [Docs] Add missing build dependencies 2021-02-01 02:36:59 +01:00
Michał Kowalczyk 5521c70401 [LibOS] Fix 'wence' -> 'whence' typo 2021-02-01 02:36:59 +01:00
Michał Kowalczyk a931de1c79 [Pal/Linux-SGX] Stop recommending GSGX driver installation in warnings 2021-02-01 02:36:59 +01:00
Michał Kowalczyk 1750d3b723 [Docs] Drop "How to run" section from the README.rst
This section was quite useless, the manifest included there didn't
really allow to run any application. Better to just link to the complete
and up-to-date guide from our docs.
2021-02-01 02:36:59 +01:00
Michał Kowalczyk 2fc5b3f9b4 [Examples] Fix up PyTorch 2021-02-01 02:36:49 +01:00
Paweł Marczewski cf0bfdf67a [Make] Use proper dependencies for generated-offsets
The generated-offsets headers have to depend on the code that
defines the relevant data structures. Otherwise, when the data
structures change, the code will get compiled with wrong offsets
and will crash.
2021-01-29 13:10:45 -08:00
Stefan Berger 02e80ff1bf [LibOS] Disable UBSAN sanitizer in test_user_memory/test_user_string
This is to prevent UBSAN from tripping on legitimate NULL pointers.
2021-01-29 04:45:29 -08:00
Vijay Dhanraj 9aab974bca [Examples] Revert OpenVINO to use default TBB/hwloc
This commit also fixes small bugs in OpenVINO Makefile and manifest.
2021-01-29 01:34:52 -08:00
Vijay Dhanraj ec4422d415 [Pal,LibOS] Add support for /sys pseudo filesystem
This commit also fixes `pseudo_name_ops::list_name()` function pointer
type: `size_t len` argument instead of `int len`.  It also adds a
regression test to exercise the newly supported /sys pseudo filesystem.
2021-01-28 23:28:29 -08:00
Vijay Dhanraj d947474ff0 [LibOS] Add /proc/[pid]/task path to /proc fs 2021-01-28 23:19:30 -08:00
Vijay Dhanraj 227b0d2053 [Pal] Add str_to_ulong() common function 2021-01-28 23:18:45 -08:00
Paweł Marczewski ae8beba1a7 [Pal,Docs] Convert 'info' log level to 'warning'; add description
We seem to be using it for warnings, so it should be less confusing.
This change also adds a description of the levels to documentation.
2021-01-26 21:01:32 +01:00
Paweł Marczewski c55f515448 [Pal/Linux-SGX] Remove SGX_DBG
Replace the old SGX_DBG macro with new subsystem (log_* inside
enclave, urts_log_* outside enclave).

Adjust log levels of some messages, and remove some unnecessary
ones.
2021-01-26 21:01:32 +01:00
Dmitrii Kuvaiskii e4c661b164 [LibOS] Add manifest option libos.check_invalid_pointers
Previously, LibOS always checked whether user-supplied buffers for
syscalls are invalid and generated EFAULT error codes if so. Since the
invalid-buffer check needed to touch memory/traverse VMAs, it could
affect performance of certain workloads. This commit adds a manifest
option that controls this behavior: most real-world applications never
supply invalid buffers in syscalls, so such checks can be disabled.
2021-01-26 10:48:52 -08:00
Dmitrii Kuvaiskii e1e036461e [LibOS] Add dummy lseek emulation for /dev/{zero,random,null}
Some apps (e.g., Python Dill module) perform a dummy lseek() on
these /dev/ files.
2021-01-26 09:16:12 -08:00
Wojtek Porczyk 9c98438b7c [CI] Add download mirror
We've experienced intermittent github.com outage, so add our own mirror.
2021-01-26 08:39:24 -08:00
Stefan Berger 183ca70fd4 [Pal] Make File regression test work with PAGE_SIZE != 4096 2021-01-25 23:20:45 -08:00
Paweł Marczewski 3388b211ae [Docs] Mention that pyelftools is needed for GDB 2021-01-25 11:43:36 -08:00
borysp f1d7d29118 [LibOS] Add missing syscalls parsers 2021-01-25 19:22:38 +01:00
Paweł Marczewski 8ca27bd3c4 [Pal] Log to stderr, not stdout 2021-01-23 01:58:26 +01:00