Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
[Pal/Linux-SGX] Define SGX allowed/trusted/protected files as TOML ar…
Browse files Browse the repository at this point in the history
…rays

This commit adds a new manifest syntax to define lists of SGX allowed,
trusted, protected files. The previous syntax used TOML tables:

  sgx.trusted_files.file1 = "file:foo"
  sgx.trusted_files.file2 = "file:bar"

The new syntax uses TOML arrays:

  sgx.trusted_files = [ "file:foo", "file:bar" ]

The new syntax also allows to specify SHA256 hashes for a subset of
trusted files (to skip hash generation during `graphene-sgx-sign`):

  [[sgx.trusted_files]]
  uri    = "file:trusted_testfile"
  sha256 = "c49a0aae384a14c8320f015ed5958d4402ba0726a31c4230cf772f76ff8aca2e"

The previous TOML-table syntax is still supported but deprecated.
Graphene utility `graphene-sgx-sign` generates final SGX manifests using
the new syntax, but `graphene-sgx` can still run old-syntax manifests.
All Graphene regression tests are updated to use the new syntax. But
all examples still use the old syntax; to be fixed in next commits.

Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
  • Loading branch information
Dmitrii Kuvaiskii committed Aug 31, 2021
1 parent fe8781f commit ddc01ba
Show file tree
Hide file tree
Showing 31 changed files with 549 additions and 225 deletions.
32 changes: 26 additions & 6 deletions Documentation/manifest-syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ Allowed files

::

sgx.allowed_files.[identifier] = "[URI]"
sgx.allowed_files = [
"[URI]",
"[URI]",
]

This syntax specifies the files that are allowed to be created or loaded into
the enclave unconditionally. In other words, allowed files can be opened for
Expand All @@ -471,24 +474,41 @@ Trusted files

::

sgx.trusted_files.[identifier] = "[URI]"
# entries can be strings
sgx.trusted_files = [
"[URI]",
"[URI]",
]

# entries can also be tables
[[sgx.trusted_files]]
uri = "[URI]"
sha256 = "[HASH]"

This syntax specifies the files to be cryptographically hashed at build time,
and allowed to be accessed by the app in runtime only if their hashes match.
This implies that trusted files can be only opened for reading (not for writing)
and cannot be created if they do not exist already. The signer tool will
automatically generate hashes of these files and add them to the SGX-specific
manifest (``.manifest.sgx``). Marking files as trusted is especially useful for
shared libraries: a |~| trusted library cannot be silently replaced by a
malicious host because the hash verification will fail.
manifest (``.manifest.sgx``). The manifest writer may also specify the hash for
a file using the TOML-table syntax, in the field ``sha256``; in this case,
hashing of the file will be skipped by the signer tool and the value in
``sha256`` field will be used instead.

Marking files as trusted is especially useful for shared libraries: a |~|
trusted library cannot be silently replaced by a malicious host because the hash
verification will fail.

Protected files
^^^^^^^^^^^^^^^

::

sgx.protected_files_key = "[16-byte hex value]"
sgx.protected_files.[identifier] = "[URI]"
sgx.protected_files = [
"[URI]",
"[URI]",
]

This syntax specifies the files that are encrypted on disk and transparently
decrypted when accessed by Graphene or by application running inside Graphene.
Expand Down
24 changes: 14 additions & 10 deletions LibOS/shim/test/fs/manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ fs.mount.tmpfs.type = "tmpfs"
fs.mount.tmpfs.path = "/mnt-tmpfs"
fs.mount.tmpfs.uri = "file:dummy-unused-by-tmpfs-uri"

sgx.trusted_files.entrypoint = "file:{{ entrypoint }}"
sgx.nonpie_binary = true
sgx.thread_num = 16

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.libgcc_s = "file:{{ arch_libdir }}/libgcc_s.so.1"
sgx.allowed_files = [
"file:tmp/",
]

sgx.allowed_files.tmp_dir = "file:tmp/"
sgx.trusted_files = [
"file:{{ entrypoint }}",
"file:{{ graphene.runtimedir() }}/",
"file:{{ arch_libdir }}/libgcc_s.so.1",
]

sgx.protected_files_key = "ffeeddccbbaa99887766554433221100"
sgx.protected_files.input = "file:tmp/pf_input"
sgx.protected_files.output = "file:tmp/pf_output"

sgx.nonpie_binary = true

