Skip to content

Commit

Permalink
bus/pci: fix TOCTOU for sysfs access
Browse files Browse the repository at this point in the history
[ upstream commit c530aa7 ]

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: 4a928ef ("bus/pci: enable write combining during mapping")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: David Marchand <david.marchand@redhat.com>
  • Loading branch information
shemminger authored and kevintraynor committed Jun 24, 2019
1 parent 6d58d68 commit 8f54619
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions drivers/bus/pci/linux/pci_uio.c
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 8f54619

Please sign in to comment.