mirror of
https://github.com/clearlinux/graphene.git
synced 2026-09-07 06:14:02 +00:00
[Pal/Linux-SGX] Lazily zero-out the heap instead of proactively on init
Previously, Linux-SGX PAL initialized the whole heap to zero from within the enclave at startup. This led to significant slowdown on large-sized enclaves. This commit removes the old proactive logic and instead zeroes-out the heap lazily, when enclave pages are actually requested. This does not change the security guarantees because the whole heap is anyway RWX on SGX v1, and the attacker may exploit app vulnerabilities (if any) by supplying malicious data within the enclave during runtime.
This commit is contained in:
@@ -207,23 +207,6 @@ void pal_linux_main(char* uptr_args, uint64_t args_size, char* uptr_env, uint64_
|
||||
g_pal_sec.exec_addr = GET_ENCLAVE_TLS(exec_addr);
|
||||
g_pal_sec.exec_size = GET_ENCLAVE_TLS(exec_size);
|
||||
|
||||
/* Zero the heap. We need to take care to not zero the exec area. */
|
||||
|
||||
void* zero1_start = g_pal_sec.heap_min;
|
||||
void* zero1_end = g_pal_sec.heap_max;
|
||||
|
||||
void* zero2_start = g_pal_sec.heap_max;
|
||||
void* zero2_end = g_pal_sec.heap_max;
|
||||
|
||||
if (g_pal_sec.exec_addr != NULL) {
|
||||
zero1_end = MIN(zero1_end, SATURATED_P_SUB(g_pal_sec.exec_addr, MEMORY_GAP, 0));
|
||||
zero2_start = SATURATED_P_ADD(g_pal_sec.exec_addr + g_pal_sec.exec_size, MEMORY_GAP,
|
||||
zero2_end);
|
||||
}
|
||||
|
||||
memset(zero1_start, 0, zero1_end - zero1_start);
|
||||
memset(zero2_start, 0, zero2_end - zero2_start);
|
||||
|
||||
/* relocate PAL itself */
|
||||
g_pal_map.l_addr = elf_machine_load_address();
|
||||
g_pal_map.l_name = ENCLAVE_PAL_FILENAME;
|
||||
|
||||
@@ -163,6 +163,9 @@ static void* __create_vma_and_merge(void* addr, size_t size, bool is_pal_interna
|
||||
vma->top = addr + size;
|
||||
vma->is_pal_internal = is_pal_internal;
|
||||
|
||||
/* initialize the contents of the new VMA to zero */
|
||||
memset(vma->bottom, 0, vma->top - vma->bottom);
|
||||
|
||||
/* how much memory was freed because [addr, addr + size) overlapped with VMAs */
|
||||
size_t freed = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user