From patchwork Tue Nov 6 21:48:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 47908 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A3DF74C92; Tue, 6 Nov 2018 22:49:11 +0100 (CET) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 1F6DB2D13 for ; Tue, 6 Nov 2018 22:49:07 +0100 (CET) Received: by mail-pg1-f194.google.com with SMTP id w7so6383635pgp.13 for ; Tue, 06 Nov 2018 13:49:07 -0800 (PST) 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:in-reply-to:references; bh=iUaPNukdms8MJ8IZhKPNuUVYkfIXvL7pCCVfg+uj/A8=; b=uTx/Q5Kd2PANiMnnwIkDz5MXc5DEwxH5MVluY8tyiaripDHKynGRR0crsEpGYuSKPK gAQKK/8PhRrTe6cBVZCUZBmo6EYgRuwnJqjImzgBNFQhuNvkv6QS26z120wNNr6bEP7t 6fYJQkeaVOtR5R6Ol+PfQPmwCXhRa2UUYLwfArIkEfRfrdwTFjr6QJTvmAqe1BXmRMIF ttFN7CVCojJP9A3Zw4Kzo6IoPyF95l9D3bs3coNvVIYGDkqGgW0tYhbppUVQGnhD6pvN /eLe+6RgXAeqbvCt1WMKIp7OZjZOZsmuDWG2RL7F45o7r20eMfQsK28pbZtXMH93825G zBEA== 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:in-reply-to :references; bh=iUaPNukdms8MJ8IZhKPNuUVYkfIXvL7pCCVfg+uj/A8=; b=c1srLrwYTPqInqoYcC1xR8IFJuqs8J9kq1ONbrjRIs4giDVMfS28WQG+wNSOc5aTrK V7LKC9IJfgRHEmInpHqoR60oYhdUrKy6iYq8vEWtREUIpFnxHDc1TZA/sZIbYNGGQNvt Tl6Xb6XZ4jfW9B3XIqoRjdcxOlAOu8SdNgccADVPEBTAZhJdLSS7fRWOPrr7YnMxwlN5 oIoaQjr4i8cbgIGXAQooaenh7foF5FlF8Mo7qqCL9B5o/nPnHT+7MbMy9Se4EyD2XAl6 R9Wvg1HvQOAlHbBPhn07OICgSXYOBVtSDv+nXFb9VnFV6r3CpIkTcrZwpAyc+ZDGt3qE pZIg== X-Gm-Message-State: AGRZ1gI7hP2MeDI2yhpngQifs63v81QlnH79Uypok4zVP2xmVsWjCqJF QLqxnQ7QY+/7ZHDgTCxPqkFjeVsJPpM= X-Google-Smtp-Source: AJdET5dEL2Ok7QfkGL6uU5RAa6Ywg4oI41hDKzB5FgGLN8eU6XRpy9Eb/xnbSNwze696caN+wl2enA== X-Received: by 2002:a63:3c44:: with SMTP id i4mr25024510pgn.286.1541540945701; Tue, 06 Nov 2018 13:49:05 -0800 (PST) Received: from localhost.localdomain ([167.220.103.1]) by smtp.gmail.com with ESMTPSA id y1sm5653608pfi.123.2018.11.06.13.49.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 13:49:05 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 6 Nov 2018 13:48:58 -0800 Message-Id: <20181106214901.1392-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181106214901.1392-1-stephen@networkplumber.org> References: <20181106214901.1392-1-stephen@networkplumber.org> Subject: [dpdk-dev] [RFC 2/5] 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" 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 --- 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 112ac51dddcc..8521fe63b0ae 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -306,12 +306,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); } }