From 9ea009ab6fb7fe9983da93fea30a653ce5fb2f1a Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 31 Jan 2019 18:31:06 -0800 Subject: [PATCH] [LibOS] clone shouldn't expose child thread until its init The final initialization of child thread of clone is done by clone_implementation_wrapper(). Until the initialization completes, child shim_thread shouldn't be exposed to other thread. Otherwise other thread can access uninitialized shim_thread. For example, other thread tries to send signal to that thread by walking thread_list and access uninitialized member of shim_thread. Defer add_thread() until initialization is complete. Signed-off-by: Isaku Yamahata --- LibOS/shim/src/sys/shim_clone.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/LibOS/shim/src/sys/shim_clone.c b/LibOS/shim/src/sys/shim_clone.c index 79c9f408..d659a608 100644 --- a/LibOS/shim/src/sys/shim_clone.c +++ b/LibOS/shim/src/sys/shim_clone.c @@ -129,6 +129,10 @@ int clone_implementation_wrapper(struct clone_args * arg) my_thread->stack_top = vma.addr + vma.length; my_thread->stack_red = my_thread->stack = vma.addr; + /* until now we're not ready to be exposed to other thread */ + add_thread(my_thread); + set_as_child(arg->parent, my_thread); + /* Don't signal the initialize event until we are actually init-ed */ DkEventSet(pcargs->initialize_event); @@ -324,8 +328,6 @@ int shim_do_clone (int flags, void * user_stack_addr, int * parent_tidptr, thread->pal_handle = pal_handle; thread->in_vm = thread->is_alive = true; - add_thread(thread); - set_as_child(self, thread); if (set_parent_tid) *set_parent_tid = tid;