DPDK-dev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] bus/pci: fix TOCTOU issue
@ 2019-04-02 18:51 Stephen Hemminger
  2019-06-14  7:16 ` [dpdk-dev] " David Marchand
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2019-04-02 18:51 UTC (permalink / raw)
  To: ferruh.yigit, bruce.richardson, gaetan.rivet; +Cc: dev, Stephen Hemminger

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 <stephen@networkplumber.org>
---
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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH v2] bus/pci: fix TOCTOU issue
  2019-04-02 18:51 [PATCH v2] bus/pci: fix TOCTOU issue Stephen Hemminger
@ 2019-06-14  7:16 ` " David Marchand
  2019-06-14  7:35   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: David Marchand @ 2019-06-14  7:16 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Yigit, Ferruh, Bruce Richardson, Gaetan Rivet, dev

On Tue, Apr 2, 2019 at 8:51 PM Stephen Hemminger <stephen@networkplumber.org>
wrote:

> 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 <stephen@networkplumber.org>
> ---
> 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);
>                 }
>         }
>
>
Reviewed-by: David Marchand <david.marchand@redhat.com>

-- 
David Marchand

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH v2] bus/pci: fix TOCTOU issue
  2019-06-14  7:16 ` [dpdk-dev] " David Marchand
@ 2019-06-14  7:35   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2019-06-14  7:35 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: dev, David Marchand, Yigit, Ferruh, Bruce Richardson, Gaetan Rivet

14/06/2019 16:16, David Marchand:
> On Tue, Apr 2, 2019 at 8:51 PM Stephen Hemminger <stephen@networkplumber.org>
> wrote:
> 
> > 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>

Applied, thanks




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-02 18:51 [PATCH v2] bus/pci: fix TOCTOU issue Stephen Hemminger
2019-06-14  7:16 ` [dpdk-dev] " David Marchand
2019-06-14  7:35   ` Thomas Monjalon

DPDK-dev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dpdk-dev/0 dpdk-dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dpdk-dev dpdk-dev/ https://lore.kernel.org/dpdk-dev \
		dev@dpdk.org dpdk-dev@archiver.kernel.org
	public-inbox-index dpdk-dev


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox