Browse Source

[Pal/Linux-SGX] Drop effectively unused manifest/exec fd

exec_fd and manifest_fd were already mostly unused. Drop them to make it
more obvious that they are never used to read the executable or
manifest from the urts.

Part of issue #509.
Simon Gaiser 6 years ago
parent
commit
f2cf0d01de

+ 17 - 8
Pal/src/host/Linux-SGX/db_main.c

@@ -87,7 +87,13 @@ int init_enclave (void);
 int init_enclave_key (void);
 int init_enclave_key (void);
 int init_child_process (PAL_HANDLE * parent_handle);
 int init_child_process (PAL_HANDLE * parent_handle);
 
 
-static PAL_HANDLE setup_file_handle (const char * name, int fd)
+/*
+ * Creates a dummy file handle with the given name.
+ *
+ * The handle is not backed by any file. Reads will return EOF and writes will
+ * fail.
+ */
+static PAL_HANDLE setup_dummy_file_handle (const char * name)
 {
 {
     if (!strpartcmp_static(name, "file:"))
     if (!strpartcmp_static(name, "file:"))
         return NULL;
         return NULL;
@@ -97,7 +103,7 @@ static PAL_HANDLE setup_file_handle (const char * name, int fd)
     PAL_HANDLE handle = malloc(HANDLE_SIZE(file) + len + 1);
     PAL_HANDLE handle = malloc(HANDLE_SIZE(file) + len + 1);
     SET_HANDLE_TYPE(handle, file);
     SET_HANDLE_TYPE(handle, file);
     HANDLE_HDR(handle)->flags |= RFD(0);
     HANDLE_HDR(handle)->flags |= RFD(0);
-    handle->file.fd = fd;
+    handle->file.fd = PAL_IDX_POISON;
     handle->file.append = 0;
     handle->file.append = 0;
     handle->file.pass = 0;
     handle->file.pass = 0;
 
 
@@ -177,15 +183,18 @@ void pal_linux_main(const char ** arguments, const char ** environments,
 
 
     SET_ENCLAVE_TLS(ready_for_exceptions, 1UL);
     SET_ENCLAVE_TLS(ready_for_exceptions, 1UL);
 
 
-    /* create executable handle */
+    /*
+     * We create dummy handles for exec and manifest here to make the logic in
+     * pal_main happy and pass the path of them. The handles can't be used to
+     * read anything.
+     */
+
     PAL_HANDLE manifest, exec = NULL;
     PAL_HANDLE manifest, exec = NULL;
 
 
-    /* create manifest handle */
-    manifest =
-        setup_file_handle(pal_sec.manifest_name, pal_sec.manifest_fd);
+    manifest = setup_dummy_file_handle(pal_sec.manifest_name);
 
 
-    if (pal_sec.exec_fd != PAL_IDX_POISON) {
-        exec = setup_file_handle(pal_sec.exec_name, pal_sec.exec_fd);
+    if (pal_sec.exec_name[0] != '\0') {
+        exec = setup_dummy_file_handle(pal_sec.exec_name);
     } else {
     } else {
         SGX_DBG(DBG_I, "Run without executable\n");
         SGX_DBG(DBG_I, "Run without executable\n");
     }
     }

+ 1 - 1
Pal/src/host/Linux-SGX/enclave_framework.c

@@ -645,7 +645,7 @@ int init_trusted_files (void)
     ssize_t cfgsize;
     ssize_t cfgsize;
     int nuris, ret;
     int nuris, ret;
 
 
-    if (pal_sec.exec_fd != PAL_IDX_POISON) {
+    if (pal_sec.exec_name[0] != '\0') {
         ret = init_trusted_file("exec", pal_sec.exec_name);
         ret = init_trusted_file("exec", pal_sec.exec_name);
         if (ret < 0)
         if (ret < 0)
             goto out;
             goto out;

+ 0 - 2
Pal/src/host/Linux-SGX/pal_security.h

@@ -40,13 +40,11 @@ struct pal_sec {
 
 
     /* executable name, addr and size */
     /* executable name, addr and size */
     PAL_SEC_STR     exec_name;
     PAL_SEC_STR     exec_name;
-    PAL_IDX         exec_fd;
     PAL_PTR         exec_addr;
     PAL_PTR         exec_addr;
     PAL_NUM         exec_size;
     PAL_NUM         exec_size;
 
 
     /* manifest name, addr and size */
     /* manifest name, addr and size */
     PAL_SEC_STR     manifest_name;
     PAL_SEC_STR     manifest_name;
-    PAL_IDX         manifest_fd;
     PAL_PTR         manifest_addr;
     PAL_PTR         manifest_addr;
     PAL_NUM         manifest_size;
     PAL_NUM         manifest_size;
 
 

+ 0 - 3
Pal/src/host/Linux-SGX/sgx_main.c

@@ -770,14 +770,11 @@ static int load_enclave (struct pal_enclave * enclave,
     if (!pal_sec->instance_id)
     if (!pal_sec->instance_id)
         create_instance(&enclave->pal_sec);
         create_instance(&enclave->pal_sec);
 
 
-    pal_sec->manifest_fd = enclave->manifest;
     memcpy(pal_sec->manifest_name, manifest_uri, strlen(manifest_uri) + 1);
     memcpy(pal_sec->manifest_name, manifest_uri, strlen(manifest_uri) + 1);
 
 
     if (enclave->exec == -1) {
     if (enclave->exec == -1) {
-        pal_sec->exec_fd = PAL_IDX_POISON;
         memset(pal_sec->exec_name, 0, sizeof(PAL_SEC_STR));
         memset(pal_sec->exec_name, 0, sizeof(PAL_SEC_STR));
     } else {
     } else {
-        pal_sec->exec_fd = enclave->exec;
         memcpy(pal_sec->exec_name, exec_uri, strlen(exec_uri) + 1);
         memcpy(pal_sec->exec_name, exec_uri, strlen(exec_uri) + 1);
     }
     }