From a12f96f49e8b0c30bf958fb4ac6be56c96099fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kowalczyk?= Date: Wed, 13 Jan 2021 17:00:29 +0100 Subject: [PATCH] [Pal/Linux-SGX] Remove loader.nonpie_binary manifest option Non-PIE binaries support requires ELRANGE to start at low addresses, which on older SGX drivers required root permissions or reconfiguring the host, so this mapping strategy was made optional by us. This issue was fixed long time ago, so we can drop this option and always start enclaves at 0. --- Documentation/manifest-syntax.rst | 11 ------ Documentation/quickstart.rst | 7 ---- Examples/apache/httpd.manifest.template | 2 -- Examples/bash/manifest.template | 2 -- Examples/blender/blender.manifest.template | 1 - Examples/gcc/gcc.manifest.template | 1 - Examples/lighttpd/lighttpd.manifest.template | 2 -- .../memcached/memcached.manifest.template | 2 -- Examples/nginx/nginx.manifest.template | 2 -- .../nodejs.manifest.template | 2 -- .../python.manifest.template | 2 -- .../python-simple/python.manifest.template | 2 -- Examples/pytorch/pytorch.manifest.template | 2 -- Examples/r/R.manifest.template | 2 -- Examples/redis/redis-server.manifest.template | 2 -- .../label_image.manifest.template | 2 -- LibOS/shim/src/elf/shim_rtld.c | 6 +--- LibOS/shim/test/fs/manifest.template | 2 -- LibOS/shim/test/ltp/manifest.template | 2 -- .../test/regression/argv_from_file.manifest | 2 -- .../regression/attestation.manifest.template | 2 -- .../test/regression/debug_log_file.manifest | 2 -- .../test/regression/debug_log_inline.manifest | 2 -- .../test/regression/env_from_file.manifest | 2 -- .../test/regression/env_from_host.manifest | 2 -- ...le_check_policy_allow_all_but_log.manifest | 2 -- .../file_check_policy_strict.manifest | 2 -- .../test/regression/host_root_fs.manifest | 2 -- LibOS/shim/test/regression/init_fail.manifest | 2 -- .../shim/test/regression/init_fail2.manifest | 2 -- .../shim/test/regression/large_mmap.manifest | 2 -- LibOS/shim/test/regression/manifest.template | 2 -- .../test/regression/multi_pthread.manifest | 1 - .../multi_pthread_exitless.manifest | 1 - .../test/regression/openmp.manifest.template | 2 -- Pal/regression/Bootstrap3.manifest | 1 - Pal/regression/Bootstrap6.manifest | 1 - Pal/regression/Bootstrap7.manifest | 1 - Pal/regression/File.manifest | 2 -- Pal/regression/Process3.manifest | 2 -- Pal/regression/Thread2.manifest | 1 - Pal/regression/Thread2_exitless.manifest | 1 - Pal/regression/manifest.template | 1 - Pal/src/host/Linux-SGX/sgx_framework.c | 10 +----- Pal/src/host/Linux-SGX/sgx_internal.h | 1 - Pal/src/host/Linux-SGX/sgx_main.c | 36 ++++++++----------- Tools/gsc/templates/manifest.template | 3 -- python/graphenelibos/sgx_sign.py | 8 ++--- tests/benchmarks/basic.manifest.template | 2 -- 49 files changed, 19 insertions(+), 135 deletions(-) diff --git a/Documentation/manifest-syntax.rst b/Documentation/manifest-syntax.rst index 433c0760..2d66a2e6 100644 --- a/Documentation/manifest-syntax.rst +++ b/Documentation/manifest-syntax.rst @@ -270,17 +270,6 @@ The PAL and library OS code/data count towards this size value, as well as the application memory itself: application's code, stack, heap, loaded application libraries, etc. The application cannot allocate memory that exceeds this limit. -Non-PIE binaries -^^^^^^^^^^^^^^^^ - -:: - - sgx.nonpie_binary = [1|0] - (Default: 0) - -This setting tells Graphene whether to use a specially crafted memory layout, -which is required to support non-relocatable binaries (non-PIE). - Number of threads ^^^^^^^^^^^^^^^^^ diff --git a/Documentation/quickstart.rst b/Documentation/quickstart.rst index 393b98c5..3c3b7f09 100644 --- a/Documentation/quickstart.rst +++ b/Documentation/quickstart.rst @@ -72,13 +72,6 @@ second command should list the process status of :command:`aesm_service`. # the console will prompt you for the path to the Intel SGX driver code # (simply press ENTER if you use the in-kernel Intel SGX driver) -#. Set ``vm.mmap_min_addr=0`` in the system (*only required for the legacy SGX - driver and not needed for newer DCAP/in-kernel drivers*):: - - sudo sysctl vm.mmap_min_addr=0 - - Note that this is an inadvisable configuration for production systems. - #. Build and run :program:`helloworld`:: cd $GRAPHENE_DIR/LibOS/shim/test/native diff --git a/Examples/apache/httpd.manifest.template b/Examples/apache/httpd.manifest.template index 6ed5adcd..abe4877f 100644 --- a/Examples/apache/httpd.manifest.template +++ b/Examples/apache/httpd.manifest.template @@ -44,8 +44,6 @@ fs.mount.cwd.uri = "file:$(INSTALL_DIR)" # SGX general options -sgx.nonpie_binary = 1 - # Set the virtual memory size of the SGX enclave. For SGX v1, the enclave # size must be specified during signing. If Apache needs more virtual memory # than the enclave size, Graphene will not be able to allocate it. diff --git a/Examples/bash/manifest.template b/Examples/bash/manifest.template index 66376c73..993de66e 100644 --- a/Examples/bash/manifest.template +++ b/Examples/bash/manifest.template @@ -79,5 +79,3 @@ sgx.trusted_files.libnssfiles = "file:$(ARCH_LIBDIR)/libnss_files.so.2" sgx.trusted_files.libnssnis = "file:$(ARCH_LIBDIR)/libnss_nis.so.2" sgx.allowed_files.scripts = "file:scripts" - -sgx.nonpie_binary = 1 diff --git a/Examples/blender/blender.manifest.template b/Examples/blender/blender.manifest.template index f664f42f..854e015d 100644 --- a/Examples/blender/blender.manifest.template +++ b/Examples/blender/blender.manifest.template @@ -53,7 +53,6 @@ sys.stack.size = "8M" sgx.enclave_size = "2048M" sgx.thread_num = 64 -sgx.nonpie_binary = 1 sgx.trusted_files.blender = "file:$(BLENDER_DIR)/blender" sgx.trusted_files.ld = "file:$(GRAPHENE_DIR)/Runtime/ld-linux-x86-64.so.2" diff --git a/Examples/gcc/gcc.manifest.template b/Examples/gcc/gcc.manifest.template index 262bee0e..f2ec3e90 100644 --- a/Examples/gcc/gcc.manifest.template +++ b/Examples/gcc/gcc.manifest.template @@ -24,7 +24,6 @@ fs.mount.tmp.path = "/tmp" fs.mount.tmp.uri = "file:/tmp" sgx.enclave_size = "1G" -sgx.nonpie_binary = 1 sgx.trusted_files.ld = "file:$(GRAPHENEDIR)/Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:$(GRAPHENEDIR)/Runtime/libc.so.6" diff --git a/Examples/lighttpd/lighttpd.manifest.template b/Examples/lighttpd/lighttpd.manifest.template index f84f1241..ad0a4662 100644 --- a/Examples/lighttpd/lighttpd.manifest.template +++ b/Examples/lighttpd/lighttpd.manifest.template @@ -62,8 +62,6 @@ sgx.enclave_size = "256M" # the application can create is (sgx.thread_num - 2). sgx.thread_num = 3 -sgx.nonpie_binary = 1 - # SGX trusted files sgx.trusted_files.lighttpd = "file:$(INSTALL_DIR)/sbin/lighttpd" diff --git a/Examples/memcached/memcached.manifest.template b/Examples/memcached/memcached.manifest.template index 51f73aef..e1d0bbc8 100644 --- a/Examples/memcached/memcached.manifest.template +++ b/Examples/memcached/memcached.manifest.template @@ -102,8 +102,6 @@ fs.mount.etc.uri = "file:/etc" # an issue in Memcached source code, not related to Graphene. sgx.enclave_size = "1024M" -sgx.nonpie_binary = 1 - # Set maximum number of in-enclave threads (somewhat arbitrarily) to 16. Recall # that SGX v1 requires to specify the maximum number of simulteneous threads at # enclave creation time. If Memcached spawns more threads, Graphene-SGX fails. diff --git a/Examples/nginx/nginx.manifest.template b/Examples/nginx/nginx.manifest.template index 03e9a9c5..8cb65b5e 100644 --- a/Examples/nginx/nginx.manifest.template +++ b/Examples/nginx/nginx.manifest.template @@ -45,8 +45,6 @@ fs.mount.cwd.uri = "file:$(INSTALL_DIR)" # than the enclave size, Graphene will not be able to allocate it. sgx.enclave_size = "256M" -sgx.nonpie_binary = 1 - # Set the maximum number of enclave threads. For SGX v1, the number of enclave # TCSes must be specified during signing, so the application cannot use more # threads than the number of TCSes. Note that Graphene also creates an internal diff --git a/Examples/nodejs-express-server/nodejs.manifest.template b/Examples/nodejs-express-server/nodejs.manifest.template index 41b8e48c..21bb99dd 100644 --- a/Examples/nodejs-express-server/nodejs.manifest.template +++ b/Examples/nodejs-express-server/nodejs.manifest.template @@ -37,8 +37,6 @@ fs.mount.lib3.uri = "file:/usr/$(ARCH_LIBDIR)" # time. sgx.enclave_size = "2G" -sgx.nonpie_binary = 1 - # Set maximum number of in-enclave threads to 8. Recall that SGX v1 requires to specify the maximum # number of simultaneous threads at enclave creation time. sgx.thread_num = 8 diff --git a/Examples/python-scipy-insecure/python.manifest.template b/Examples/python-scipy-insecure/python.manifest.template index fa1b6b1d..eab4e6c3 100644 --- a/Examples/python-scipy-insecure/python.manifest.template +++ b/Examples/python-scipy-insecure/python.manifest.template @@ -65,8 +65,6 @@ sys.stack.size = "2M" # SGX general options -sgx.nonpie_binary = 1 - # Set the virtual memory size of the SGX enclave. For SGX v1, the enclave # size must be specified during signing. If Python needs more virtual memory # than the enclave size, Graphene will not be able to allocate it. diff --git a/Examples/python-simple/python.manifest.template b/Examples/python-simple/python.manifest.template index da5b61cb..c7a3a0ff 100644 --- a/Examples/python-simple/python.manifest.template +++ b/Examples/python-simple/python.manifest.template @@ -72,8 +72,6 @@ sgx.enclave_size = "1G" # the application can create is (sgx.thread_num - 2). sgx.thread_num = 8 -sgx.nonpie_binary = 1 - # SGX trusted libraries sgx.trusted_files.python = "file:$(PYTHONEXEC)" diff --git a/Examples/pytorch/pytorch.manifest.template b/Examples/pytorch/pytorch.manifest.template index f950d0d9..4b7d3ded 100644 --- a/Examples/pytorch/pytorch.manifest.template +++ b/Examples/pytorch/pytorch.manifest.template @@ -164,8 +164,6 @@ sgx.allowed_files.resolv = "file:/etc/resolv.conf" # System's file system table sgx.allowed_files.fstab = "file:/etc/fstab" -sgx.nonpie_binary = 1 - # Graphene optionally provides patched OpenMP runtime library that runs faster # inside SGX enclaves (execute `make -C LibOS gcc` to generate it). Uncomment # the lines below to use the patched library. PyTorch's SGX perf overhead diff --git a/Examples/r/R.manifest.template b/Examples/r/R.manifest.template index 9653b01f..307e7b20 100644 --- a/Examples/r/R.manifest.template +++ b/Examples/r/R.manifest.template @@ -57,8 +57,6 @@ sys.stack.size = "8M" # SGX general options -sgx.nonpie_binary = 1 - # Set the virtual memory size of the SGX enclave. For SGX v1, the enclave size must be specified # during signing. If R needs more virtual memory than the enclave size, Graphene will not be able to # allocate it. diff --git a/Examples/redis/redis-server.manifest.template b/Examples/redis/redis-server.manifest.template index 9578d4c9..512d892a 100644 --- a/Examples/redis/redis-server.manifest.template +++ b/Examples/redis/redis-server.manifest.template @@ -74,8 +74,6 @@ fs.mount.etc.uri = "file:/etc" # typical Redis workloads. sgx.enclave_size = "1024M" -sgx.nonpie_binary = 1 - # Set maximum number of in-enclave threads (somewhat arbitrarily) to 8. Recall # that SGX v1 requires to specify the maximum number of simulteneous threads at # enclave creation time. diff --git a/Examples/tensorflow-lite/label_image.manifest.template b/Examples/tensorflow-lite/label_image.manifest.template index a47d648b..5a67aad7 100644 --- a/Examples/tensorflow-lite/label_image.manifest.template +++ b/Examples/tensorflow-lite/label_image.manifest.template @@ -14,8 +14,6 @@ fs.mount.lib1.uri = "file:$(GRAPHENEDIR)/Runtime" # Minimum amount of memory to make it work. sgx.enclave_size = "512M" -sgx.nonpie_binary = 1 - # We test with 4 TensorFlow threads, so over-approximate to 16 enclave threads. sgx.thread_num = 16 diff --git a/LibOS/shim/src/elf/shim_rtld.c b/LibOS/shim/src/elf/shim_rtld.c index 5667ac55..19f551f2 100644 --- a/LibOS/shim/src/elf/shim_rtld.c +++ b/LibOS/shim/src/elf/shim_rtld.c @@ -1451,11 +1451,7 @@ int init_loader(void) { if (!exec_map) { ret = load_elf_object(exec); if (ret < 0) { - // TODO: Actually verify that the non-PIE-ness was the real cause of loading failure. - warn("ERROR: Failed to load %s. This may be caused by the binary being non-PIE, in " - "which case Graphene requires a specially-crafted memory layout. You can enable " - "it by adding 'sgx.nonpie_binary = 1' to the manifest.\n", - qstrgetstr(&exec->path)); + warn("ERROR: Failed to load %s\n", qstrgetstr(&exec->path)); goto out; } diff --git a/LibOS/shim/test/fs/manifest.template b/LibOS/shim/test/fs/manifest.template index 2e019946..f665fc57 100644 --- a/LibOS/shim/test/fs/manifest.template +++ b/LibOS/shim/test/fs/manifest.template @@ -38,5 +38,3 @@ sgx.allowed_files.tmp_dir = "file:tmp/" sgx.protected_files_key = "ffeeddccbbaa99887766554433221100" sgx.protected_files.input = "file:tmp/pf_input" sgx.protected_files.output = "file:tmp/pf_output" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/ltp/manifest.template b/LibOS/shim/test/ltp/manifest.template index 74347a80..462a876b 100644 --- a/LibOS/shim/test/ltp/manifest.template +++ b/LibOS/shim/test/ltp/manifest.template @@ -32,8 +32,6 @@ fs.mount.tmp.uri = "file:/tmp" sys.brk.max_size = "32M" sys.stack.size = "4M" -sgx.nonpie_binary = 1 - sgx.trusted_files.entrypoint = "file:$(ENTRYPOINT)" sgx.trusted_files.ld = "file:$(LIBCDIR)/ld-linux-x86-64.so.2" diff --git a/LibOS/shim/test/regression/argv_from_file.manifest b/LibOS/shim/test/regression/argv_from_file.manifest index 9f76f05e..6b46bba9 100644 --- a/LibOS/shim/test/regression/argv_from_file.manifest +++ b/LibOS/shim/test/regression/argv_from_file.manifest @@ -15,5 +15,3 @@ sgx.allowed_files.argv = "file:argv_test_input" sgx.trusted_files.ld = "file:../../../../Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.bootstrap = "file:bootstrap" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/attestation.manifest.template b/LibOS/shim/test/regression/attestation.manifest.template index bc59ede1..defea20e 100644 --- a/LibOS/shim/test/regression/attestation.manifest.template +++ b/LibOS/shim/test/regression/attestation.manifest.template @@ -21,8 +21,6 @@ sgx.trusted_files.libdl = "file:../../../../Runtime/libdl.so.2" sgx.trusted_files.libm = "file:../../../../Runtime/libm.so.6" sgx.trusted_files.attestation = "file:attestation" -sgx.nonpie_binary = 1 - sgx.remote_attestation = 1 sgx.ra_client_spid = "$(RA_CLIENT_SPID)" sgx.ra_client_linkable = $(RA_CLIENT_LINKABLE) diff --git a/LibOS/shim/test/regression/debug_log_file.manifest b/LibOS/shim/test/regression/debug_log_file.manifest index 8361c3af..0405f63b 100644 --- a/LibOS/shim/test/regression/debug_log_file.manifest +++ b/LibOS/shim/test/regression/debug_log_file.manifest @@ -13,5 +13,3 @@ fs.mount.lib.uri = "file:../../../../Runtime" sgx.trusted_files.ld = "file:../../../../Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.bootstrap = "file:bootstrap" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/debug_log_inline.manifest b/LibOS/shim/test/regression/debug_log_inline.manifest index e4e8c901..e9a2ad3d 100644 --- a/LibOS/shim/test/regression/debug_log_inline.manifest +++ b/LibOS/shim/test/regression/debug_log_inline.manifest @@ -12,5 +12,3 @@ fs.mount.lib.uri = "file:../../../../Runtime" sgx.trusted_files.ld = "file:../../../../Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.bootstrap = "file:bootstrap" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/env_from_file.manifest b/LibOS/shim/test/regression/env_from_file.manifest index f1c7ab12..87fba536 100644 --- a/LibOS/shim/test/regression/env_from_file.manifest +++ b/LibOS/shim/test/regression/env_from_file.manifest @@ -14,5 +14,3 @@ sgx.allowed_files.env = "file:env_test_input" sgx.trusted_files.ld = "file:../../../../Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.bootstrap = "file:bootstrap" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/env_from_host.manifest b/LibOS/shim/test/regression/env_from_host.manifest index 3dfba0ee..972df342 100644 --- a/LibOS/shim/test/regression/env_from_host.manifest +++ b/LibOS/shim/test/regression/env_from_host.manifest @@ -13,5 +13,3 @@ fs.mount.lib.uri = "file:../../../../Runtime" sgx.trusted_files.ld = "file:../../../../Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.bootstrap = "file:bootstrap" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/file_check_policy_allow_all_but_log.manifest b/LibOS/shim/test/regression/file_check_policy_allow_all_but_log.manifest index eeba7091..612694b8 100644 --- a/LibOS/shim/test/regression/file_check_policy_allow_all_but_log.manifest +++ b/LibOS/shim/test/regression/file_check_policy_allow_all_but_log.manifest @@ -17,5 +17,3 @@ sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.file_check_policy = "file:file_check_policy" sgx.trusted_files.test = "file:trusted_testfile" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/file_check_policy_strict.manifest b/LibOS/shim/test/regression/file_check_policy_strict.manifest index 87b7e66a..ece5163d 100644 --- a/LibOS/shim/test/regression/file_check_policy_strict.manifest +++ b/LibOS/shim/test/regression/file_check_policy_strict.manifest @@ -17,5 +17,3 @@ sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.file_check_policy = "file:file_check_policy" sgx.trusted_files.test = "file:trusted_testfile" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/host_root_fs.manifest b/LibOS/shim/test/regression/host_root_fs.manifest index 98ac7b81..8cc91a10 100644 --- a/LibOS/shim/test/regression/host_root_fs.manifest +++ b/LibOS/shim/test/regression/host_root_fs.manifest @@ -17,5 +17,3 @@ sgx.trusted_files.ld = "file:../../../../Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.libdl = "file:../../../../Runtime/libdl.so.2" sgx.trusted_files.host_root_fs = "file:host_root_fs" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/init_fail.manifest b/LibOS/shim/test/regression/init_fail.manifest index 552e9ed9..be415065 100644 --- a/LibOS/shim/test/regression/init_fail.manifest +++ b/LibOS/shim/test/regression/init_fail.manifest @@ -17,5 +17,3 @@ fs.mount.test.uri = "file:I_DONT_EXIST" sgx.trusted_files.ld = "file:../../../../Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.init_fail = "file:init_fail" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/init_fail2.manifest b/LibOS/shim/test/regression/init_fail2.manifest index 30b3d2c5..866fbeab 100644 --- a/LibOS/shim/test/regression/init_fail2.manifest +++ b/LibOS/shim/test/regression/init_fail2.manifest @@ -13,8 +13,6 @@ sgx.trusted_files.ld = "file:../../../../Runtime/ld-linux-x86-64.so.2" sgx.trusted_files.libc = "file:../../../../Runtime/libc.so.6" sgx.trusted_files.init_fail = "file:init_fail" -sgx.nonpie_binary = 1 - # this is an impossible combination of options, LibOS must fail very early in init process sgx.enclave_size = "256M" sys.brk.max_size = "512M" diff --git a/LibOS/shim/test/regression/large_mmap.manifest b/LibOS/shim/test/regression/large_mmap.manifest index 2c4200a6..9a7af413 100644 --- a/LibOS/shim/test/regression/large_mmap.manifest +++ b/LibOS/shim/test/regression/large_mmap.manifest @@ -20,5 +20,3 @@ sgx.trusted_files.large_mmap = "file:large_mmap" sgx.allowed_files.testfile = "file:testfile" sgx.enclave_size = "8G" - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/manifest.template b/LibOS/shim/test/regression/manifest.template index 82c97ec9..09605a30 100644 --- a/LibOS/shim/test/regression/manifest.template +++ b/LibOS/shim/test/regression/manifest.template @@ -43,5 +43,3 @@ sgx.allowed_files.root = "file:root" # for getdents test sgx.allowed_files.testfile = "file:testfile" # for mmap_file test sgx.thread_num = 16 - -sgx.nonpie_binary = 1 diff --git a/LibOS/shim/test/regression/multi_pthread.manifest b/LibOS/shim/test/regression/multi_pthread.manifest index 74aa7104..a5b6e006 100644 --- a/LibOS/shim/test/regression/multi_pthread.manifest +++ b/LibOS/shim/test/regression/multi_pthread.manifest @@ -16,5 +16,4 @@ sgx.trusted_files.multi_pthread = "file:multi_pthread" # app runs with 4 parallel threads + Graphene has couple internal threads sgx.thread_num = 8 -sgx.nonpie_binary = 1 sgx.enable_stats = 1 diff --git a/LibOS/shim/test/regression/multi_pthread_exitless.manifest b/LibOS/shim/test/regression/multi_pthread_exitless.manifest index 75e2d189..96c28e06 100644 --- a/LibOS/shim/test/regression/multi_pthread_exitless.manifest +++ b/LibOS/shim/test/regression/multi_pthread_exitless.manifest @@ -17,5 +17,4 @@ sgx.trusted_files.multi_pthread = "file:multi_pthread" sgx.thread_num = 8 sgx.rpc_thread_num = 8 -sgx.nonpie_binary = 1 sgx.enable_stats = 1 diff --git a/LibOS/shim/test/regression/openmp.manifest.template b/LibOS/shim/test/regression/openmp.manifest.template index 942677c3..974d1302 100644 --- a/LibOS/shim/test/regression/openmp.manifest.template +++ b/LibOS/shim/test/regression/openmp.manifest.template @@ -33,5 +33,3 @@ sgx.trusted_files.libgomp_native = "file:/usr$(ARCH_LIBDIR)/libgomp.so.1" # native one because Graphene's Runtime path has priority in LD_LIBRARY_PATH. #sgx.trusted_files.libgomp_graphene = "file:../../../../Runtime/libgomp.so.1" - -sgx.nonpie_binary = 1 diff --git a/Pal/regression/Bootstrap3.manifest b/Pal/regression/Bootstrap3.manifest index 78fada99..229f86da 100644 --- a/Pal/regression/Bootstrap3.manifest +++ b/Pal/regression/Bootstrap3.manifest @@ -4,4 +4,3 @@ loader.preload = "file:Preload1.so,file:Preload2.so" loader.argv0_override = "Bootstrap3" sgx.trusted_files.entrypoint = "file:Bootstrap3" -sgx.nonpie_binary = 1 diff --git a/Pal/regression/Bootstrap6.manifest b/Pal/regression/Bootstrap6.manifest index f748af8e..181ac944 100644 --- a/Pal/regression/Bootstrap6.manifest +++ b/Pal/regression/Bootstrap6.manifest @@ -6,6 +6,5 @@ loader.argv0_override = "Bootstrap" fs.mount.root.uri = "file:" sgx.enclave_size = "8192M" -sgx.nonpie_binary = 1 sgx.trusted_files.entrypoint = "file:Bootstrap" diff --git a/Pal/regression/Bootstrap7.manifest b/Pal/regression/Bootstrap7.manifest index 02cad889..4585f0eb 100644 --- a/Pal/regression/Bootstrap7.manifest +++ b/Pal/regression/Bootstrap7.manifest @@ -2,7 +2,6 @@ pal.entrypoint = "file:Bootstrap7" loader.argv0_override = "Bootstrap7" sgx.trusted_files.entrypoint = "file:Bootstrap7" -sgx.nonpie_binary = 1 loader.env.key1 = "na" loader.env.key2 = "na" diff --git a/Pal/regression/File.manifest b/Pal/regression/File.manifest index 666ae29e..cfde456f 100644 --- a/Pal/regression/File.manifest +++ b/Pal/regression/File.manifest @@ -4,8 +4,6 @@ loader.debug_type = "inline" fs.mount.root.uri = "file:" -sgx.nonpie_binary = 1 - sgx.trusted_files.tmp1 = "file:File" sgx.trusted_files.tmp2 = "file:../regression/File" sgx.allowed_files.tmp3 = "file:file_nonexist.tmp" diff --git a/Pal/regression/Process3.manifest b/Pal/regression/Process3.manifest index b7eaf41d..974384f5 100644 --- a/Pal/regression/Process3.manifest +++ b/Pal/regression/Process3.manifest @@ -3,6 +3,4 @@ loader.debug_type = "inline" loader.preload = "file:Preload1.so,file:Preload2.so" loader.insecure__use_cmdline_argv = 1 -sgx.nonpie_binary = 1 - sgx.trusted_files.entrypoint = "file:Process3" diff --git a/Pal/regression/Thread2.manifest b/Pal/regression/Thread2.manifest index 7f85f2d0..9ec46da5 100644 --- a/Pal/regression/Thread2.manifest +++ b/Pal/regression/Thread2.manifest @@ -3,6 +3,5 @@ loader.argv0_override = "Thread2" sgx.thread_num = 2 sgx.enable_stats = 1 -sgx.nonpie_binary = 1 sgx.trusted_files.entrypoint = "file:Thread2" diff --git a/Pal/regression/Thread2_exitless.manifest b/Pal/regression/Thread2_exitless.manifest index cbd4f4f3..3dacb9a0 100644 --- a/Pal/regression/Thread2_exitless.manifest +++ b/Pal/regression/Thread2_exitless.manifest @@ -4,6 +4,5 @@ loader.argv0_override = "Thread2" sgx.thread_num = 2 sgx.rpc_thread_num = 2 sgx.enable_stats = 1 -sgx.nonpie_binary = 1 sgx.trusted_files.entrypoint = "file:Thread2" diff --git a/Pal/regression/manifest.template b/Pal/regression/manifest.template index a54d77bf..61fcbf18 100644 --- a/Pal/regression/manifest.template +++ b/Pal/regression/manifest.template @@ -4,6 +4,5 @@ loader.insecure__use_cmdline_argv = 1 fs.mount.root.uri = "file:" sgx.trusted_files.entrypoint = "file:$(ENTRYPOINT)" -sgx.nonpie_binary = 1 # all tests are currently non-PIE unless overridden sgx.allowed_files.to_send_tmp = "file:to_send.tmp" # for SendHandle test diff --git a/Pal/src/host/Linux-SGX/sgx_framework.c b/Pal/src/host/Linux-SGX/sgx_framework.c index d207c9dc..45d6f73e 100644 --- a/Pal/src/host/Linux-SGX/sgx_framework.c +++ b/Pal/src/host/Linux-SGX/sgx_framework.c @@ -146,14 +146,11 @@ int create_enclave(sgx_arch_secs_t* secs, sgx_arch_token_t* token) { uint64_t request_mmap_addr = secs->base; uint64_t request_mmap_size = secs->size; -#ifdef SGX_DCAP - /* newer DCAP/in-kernel SGX drivers allow starting enclave address space with non-zero; - * the below trick to start from MMAP_MIN_ADDR is to avoid vm.mmap_min_addr==0 issue */ + /* We have to avoid mapping below MMAP_MIN_ADDR, it's usually not allowed on Linux. */ if (request_mmap_addr < MMAP_MIN_ADDR) { request_mmap_size -= MMAP_MIN_ADDR - request_mmap_addr; request_mmap_addr = MMAP_MIN_ADDR; } -#endif uint64_t addr = INLINE_SYSCALL(mmap, 6, request_mmap_addr, request_mmap_size, PROT_NONE, /* newer DCAP driver requires such initial mmap */ @@ -164,11 +161,6 @@ int create_enclave(sgx_arch_secs_t* secs, sgx_arch_token_t* token) { #endif if (IS_ERR_P(addr)) { - if (ERRNO_P(addr) == EPERM) { - pal_printf("Permission denied on mapping enclave. " - "You may need to set sysctl vm.mmap_min_addr to zero\n"); - } - SGX_DBG(DBG_I, "ECREATE failed in allocating EPC memory (errno = %ld)\n", ERRNO_P(addr)); return -ENOMEM; } diff --git a/Pal/src/host/Linux-SGX/sgx_internal.h b/Pal/src/host/Linux-SGX/sgx_internal.h index f29cf6c4..92a338db 100644 --- a/Pal/src/host/Linux-SGX/sgx_internal.h +++ b/Pal/src/host/Linux-SGX/sgx_internal.h @@ -59,7 +59,6 @@ struct pal_enclave { unsigned long thread_num; unsigned long rpc_thread_num; unsigned long ssaframesize; - bool nonpie_binary; bool remote_attestation_enabled; bool use_epid_attestation; /* Valid only if `remote_attestation_enabled` is true, selects * EPID/DCAP attestation scheme. */ diff --git a/Pal/src/host/Linux-SGX/sgx_main.c b/Pal/src/host/Linux-SGX/sgx_main.c index 38a02d01..a74d0495 100644 --- a/Pal/src/host/Linux-SGX/sgx_main.c +++ b/Pal/src/host/Linux-SGX/sgx_main.c @@ -233,18 +233,21 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ goto out; } - if (enclave->nonpie_binary) { - /* executable is non-PIE: enclave base address must cover code segment loaded at some - * hardcoded address (usually 0x400000), and heap cannot start at zero (modern OSes do not - * allow this) */ - enclave->baseaddr = DEFAULT_ENCLAVE_BASE; - enclave_heap_min = MMAP_MIN_ADDR; - } else { - /* executable is PIE: enclave base address can be arbitrary (we choose it same as - * enclave_size), and heap can start immediately at this base address */ - enclave->baseaddr = enclave->size; - enclave_heap_min = enclave->baseaddr; - } + /* We reserve address range [0; size) for the enclave (ELRANGE in SGX docs). The reasons for + * this choice are: + * - For non-PIE binaries it must cover some hardcoded address range (usually starting at + * 0x400000). + * - SGX requires enclave size to be a power of 2 and the enclave base address to be + * divisible by the size. + * - Having low addresses reserved for enclave makes NULL-deref bugs exploitation much + * harder. + * In the past starting ELRANGE at 0 was problematic, because the driver checked this range + * against vm.mmap_min_addr setting, which is 0x10000 by default (even if we didn't really map + * any pages at 0). This was fixed in the newer SGX drivers, so now we can just always use this + * range. + */ + enclave->baseaddr = DEFAULT_ENCLAVE_BASE; + enclave_heap_min = MMAP_MIN_ADDR; ret = read_enclave_token(enclave->token, &enclave_token); if (ret < 0) { @@ -697,15 +700,6 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) goto out; } - int64_t nonpie_binary; - ret = toml_int_in(manifest_root, "sgx.nonpie_binary", /*defaultval=*/0, &nonpie_binary); - if (ret < 0 || (nonpie_binary != 0 && nonpie_binary != 1)) { - SGX_DBG(DBG_E, "Cannot parse 'sgx.nonpie_binary' (the value must be 0 or 1)\n"); - ret = -EINVAL; - goto out; - } - enclave_info->nonpie_binary = !!nonpie_binary; - int64_t enable_stats_int64; ret = toml_int_in(manifest_root, "sgx.enable_stats", /*defaultval=*/0, &enable_stats_int64); if (ret < 0 || (enable_stats_int64 != 0 && enable_stats_int64 != 1)) { diff --git a/Tools/gsc/templates/manifest.template b/Tools/gsc/templates/manifest.template index 77151d57..a05b349b 100644 --- a/Tools/gsc/templates/manifest.template +++ b/Tools/gsc/templates/manifest.template @@ -16,9 +16,6 @@ fs.root.uri = "file:/" # working directory to the desired location fs.start_dir = "{{working_dir}}" -# Start at static addresses (otherwise breaks when non-relocatable executables are used) -sgx.nonpie_binary = 1 - {% if insecure_args %} # !! INSECURE !! Allow passing command-line arguments from the host without validation # Most Docker images rely on runtime arguments and hence, a more general technique is required. diff --git a/python/graphenelibos/sgx_sign.py b/python/graphenelibos/sgx_sign.py index 7ca39779..2ea77578 100644 --- a/python/graphenelibos/sgx_sign.py +++ b/python/graphenelibos/sgx_sign.py @@ -781,12 +781,8 @@ def main_sign(args): # Try populate memory areas memory_areas = get_memory_areas(attr, args) - if manifest.get('sgx.nonpie_binary', None) == '1': - enclave_base = offs.DEFAULT_ENCLAVE_BASE - enclave_heap_min = offs.MMAP_MIN_ADDR - else: - enclave_base = attr['enclave_size'] - enclave_heap_min = enclave_base + enclave_base = offs.DEFAULT_ENCLAVE_BASE + enclave_heap_min = offs.MMAP_MIN_ADDR if manifest.get('sgx.enable_stats', None) is None: manifest['sgx.enable_stats'] = '0' diff --git a/tests/benchmarks/basic.manifest.template b/tests/benchmarks/basic.manifest.template index 182bdf1b..0cd0255f 100644 --- a/tests/benchmarks/basic.manifest.template +++ b/tests/benchmarks/basic.manifest.template @@ -17,5 +17,3 @@ sgx.trusted_files.libm = file:@GRAPHENEDIR@/Runtime/libm.so.6 sgx.trusted_files.libpthread = file:@GRAPHENEDIR@/Runtime/libpthread.so.0 sgx.thread_num = 3 - -#sgx.nonpie_binary = 1