DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: anatoly.burakov@intel.com, olivier.matz@6wind.com,
	thomas@monjalon.net, Jianfeng Tan <jianfeng.tan@intel.com>
Subject: [dpdk-dev] [PATCH v3] eal: fix use-after-free issue on thread creation
Date: Wed,  2 May 2018 13:52:14 +0000	[thread overview]
Message-ID: <1525269134-103270-1-git-send-email-jianfeng.tan@intel.com> (raw)
In-Reply-To: <1525255198-20906-1-git-send-email-jianfeng.tan@intel.com>

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 <maxime.coquelin@redhat.com>
Reported-by: Lei Yao <lei.a.yao@intel.com>
Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
Suggested-by: Olivier Matz <olivier.matz@6wind.com>
---
 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(&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);
 }
@@ -204,14 +209,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;
 }
-- 
2.7.4

  parent reply	other threads:[~2018-05-02 13:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02  9:59 [dpdk-dev] [PATCH] " Jianfeng Tan
2018-05-02 10:17 ` [dpdk-dev] [PATCH v2] " Jianfeng Tan
2018-05-02 11:24   ` Olivier Matz
2018-05-02 13:54     ` Tan, Jianfeng
2018-05-02 13:52 ` Jianfeng Tan [this message]
2018-05-02 14:56   ` [dpdk-dev] [PATCH v3] " Olivier Matz
2018-05-02 15:26     ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1525269134-103270-1-git-send-email-jianfeng.tan@intel.com \
    --to=jianfeng.tan@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=olivier.matz@6wind.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).