summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2019-04-02 11:51:05 -0700
committerThomas Monjalon <thomas@monjalon.net>2019-06-14 16:33:56 +0900
commitc530aa78e3747cdd273310eeb9c50603da7f9cb6 (patch)
tree64cb66c2a4777db1961538ae289e5c1fa8538c9c
parent07517400c4740397477153910edee38268294031 (diff)
downloaddpdk-c530aa78e3747cdd273310eeb9c50603da7f9cb6.zip
dpdk-c530aa78e3747cdd273310eeb9c50603da7f9cb6.tar.gz
dpdk-c530aa78e3747cdd273310eeb9c50603da7f9cb6.tar.xz
bus/pci: fix TOCTOU for sysfs access
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") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Reviewed-by: David Marchand <david.marchand@redhat.com>
-rw-r--r--drivers/bus/pci/linux/pci_uio.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index 65f4896..f240fe4 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -315,12 +315,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);
}
}