From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [RFC 2/5] bus/pci: fix TOCTOU issue Date: Sun, 18 Nov 2018 16:04:38 +0100 Message-ID: <45370656.e11tQEUeGQ@xps> References: <20181106214901.1392-1-stephen@networkplumber.org> <20181106214901.1392-3-stephen@networkplumber.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit Cc: dev@dpdk.org, ferruh.yigit@intel.com To: Stephen Hemminger Return-path: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id 428AB322C for ; Sun, 18 Nov 2018 16:04:41 +0100 (CET) In-Reply-To: <20181106214901.1392-3-stephen@networkplumber.org> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" +Cc Ferruh 06/11/2018 22:48, Stephen Hemminger: > Using access followed by open causes a static analysis warning > about Time of check versus Time of use. Also, access() and > open() have different UID permission checks. > > This is not a serious problem; but easy to fix by using errno instead. > > Coverity issue: 300870 > Fixes: 4a928ef9f611 ("bus/pci: enable write combining during mapping") > Signed-off-by: Stephen Hemminger > --- > drivers/bus/pci/linux/pci_uio.c | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c > index 112ac51dddcc..8521fe63b0ae 100644 > --- a/drivers/bus/pci/linux/pci_uio.c > +++ b/drivers/bus/pci/linux/pci_uio.c > @@ -306,12 +306,11 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, > loc->domain, loc->bus, loc->devid, > loc->function, res_idx); > > - if (access(devname, R_OK|W_OK) != -1) { > - fd = open(devname, O_RDWR); > - if (fd < 0) > - RTE_LOG(INFO, EAL, "%s cannot be mapped. " > - "Fall-back to non prefetchable mode.\n", > - devname); > + fd = open(devname, O_RDWR); > + if (fd < 0 && errno != ENOENT) { > + RTE_LOG(INFO, EAL, "%s cannot be mapped. " > + "Fall-back to non prefetchable mode.\n", > + devname); > } > }