sgx.thread_num = 16
sgx.protected_files = [
"file:tmp/pf_input",
"file:tmp/pf_output",
]
26 changes: 14 additions & 12 deletions LibOS/shim/test/ltp/manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ fs.mount.tmp.uri = "file:/tmp"

sys.brk.max_size = "32M"
sys.stack.size = "4M"

sgx.nonpie_binary = true

sgx.trusted_files.entrypoint = "file:{{ entrypoint }}"

sgx.trusted_files.ld = "file:{{ graphene.runtimedir() }}/ld-linux-x86-64.so.2"
sgx.trusted_files.libc = "file:{{ graphene.runtimedir() }}/libc.so.6"
sgx.trusted_files.libdl = "file:{{ graphene.runtimedir() }}/libdl.so.2"
sgx.trusted_files.libm = "file:{{ graphene.runtimedir() }}/libm.so.6"
sgx.trusted_files.libpthread = "file:{{ graphene.runtimedir() }}/libpthread.so.0"
sgx.trusted_files.librt = "file:{{ graphene.runtimedir() }}/librt.so.1"
sgx.trusted_files.libstdbuf = "file:{{ coreutils_libdir }}/libstdbuf.so"

sgx.allowed_files.tmp = "file:/tmp"
sgx.allowed_files = [
"file:/tmp",
]

sgx.trusted_files = [
"file:{{ entrypoint }}",
"file:{{ graphene.runtimedir() }}/ld-linux-x86-64.so.2",
"file:{{ graphene.runtimedir() }}/libc.so.6",
"file:{{ graphene.runtimedir() }}/libdl.so.2",
"file:{{ graphene.runtimedir() }}/libm.so.6",
"file:{{ graphene.runtimedir() }}/libpthread.so.0",
"file:{{ graphene.runtimedir() }}/librt.so.1",
"file:{{ coreutils_libdir }}/libstdbuf.so",
]
1 change: 1 addition & 0 deletions LibOS/shim/test/regression/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/nonexisting_testfile
/testfile
/trusted_testfile

