From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B9351A0530; Wed, 12 Feb 2020 06:22:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 58DBB262E; Wed, 12 Feb 2020 06:22:05 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 228452629; Wed, 12 Feb 2020 06:22:02 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2020 21:22:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,428,1574150400"; d="scan'208";a="433927716" Received: from storage36.sh.intel.com ([10.67.110.177]) by fmsmga006.fm.intel.com with ESMTP; 11 Feb 2020 21:22:01 -0800 From: Jin Yu To: dev@dpdk.org, Maxime Coquelin , Tiwei Bie , Zhihong Wang Cc: Jin Yu , stable@dpdk.org Date: Wed, 12 Feb 2020 20:54:46 +0800 Message-Id: <20200212125446.7949-1-jin.yu@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200211093336.32792-1-jin.yu@intel.com> References: <20200211093336.32792-1-jin.yu@intel.com> Subject: [dpdk-dev] [PATCH v2] examples/vhost_blk: fix the TOCTOU 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Fix the time of check time of use warning in example code. Ignore the errno of unlink failure. There are two situations. The first one is that file doesn't exist the unlink fails and it's ok to ignore. The second one is that unlink fails to remove file but the next bind() would fail too. Coverity issue: 350589 158663 Fixes: c19beb3f38cd ("examples/vhost_blk: introduce vhost storage sample") Cc: stable@dpdk.org Signed-off-by: Jin Yu Reviewed-by: Maxime Coquelin --- V2 - complement the commit message. --- examples/vhost_blk/vhost_blk.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c index e1036bf3a..74c82a900 100644 --- a/examples/vhost_blk/vhost_blk.c +++ b/examples/vhost_blk/vhost_blk.c @@ -994,11 +994,7 @@ vhost_blk_ctrlr_construct(const char *ctrlr_name) } snprintf(dev_pathname, sizeof(dev_pathname), "%s/%s", path, ctrlr_name); - if (access(dev_pathname, F_OK) != -1) { - if (unlink(dev_pathname) != 0) - rte_exit(EXIT_FAILURE, "Cannot remove %s.\n", - dev_pathname); - } + unlink(dev_pathname); if (rte_vhost_driver_register(dev_pathname, 0) != 0) { fprintf(stderr, "socket %s already exists\n", dev_pathname); @@ -1041,8 +1037,7 @@ signal_handler(__rte_unused int signum) { struct vhost_blk_ctrlr *ctrlr; - if (access(dev_pathname, F_OK) == 0) - unlink(dev_pathname); + unlink(dev_pathname); if (g_should_stop != -1) { g_should_stop = 1; -- 2.17.2