From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id C5273DD2 for ; Wed, 2 May 2018 15:50:03 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 May 2018 06:50:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,354,1520924400"; d="scan'208";a="36275625" Received: from dpdk06.sh.intel.com ([10.67.110.196]) by fmsmga007.fm.intel.com with ESMTP; 02 May 2018 06:50:01 -0700 From: Jianfeng Tan To: dev@dpdk.org Cc: anatoly.burakov@intel.com, olivier.matz@6wind.com, thomas@monjalon.net, Jianfeng Tan Date: Wed, 2 May 2018 13:52:14 +0000 Message-Id: <1525269134-103270-1-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525255198-20906-1-git-send-email-jianfeng.tan@intel.com> References: <1525255198-20906-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v3] eal: fix use-after-free issue on thread creation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 May 2018 13:50:04 -0000 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 Signed-off-by: Jianfeng Tan Suggested-by: Olivier Matz --- v1->v2: - Destroy barrier if failure happens. v2->v3: - Add proper failure handling. lib/librte_eal/common/eal_common_thread.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index de69452..cb0855d 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); } @@ -204,14 +209,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; } -- 2.7.4