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: 3d09a6e26d ("eal: fix threads block on barrier")

Reported-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reported-by: Lei Yao <lei.a.yao@intel.com>
Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Suggested-by: Olivier Matz <olivier.matz@6wind.com>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
This commit is contained in:
Jianfeng Tan 2018-05-02 13:52:14 +00:00 committed by Thomas Monjalon
parent e87923a9be
commit 3a0d465d4c

View File

@ -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(&params->configured);
ret = pthread_barrier_wait(&params->configured);
if (ret == PTHREAD_BARRIER_SERIAL_THREAD) {
pthread_barrier_destroy(&params->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(&params->configured);
free(params);
ret = pthread_barrier_wait(&params->configured);
if (ret == PTHREAD_BARRIER_SERIAL_THREAD) {
pthread_barrier_destroy(&params->configured);
free(params);
}
return 0;
fail:
if (PTHREAD_BARRIER_SERIAL_THREAD ==
pthread_barrier_wait(&params->configured)) {
pthread_barrier_destroy(&params->configured);
free(params);
}
pthread_cancel(*thread);
pthread_join(*thread, NULL);
free(params);
return ret;
}