From: Jianfeng Tan Date: Wed, 2 May 2018 13:52:14 +0000 (+0000) Subject: eal: fix use-after-free on control thread creation X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=3a0d465d4c53;p=dpdk.git eal: fix use-after-free on control thread creation After below commit, we encounter some strange issue: 1) Dead lock as described here: http://dpdk.org/ml/archives/dev/2018-April/099806.html 2) SIGSEGV issue when starting a testpmd in VM. Considering below commit changes to use dynamic memory instead of stack for memory barrier, we doubt it's caused by use-after-free. Fixes: 3d09a6e26d8b ("eal: fix threads block on barrier") Reported-by: Maxime Coquelin Reported-by: Lei Yao Suggested-by: Stephen Hemminger Suggested-by: Olivier Matz Signed-off-by: Jianfeng Tan Reviewed-by: Olivier Matz --- diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index a2c05e40fa..42398630a1 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -149,11 +149,16 @@ struct rte_thread_ctrl_params { static void *rte_thread_init(void *arg) { + int ret; struct rte_thread_ctrl_params *params = arg; void *(*start_routine)(void *) = params->start_routine; void *routine_arg = params->arg; - pthread_barrier_wait(¶ms->configured); + ret = pthread_barrier_wait(¶ms->configured); + if (ret == PTHREAD_BARRIER_SERIAL_THREAD) { + pthread_barrier_destroy(¶ms->configured); + free(params); + } return start_routine(routine_arg); } @@ -206,14 +211,21 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, if (ret < 0) goto fail; - pthread_barrier_wait(¶ms->configured); - free(params); + ret = pthread_barrier_wait(¶ms->configured); + if (ret == PTHREAD_BARRIER_SERIAL_THREAD) { + pthread_barrier_destroy(¶ms->configured); + free(params); + } return 0; fail: + if (PTHREAD_BARRIER_SERIAL_THREAD == + pthread_barrier_wait(¶ms->configured)) { + pthread_barrier_destroy(¶ms->configured); + free(params); + } pthread_cancel(*thread); pthread_join(*thread, NULL); - free(params); return ret; }