[dpdk-dev,3/3] ethdev: prevent segfaults in rte_eth_dev_is_detachable

Message ID 1446108903-14412-4-git-send-email-david.marchand@6wind.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

David Marchand Oct. 29, 2015, 8:55 a.m. UTC
  From: Maxime Leroy <maxime.leroy@6wind.com>

Some drivers like virtual ones don't specify any driver pointer in the
structure rte_eth_dev.

To prevent segfault, we should check if this pointer is NULL before
dereferencing it.

Signed-off-by: Maxime Leroy <maxime.leroy@6wind.com>
Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_ether/rte_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Thomas Monjalon Nov. 3, 2015, 11:10 a.m. UTC | #1
2015-10-29 09:55, David Marchand:
> From: Maxime Leroy <maxime.leroy@6wind.com>
> 
> Some drivers like virtual ones don't specify any driver pointer in the
> structure rte_eth_dev.
> 
> To prevent segfault, we should check if this pointer is NULL before
> dereferencing it.
> 
> Signed-off-by: Maxime Leroy <maxime.leroy@6wind.com>
> Signed-off-by: David Marchand <david.marchand@6wind.com>

It is not clear what the problem is.
And the driver fields should probably be removed or changed as it too tigthly
related to the PCI driver.
  
David Marchand Nov. 3, 2015, 11:19 a.m. UTC | #2
On Tue, Nov 3, 2015 at 12:10 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> 2015-10-29 09:55, David Marchand:
> > From: Maxime Leroy <maxime.leroy@6wind.com>
> >
> > Some drivers like virtual ones don't specify any driver pointer in the
> > structure rte_eth_dev.
> >
> > To prevent segfault, we should check if this pointer is NULL before
> > dereferencing it.
> >
> > Signed-off-by: Maxime Leroy <maxime.leroy@6wind.com>
> > Signed-off-by: David Marchand <david.marchand@6wind.com>
>
> It is not clear what the problem is.
> And the driver fields should probably be removed or changed as it too
> tigthly
> related to the PCI driver.
>

It does look odd to me as well, quickly went through head, and did not see
a case where this could happen.
Maxime is not available at the moment, so I think I will just drop this
patch.

How about this patchset rebased on head with just the first two patches ?
  
Thomas Monjalon Nov. 3, 2015, 11:20 a.m. UTC | #3
2015-11-03 12:19, David Marchand:
> On Tue, Nov 3, 2015 at 12:10 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
> wrote:
> 
> > 2015-10-29 09:55, David Marchand:
> > > From: Maxime Leroy <maxime.leroy@6wind.com>
> > >
> > > Some drivers like virtual ones don't specify any driver pointer in the
> > > structure rte_eth_dev.
> > >
> > > To prevent segfault, we should check if this pointer is NULL before
> > > dereferencing it.
> > >
> > > Signed-off-by: Maxime Leroy <maxime.leroy@6wind.com>
> > > Signed-off-by: David Marchand <david.marchand@6wind.com>
> >
> > It is not clear what the problem is.
> > And the driver fields should probably be removed or changed as it too
> > tigthly
> > related to the PCI driver.
> >
> 
> It does look odd to me as well, quickly went through head, and did not see
> a case where this could happen.
> Maxime is not available at the moment, so I think I will just drop this
> patch.
> 
> How about this patchset rebased on head with just the first two patches ?

Perfect, thanks
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 7fa5717..750e4b5 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -522,6 +522,9 @@  rte_eth_dev_is_detachable(uint8_t port_id)
 		}
 	}
 
+	if (rte_eth_devices[port_id].driver == NULL)
+		return 0;
+
 	drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
 	return drv_flags & RTE_PCI_DRV_DETACHABLE;
 }