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 23EF2A052F for ; Tue, 11 Feb 2020 03:00:55 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E7B421BF9A; Tue, 11 Feb 2020 03:00:54 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 4D23B1BE9C; Tue, 11 Feb 2020 03:00:51 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Feb 2020 18:00:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,427,1574150400"; d="scan'208";a="221770382" Received: from storage36.sh.intel.com ([10.67.110.177]) by orsmga007.jf.intel.com with ESMTP; 10 Feb 2020 18:00:48 -0800 From: Jin Yu To: dev@dpdk.org, Maxime Coquelin , Tiwei Bie , Zhihong Wang Cc: Jin Yu , stable@dpdk.org Date: Tue, 11 Feb 2020 17:33:36 +0800 Message-Id: <20200211093336.32792-1-jin.yu@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20191126153214.7952-1-jin.yu@intel.com> References: <20191126153214.7952-1-jin.yu@intel.com> Subject: [dpdk-stable] [PATCH v2] examples/vhost_blk: fix the TOCTOU X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" 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 3182a488b..bcb4ebb0b 100644 --- a/examples/vhost_blk/vhost_blk.c +++ b/examples/vhost_blk/vhost_blk.c @@ -993,11 +993,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); @@ -1040,8 +1036,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