Skip to content

Commit c530aa7

Browse files
shemmingertmonjalo
authored andcommitted
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: 4a928ef ("bus/pci: enable write combining during mapping") Cc: [email protected] Signed-off-by: Stephen Hemminger <[email protected]> Reviewed-by: David Marchand <[email protected]>
1 parent 0751740 commit c530aa7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/bus/pci/linux/pci_uio.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,11 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
315315
loc->domain, loc->bus, loc->devid,
316316
loc->function, res_idx);
317317

318-
if (access(devname, R_OK|W_OK) != -1) {
319-
fd = open(devname, O_RDWR);
320-
if (fd < 0)
321-
RTE_LOG(INFO, EAL, "%s cannot be mapped. "
322-
"Fall-back to non prefetchable mode.\n",
323-
devname);
318+
fd = open(devname, O_RDWR);
319+
if (fd < 0 && errno != ENOENT) {
320+
RTE_LOG(INFO, EAL, "%s cannot be mapped. "
321+
"Fall-back to non prefetchable mode.\n",
322+
devname);
324323
}
325324
}
326325

0 commit comments

Comments
 (0)