/.cache
/abort
Expand Down
1 change: 1 addition & 0 deletions LibOS/shim/test/regression/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,6 @@ clean-tmp:
__pycache__ \
libos-regression.xml \
testfile \
trusted_testfile \
tmp/* \
*.o
12 changes: 8 additions & 4 deletions LibOS/shim/test/regression/argv_from_file.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.allowed_files.argv = "file:argv_test_input"
sgx.nonpie_binary = true

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.bootstrap = "file:bootstrap"
sgx.allowed_files = [
"file:argv_test_input",
]

sgx.nonpie_binary = true
sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:bootstrap",
]
11 changes: 6 additions & 5 deletions LibOS/shim/test/regression/attestation.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ fs.mount.bin.type = "chroot"
fs.mount.bin.path = "/bin"
fs.mount.bin.uri = "file:/bin"

# sgx-related
sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.attestation = "file:attestation"

sgx.nonpie_binary = true

sgx.remote_attestation = true

sgx.ra_client_spid = "{{ ra_client_spid }}"
sgx.ra_client_linkable = {{ ra_client_linkable }}

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:attestation",
]
18 changes: 9 additions & 9 deletions LibOS/shim/test/regression/bootstrap_cpp.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ fs.mount.host_usr_lib.type = "chroot"
fs.mount.host_usr_lib.path = "/usr/{{ arch_libdir }}"
fs.mount.host_usr_lib.uri = "file:/usr/{{ arch_libdir }}"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.libgcc_s = "file:{{ arch_libdir }}/libgcc_s.so.1"
sgx.trusted_files.libstdcxx = "file:/usr{{ arch_libdir }}/libstdc++.so.6"
sgx.trusted_files.libunwindso = "file:/usr{{ arch_libdir }}/libunwind.so.8"
sgx.trusted_files.liblzma = "file:{{ arch_libdir }}/liblzma.so.5"

sgx.trusted_files.entrypoint = "file:bootstrap_cpp"

sgx.thread_num = 8

sgx.nonpie_binary = true

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:{{ arch_libdir }}/libgcc_s.so.1",
"file:/usr{{ arch_libdir }}/libstdc++.so.6",
"file:/usr{{ arch_libdir }}/libunwind.so.8",
"file:{{ arch_libdir }}/liblzma.so.5",
"file:bootstrap_cpp",
]
8 changes: 5 additions & 3 deletions LibOS/shim/test/regression/debug_log_file.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.bootstrap = "file:bootstrap"

sgx.nonpie_binary = true

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:bootstrap",
]
8 changes: 5 additions & 3 deletions LibOS/shim/test/regression/debug_log_inline.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.bootstrap = "file:bootstrap"

sgx.nonpie_binary = true

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:bootstrap",
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ fs.mount.dev.type = "chroot"
fs.mount.dev.path = "/dev/host-zero"
fs.mount.dev.uri = "dev:/dev/zero"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"

sgx.trusted_files.entrypoint = "file:device_passthrough"

sgx.nonpie_binary = true

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:device_passthrough",
]
11 changes: 7 additions & 4 deletions LibOS/shim/test/regression/env_from_file.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.allowed_files.env = "file:env_test_input"
sgx.nonpie_binary = true

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.bootstrap = "file:bootstrap"
# this tests the old syntax for allowed_files (TOML table)
sgx.allowed_files.env = "file:env_test_input"

sgx.nonpie_binary = true
sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:bootstrap",
]
8 changes: 5 additions & 3 deletions LibOS/shim/test/regression/env_from_host.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.bootstrap = "file:bootstrap"

sgx.nonpie_binary = true

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:bootstrap",
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.nonpie_binary = true
sgx.file_check_policy = "allow_all_but_log"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.file_check_policy = "file:file_check_policy"
sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
]

sgx.trusted_files.test = "file:trusted_testfile"
# below entry in sgx.trusted_files is to test TOML-table syntax without `sha256`
[[sgx.trusted_files]]
uri = "file:file_check_policy"

sgx.nonpie_binary = true
# below entry in sgx.trusted_files is for testing purposes (trusted_testfile has
# hard-coded contents, so we can use pre-calculated SHA256 hash)
[[sgx.trusted_files]]
uri = "file:trusted_testfile"
sha256 = "41dacdf1e6d0481d3b1ab1a91f93139db02b96f29cfdd3fb0b819ba1e33cafc4"
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.nonpie_binary = true
sgx.file_check_policy = "strict"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.file_check_policy = "file:file_check_policy"
sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
]

sgx.trusted_files.test = "file:trusted_testfile"
# below entry in sgx.trusted_files is to test TOML-table syntax without `sha256`
[[sgx.trusted_files]]
uri = "file:file_check_policy"

sgx.nonpie_binary = true
# below entry in sgx.trusted_files is for testing purposes (trusted_testfile has
# hard-coded contents, so we can use pre-calculated SHA256 hash)
[[sgx.trusted_files]]
uri = "file:trusted_testfile"
sha256 = "41dacdf1e6d0481d3b1ab1a91f93139db02b96f29cfdd3fb0b819ba1e33cafc4"
8 changes: 5 additions & 3 deletions LibOS/shim/test/regression/host_root_fs.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ fs.mount.graphene_lib.type = "chroot"
fs.mount.graphene_lib.path = "/lib"
fs.mount.graphene_lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.host_root_fs = "file:{{ env.PWD }}/host_root_fs"

sgx.nonpie_binary = true

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:{{ env.PWD }}/host_root_fs",
]
8 changes: 5 additions & 3 deletions LibOS/shim/test/regression/init_fail.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ fs.mount.test.type = "chroot"
fs.mount.test.path = "/test"
fs.mount.test.uri = "file:I_DONT_EXIST"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.init_fail = "file:init_fail"

sgx.nonpie_binary = true

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:init_fail",
]
8 changes: 5 additions & 3 deletions LibOS/shim/test/regression/init_fail2.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.init_fail = "file:init_fail"

sgx.nonpie_binary = true

# this is an impossible combination of options, LibOS must fail very early in init process
sgx.enclave_size = "256M"
sys.brk.max_size = "512M"

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:init_fail",
]
15 changes: 9 additions & 6 deletions LibOS/shim/test/regression/large_mmap.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ graphene.runtimedir() }}"

sgx.trusted_files.runtime = "file:{{ graphene.runtimedir() }}/"
sgx.trusted_files.large_mmap = "file:large_mmap"

sgx.allowed_files.testfile = "file:testfile"

sgx.enclave_size = "8G"

sgx.nonpie_binary = true

sgx.allowed_files = [
"file:testfile",
]

sgx.trusted_files = [
"file:{{ graphene.runtimedir() }}/",
"file:large_mmap",
]
Loading

0 comments on commit ddc01ba

Please sign in to comment.