From mboxrd@z Thu Jan 1 00:00:00 1970 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=Ac+aelww2W5EKOaZkzyx38NMc6+4PEQWVCiPVT/YOu8=; b=Srm1FcDnkJUYN6Q0kzn81qvTejjEGVUHIhqn4oxVPXsrx/Z4AUfrcGjF/K6VLBYpZ0 cGcJnpoO1rsIwHHFEVufPMQys2ADVndI9t17bij3y7CcKcG6y5lRxVpXASGfo4YWzqlN ONHycEBhpFD/CpT8VdsbhmwiO06pvxY0aVYdi4UGX4dNp83pQsYWEgmFTalz/RHfuj96 zftjer85TwkcB4bF4/0KNp5P12ZZl23MgmiZs4IfInTGgdnu58HthG+WchwU/5OFMB0D 97zeIqnTVc4bpkzz+IK4ynjFf/dwNppVvBRdCXfVIQ0WTDioxUyG10DjV3m9E2lsn1sS zqPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Ac+aelww2W5EKOaZkzyx38NMc6+4PEQWVCiPVT/YOu8=; b=OMkM6cP15UJ4+Z1eTgwHkPgo52kL32J3h79ZtjeDqi7T3VYLsw/mdbzwFQlKiBeCZn mtPvBhZ233NcEXyd++4iBLIFe60ETp60+oYdrUNx9/ZN9SHQyVMVifORM5H8KPGAXXPg qtq09Jm1+anDDZR7OQPE1eNwys4qrAzwRfCzRNvK75RgTco8n+8cmdxHc2xLEAPezEJk e7p/HnuWcKQYu7BCfeWul6qXLqriko5wLwJeHgGpsbb/7dlXUhMnl+fcC5cDC1QHeNt/ d3zVfbN26SYqnj58kZqovQfw4kkUA/WA9OzD/glhl5PoYEqvReii1AFnZRDgbmxnGIPX HarQ== X-Gm-Message-State: APjAAAW0tNGlFqFlc26lOG8B/35cZfDw5AHrtK6r663azJnLxl1zc457 VDOxBnDa/CmygVrNvcB+mJDswQ== X-Google-Smtp-Source: APXvYqzhleJlzbjxo6pFJGpLIa/m7JAQypj9xIVWS286UpCM3RAdEuBCNONa7CyALy1WZo9dWTQKRA== X-Received: by 2002:a17:902:e109:: with SMTP id cc9mr19442787plb.148.1554231067602; Tue, 02 Apr 2019 11:51:07 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id o89sm27124731pfi.178.2019.04.02.11.51.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 11:51:06 -0700 (PDT) From: Stephen Hemminger To: ferruh.yigit@intel.com, bruce.richardson@intel.com, gaetan.rivet@6wind.com Cc: dev@dpdk.org, Stephen Hemminger Date: Tue, 2 Apr 2019 11:51:05 -0700 Message-Id: <20190402185105.2852-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v2] bus/pci: fix TOCTOU issue 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: , X-List-Received-Date: Tue, 02 Apr 2019 18:51:08 -0000 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 7F0F7A0679 for ; Tue, 2 Apr 2019 20:51:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3CD135F28; Tue, 2 Apr 2019 20:51:09 +0200 (CEST) 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=Ac+aelww2W5EKOaZkzyx38NMc6+4PEQWVCiPVT/YOu8=; b=Srm1FcDnkJUYN6Q0kzn81qvTejjEGVUHIhqn4oxVPXsrx/Z4AUfrcGjF/K6VLBYpZ0 cGcJnpoO1rsIwHHFEVufPMQys2ADVndI9t17bij3y7CcKcG6y5lRxVpXASGfo4YWzqlN ONHycEBhpFD/CpT8VdsbhmwiO06pvxY0aVYdi4UGX4dNp83pQsYWEgmFTalz/RHfuj96 zftjer85TwkcB4bF4/0KNp5P12ZZl23MgmiZs4IfInTGgdnu58HthG+WchwU/5OFMB0D 97zeIqnTVc4bpkzz+IK4ynjFf/dwNppVvBRdCXfVIQ0WTDioxUyG10DjV3m9E2lsn1sS zqPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Ac+aelww2W5EKOaZkzyx38NMc6+4PEQWVCiPVT/YOu8=; b=OMkM6cP15UJ4+Z1eTgwHkPgo52kL32J3h79ZtjeDqi7T3VYLsw/mdbzwFQlKiBeCZn mtPvBhZ233NcEXyd++4iBLIFe60ETp60+oYdrUNx9/ZN9SHQyVMVifORM5H8KPGAXXPg qtq09Jm1+anDDZR7OQPE1eNwys4qrAzwRfCzRNvK75RgTco8n+8cmdxHc2xLEAPezEJk e7p/HnuWcKQYu7BCfeWul6qXLqriko5wLwJeHgGpsbb/7dlXUhMnl+fcC5cDC1QHeNt/ d3zVfbN26SYqnj58kZqovQfw4kkUA/WA9OzD/glhl5PoYEqvReii1AFnZRDgbmxnGIPX HarQ== X-Gm-Message-State: APjAAAW0tNGlFqFlc26lOG8B/35cZfDw5AHrtK6r663azJnLxl1zc457 VDOxBnDa/CmygVrNvcB+mJDswQ== X-Google-Smtp-Source: APXvYqzhleJlzbjxo6pFJGpLIa/m7JAQypj9xIVWS286UpCM3RAdEuBCNONa7CyALy1WZo9dWTQKRA== X-Received: by 2002:a17:902:e109:: with SMTP id cc9mr19442787plb.148.1554231067602; Tue, 02 Apr 2019 11:51:07 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id o89sm27124731pfi.178.2019.04.02.11.51.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 11:51:06 -0700 (PDT) From: Stephen Hemminger To: ferruh.yigit@intel.com, bruce.richardson@intel.com, gaetan.rivet@6wind.com Cc: dev@dpdk.org, Stephen Hemminger Date: Tue, 2 Apr 2019 11:51:05 -0700 Message-Id: <20190402185105.2852-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v2] bus/pci: fix TOCTOU issue 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" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190402185105.P5kcdGYGucgDJsCVFBjhMbXDaWFwXc-WEfMleJOxsbg@z> 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