From 6f986855e9ac5045b2d2a9b1c1936fdf643671f8 Mon Sep 17 00:00:00 2001 From: LI Qing Date: Thu, 20 Feb 2020 08:26:02 +0000 Subject: [PATCH] Fix the issue that process resource cannot be freed in some cases If untrusted app calls "occlum_pal_exec" sequentially or concurrently, Occlum cannot free the resource of the enclave process correctly. --- src/libos/src/process/task.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libos/src/process/task.rs b/src/libos/src/process/task.rs index f6b3379a..ac6ffb04 100644 --- a/src/libos/src/process/task.rs +++ b/src/libos/src/process/task.rs @@ -101,14 +101,15 @@ pub fn run_task(libos_tid: pid_t, host_tid: pid_t) -> Result { do_run_task(task); } - let exit_status = { + let (exit_status, parent_pid) = { let mut process = new_process.lock().unwrap(); - process.get_exit_status() + let parent = process.get_parent().lock().unwrap(); + (process.get_exit_status(), parent.get_tid()) }; - // Init process does not have any parent, so it has to release itself - if pid == 1 { - process_table::remove(1); + // If process's parent is the IDLE_PROCESS (pid = 0), so it has to release itself + if parent_pid == 0 { + process_table::remove(pid); } reset_current();