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 43E6EA04DE; Wed, 27 Nov 2019 03:36:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 150241BDAC; Wed, 27 Nov 2019 03:36:08 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id BA141CF3; Wed, 27 Nov 2019 03:36:05 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Nov 2019 18:36:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,247,1571727600"; d="scan'208";a="202921113" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga008.jf.intel.com with ESMTP; 26 Nov 2019 18:36:04 -0800 Received: from shsmsx108.ccr.corp.intel.com (10.239.4.97) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 26 Nov 2019 18:36:03 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.213]) by SHSMSX108.ccr.corp.intel.com ([169.254.8.41]) with mapi id 14.03.0439.000; Wed, 27 Nov 2019 10:36:02 +0800 From: "Yu, Jin" To: "Richardson, Bruce" CC: Maxime Coquelin , "Bie, Tiwei" , "Wang, Zhihong" , "dev@dpdk.org" , "stable@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] examples/vhost_blk: fix the TOCTOU Thread-Index: AQHVpC4i/q0+R3dYoka3sUEIYCDxdKecuUyAgAGQsVA= Date: Wed, 27 Nov 2019 02:36:01 +0000 Message-ID: References: <20191126153214.7952-1-jin.yu@intel.com> <20191126102555.GA1629@bricha3-MOBL.ger.corp.intel.com> In-Reply-To: <20191126102555.GA1629@bricha3-MOBL.ger.corp.intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOGUxNGNmODItMWI4Yi00OGViLTk1NDgtODZlM2M4NDMyMTllIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoid2tSN3h1SmVyNXArOExDanhFeTVQTzlTODhJbFBSUTVsYlFRQ2RNUnNWS0t6MExQaU5lTlRPR2lGbVpMYVNWRiJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] 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" > -----Original Message----- > From: Bruce Richardson > Sent: Tuesday, November 26, 2019 6:26 PM > To: Yu, Jin > Cc: Maxime Coquelin ; Bie, Tiwei > ; Wang, Zhihong ; > dev@dpdk.org; stable@dpdk.org > Subject: Re: [dpdk-dev] [PATCH] examples/vhost_blk: fix the TOCTOU >=20 > On Tue, Nov 26, 2019 at 11:32:14PM +0800, Jin Yu wrote: > > Fix the time of check time of use warning in example code > > > > Coverity issue: 350589 158663 > > Fixes: c19beb3f38cd ("examples/vhost_blk: introduce vhost storage > > sample") > > Cc: stable@dpdk.org > > > > Signed-off-by: Jin Yu > > --- > > 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) !=3D -1) { > > - if (unlink(dev_pathname) !=3D 0) > > - rte_exit(EXIT_FAILURE, "Cannot remove %s.\n", > > - dev_pathname); > > - } > > + unlink(dev_pathname); > > >=20 > The original code did an exit if the delete failed, do you intend there t= o be a > behaviour change here? You can probably get the same behaviour if you > check the errno on an unlink failure, e.g. ENOENT means file doesn't exis= t. >=20 > If not having the app exit on unlink failure is reasonable behaviour then > ignore this comment. I considered it. I think it's ok to ignore the errno of unlink failure. Thi= s code just want to remove the file. There are two situations. The first one is that file do= esn'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()=20 would fail too so I think it's ok to ignore too. >=20 > Regards, > /Bruce