Explorar el Código

[Pal/Linux-SGX] Keep 8MB of enclave heap for internal PAL objects

This commit adds a hack to keep some heap (currently 8MB) for internal
PAL objects allocated at runtime (recall that LibOS does not keep track
of PAL memory, so without this hack it could overwrite internal PAL
memory). This hack is probabilistic and brittle, but sufficient for now.
Dmitrii Kuvaiskii hace 5 años
padre
commit
50316ff984
Se han modificado 1 ficheros con 11 adiciones y 1 borrados
  1. 11 1
      Pal/src/host/Linux-SGX/db_main.c

+ 11 - 1
Pal/src/host/Linux-SGX/db_main.c

@@ -63,8 +63,18 @@ void _DkGetAvailableUserAddressRange (PAL_PTR * start, PAL_PTR * end,
 {
     *start = (PAL_PTR)pal_sec.heap_min;
     *end   = (PAL_PTR)get_enclave_heap_top();
+
+    /* FIXME: hack to keep some heap for internal PAL objects allocated at runtime (recall that
+     * LibOS does not keep track of PAL memory, so without this hack it could overwrite internal
+     * PAL memory). This hack is probabilistic and brittle. */
+    *end = SATURATED_P_SUB(*end, 2 * 1024 * g_page_size, *start);  /* 8MB reserved for PAL stuff */
+    if (*end <= *start) {
+        SGX_DBG(DBG_E, "Not enough enclave memory, please increase enclave size!\n");
+        ocall_exit(1, /*is_exitgroup=*/true);
+    }
+
     *hole_start = SATURATED_P_SUB(pal_sec.exec_addr, MEMORY_GAP, *start);
-    *hole_end = SATURATED_P_ADD(pal_sec.exec_addr + pal_sec.exec_size, MEMORY_GAP, *end);
+    *hole_end   = SATURATED_P_ADD(pal_sec.exec_addr + pal_sec.exec_size, MEMORY_GAP, *end);
 }
 
 PAL_NUM _DkGetProcessId (void)