From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [PATCH v2] bus/pci: fix TOCTOU issue Date: Tue, 2 Apr 2019 11:51:05 -0700 Message-ID: <20190402185105.2852-1-stephen@networkplumber.org> Cc: dev@dpdk.org, Stephen Hemminger To: ferruh.yigit@intel.com, bruce.richardson@intel.com, gaetan.rivet@6wind.com Return-path: Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by dpdk.org (Postfix) with ESMTP id 7D64058F6 for ; Tue, 2 Apr 2019 20:51:08 +0200 (CEST) Received: by mail-pl1-f193.google.com with SMTP id t16so4833933plo.0 for ; Tue, 02 Apr 2019 11:51:08 -0700 (PDT) List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- v2 - add more CC to original mail, and rebase 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 09ecbb7aad25..0d1b9aa347ba 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -314,12 +314,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); } } -- 2.17.1