diff --git a/Examples/r/Makefile b/Examples/r/Makefile index f1bed1d8..cdd98635 100644 --- a/Examples/r/Makefile +++ b/Examples/r/Makefile @@ -27,9 +27,9 @@ LD_LIBRARY_PATH := $(LD_LIBRARY_PATH):$(R_HOME)/lib export LD_LIBRARY_PATH .PHONY: all -all: R.manifest sh.manifest pal_loader +all: R.manifest sh.manifest rm.manifest pal_loader ifeq ($(SGX),1) -all: R.manifest.sgx R.sig R.token sh.manifest.sgx sh.sig sh.token +all: R.manifest.sgx R.sig R.token sh.manifest.sgx sh.sig sh.token rm.manifest.sgx rm.sig rm.token endif include ../../Scripts/Makefile.configs @@ -85,7 +85,7 @@ R.manifest: R.manifest.template R-trusted-libs -e 's|$$(ARCH_LIBDIR)|'"$(ARCH_LIBDIR)"'|g' \ $< > $@ -sh.manifest: sh.manifest.template +%.manifest: %.manifest.template sed -e 's|$$(GRAPHENEDIR)|'"$(GRAPHENEDIR)"'|g' \ -e 's|$$(GRAPHENEDEBUG)|'"$(GRAPHENEDEBUG)"'|g' \ $< > $@ @@ -94,30 +94,24 @@ sh.manifest: sh.manifest.template # Generating the SGX-specific manifest (R.manifest.sgx), the enclave signature, # and the token for enclave initialization. -R.manifest.sgx: R.manifest sh.manifest.sgx +%.manifest.sgx: %.manifest $(GRAPHENEDIR)/Pal/src/host/Linux-SGX/signer/pal-sgx-sign \ -libpal $(GRAPHENEDIR)/Runtime/libpal-Linux-SGX.so \ -key $(SGX_SIGNER_KEY) \ -manifest $< -output $@ +# Theoretically we could write "%.sig: %.manifest.sgx" or use a "Rule with Grouped Targets" +# ("%.manifest.sgx %.sig &: %.manifest") but neither of this works (Make is broken?). R.sig: R.manifest.sgx - -R.token: R.sig - $(GRAPHENEDIR)/Pal/src/host/Linux-SGX/signer/pal-sgx-get-token \ - -output R.token -sig R.sig - -# sh.manifest.sgx is needed for R to run the shell for file clean-up -sh.manifest.sgx: sh.manifest - $(GRAPHENEDIR)/Pal/src/host/Linux-SGX/signer/pal-sgx-sign \ - -libpal $(GRAPHENEDIR)/Runtime/libpal-Linux-SGX.so \ - -key $(SGX_SIGNER_KEY) \ - -manifest $< -output $@ - sh.sig: sh.manifest.sgx +rm.sig: rm.manifest.sgx -sh.token: sh.sig - $(GRAPHENEDIR)/Pal/src/host/Linux-SGX/signer/pal-sgx-get-token \ - -output sh.token -sig sh.sig +%.token: %.sig + $(GRAPHENEDIR)/Pal/src/host/Linux-SGX/signer/pal-sgx-get-token -output $@ -sig $< + +# sh and rm are used by R for file clean-up +R.manifest.sgx: sh.sig +sh.manifest.sgx: rm.sig # Extra executables pal_loader: @@ -126,3 +120,6 @@ pal_loader: .PHONY: clean clean: $(RM) *.manifest *.manifest.sgx *.token *.sig pal_loader + +.PHONY: distclean +distclean: clean diff --git a/Examples/r/R.manifest.template b/Examples/r/R.manifest.template index c83e0428..7eff1198 100644 --- a/Examples/r/R.manifest.template +++ b/Examples/r/R.manifest.template @@ -56,6 +56,10 @@ fs.mount.tmp.type = chroot fs.mount.tmp.path = /tmp fs.mount.tmp.uri = file:/tmp +# Mount host's /bin +fs.mount.bin.type = chroot +fs.mount.bin.path = /bin +fs.mount.bin.uri = file:/bin # SGX general options @@ -93,7 +97,9 @@ sgx.allowed_files.tmp = file:/tmp sgx.allowed_files.r_etc = file:$(R_HOME)/etc sgx.allowed_files.r_lib = file:$(R_HOME)/library -# Allow creating child enclaves for sh +# R uses shell to delete files, so we need to allow /bin/sh and /bin/rm to be spawned. +# strace snippet: execve("/bin/sh", ["sh", "-c", "rm -rf /tmp/RtmpEiedDF"], [/* 41 vars */]) + sgx.trusted_files.sh = file:/bin/sh sgx.trusted_children.sh = file:sh.sig diff --git a/Examples/r/rm.manifest.template b/Examples/r/rm.manifest.template new file mode 100644 index 00000000..2b8b7275 --- /dev/null +++ b/Examples/r/rm.manifest.template @@ -0,0 +1,32 @@ +# rm manifest example +# +# This manifest was prepared and tested on Ubuntu 16.04. + +loader.exec = file:/bin/rm +loader.preload = file:$(GRAPHENEDIR)/Runtime/libsysdb.so +loader.debug_type = $(GRAPHENEDEBUG) + +# Don't use this on production! +loader.insecure__use_cmdline_argv = 1 + +loader.env.LD_LIBRARY_PATH = /lib + +fs.mount.lib.type = chroot +fs.mount.lib.path = /lib +fs.mount.lib.uri = file:$(GRAPHENEDIR)/Runtime + +fs.mount.tmp.type = chroot +fs.mount.tmp.path = /tmp +fs.mount.tmp.uri = file:/tmp + +fs.mount.bin.type = chroot +fs.mount.bin.path = /bin +fs.mount.bin.uri = file:/bin + +sgx.enclave_size = 1G +sgx.thread_num = 4 + +sgx.trusted_files.ld = file:$(GRAPHENEDIR)/Runtime/ld-linux-x86-64.so.2 +sgx.trusted_files.libc = file:$(GRAPHENEDIR)/Runtime/libc.so.6 + +sgx.zero_heap_on_demand = 1 diff --git a/Examples/r/sh.manifest.template b/Examples/r/sh.manifest.template index 80db9c53..3079d357 100644 --- a/Examples/r/sh.manifest.template +++ b/Examples/r/sh.manifest.template @@ -24,12 +24,22 @@ fs.mount.lib.type = chroot fs.mount.lib.path = /lib fs.mount.lib.uri = file:$(GRAPHENEDIR)/Runtime +# Mount /tmp +fs.mount.tmp.type = chroot +fs.mount.tmp.path = /tmp +fs.mount.tmp.uri = file:/tmp + +# Mount host's /bin +fs.mount.bin.type = chroot +fs.mount.bin.path = /bin +fs.mount.bin.uri = file:/bin + # SGX general options # Set the virtual memory size of the SGX enclave. For SGX v1, the enclave size # must be specified during signing. If sh needs more virtual memory than the # enclave size, Graphene will not be able to allocate it. -sgx.enclave_size = 256M +sgx.enclave_size = 1G # 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 @@ -37,10 +47,13 @@ sgx.enclave_size = 256M # thread for handling inter-process communication (IPC), and potentially another # thread for asynchronous events. Therefore, the actual number of threads that # the application can create is (sgx.thread_num - 2). -sgx.thread_num = 2 +sgx.thread_num = 4 # SGX trusted libraries sgx.trusted_files.ld = file:$(GRAPHENEDIR)/Runtime/ld-linux-x86-64.so.2 sgx.trusted_files.libc = file:$(GRAPHENEDIR)/Runtime/libc.so.6 +sgx.trusted_files.rm = file:/bin/rm +sgx.trusted_children.rm = file:rm.sig + sgx.zero_heap_on_demand = 1