[dpdk-dev] drivers/net/pcap: fix segfault in pcap pmd

Message ID 1464269389-24687-1-git-send-email-reshma.pattan@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Pattan, Reshma May 26, 2016, 1:29 p.m. UTC
  Testpmd application will crash in fclose() upon quit after running
the below command.

"sudo gdb --args ./x86_64-native-linuxapp-gcc/app/testpmd -c 0xf0 -n 4 --vdev
'eth_pcap0,tx_iface=enp1s0f1,rx_pcap=/tmp/test.pcap' -- --port-topology=chained -i"

The reason is, pcap vdev creation with tx stream type as "iface" as in above
command dont need member ''dumpers'' of "struct tx_pcaps", hence will not have
memory allocated. But contains a garbage values, as local object of struct tx_pcaps
is not initialized to 0 inside rte_pmd_pcap_dev_init(). So calling pcap_dump_close() on
dumper as part of eth_dev_stop() is causing segfault in fclose().

Fix is to initilize local object of struct tx_pcaps to 0.
Also initiliaze local object of stcruct rx_pcaps to 0.

So during eth_dev_stop(), pcap_dump_close() will not be called if dumper is NULL.

Fixes:4c173302("pcap: add new driver")

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 drivers/net/pcap/rte_eth_pcap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Pattan, Reshma May 26, 2016, 1:32 p.m. UTC | #1
Self-Nacking.. wrong patch

> -----Original Message-----
> From: Pattan, Reshma
> Sent: Thursday, May 26, 2016 2:30 PM
> To: dev@dpdk.org
> Cc: Pattan, Reshma <reshma.pattan@intel.com>
> Subject: [PATCH] drivers/net/pcap: fix segfault in pcap pmd
> 
> Testpmd application will crash in fclose() upon quit after running the below
> command.
> 
> "sudo gdb --args ./x86_64-native-linuxapp-gcc/app/testpmd -c 0xf0 -n 4 --vdev
> 'eth_pcap0,tx_iface=enp1s0f1,rx_pcap=/tmp/test.pcap' -- --port-
> topology=chained -i"
> 
> The reason is, pcap vdev creation with tx stream type as "iface" as in above
> command dont need member ''dumpers'' of "struct tx_pcaps", hence will not
> have memory allocated. But contains a garbage values, as local object of struct
> tx_pcaps is not initialized to 0 inside rte_pmd_pcap_dev_init(). So calling
> pcap_dump_close() on dumper as part of eth_dev_stop() is causing segfault in
> fclose().
> 
> Fix is to initilize local object of struct tx_pcaps to 0.
> Also initiliaze local object of stcruct rx_pcaps to 0.
> 
> So during eth_dev_stop(), pcap_dump_close() will not be called if dumper is
> NULL.
> 
> Fixes:4c173302("pcap: add new driver")
> 
> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
> ---
>  drivers/net/pcap/rte_eth_pcap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
> index c98e234..e0bb500 100644
> --- a/drivers/net/pcap/rte_eth_pcap.c
> +++ b/drivers/net/pcap/rte_eth_pcap.c
> @@ -978,8 +978,8 @@ rte_pmd_pcap_devinit(const char *name, const char
> *params)
>  	unsigned numa_node, using_dumpers = 0;
>  	int ret;
>  	struct rte_kvargs *kvlist;
> -	struct rx_pcaps pcaps;
> -	struct tx_pcaps dumpers;
> +	struct rx_pcaps pcaps={0};
> +	struct tx_pcaps dumpers={0};
> 
>  	RTE_LOG(INFO, PMD, "Initializing pmd_pcap for %s\n", name);
> 
> --
> 2.5.0
  

Patch

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index c98e234..e0bb500 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -978,8 +978,8 @@  rte_pmd_pcap_devinit(const char *name, const char *params)
 	unsigned numa_node, using_dumpers = 0;
 	int ret;
 	struct rte_kvargs *kvlist;
-	struct rx_pcaps pcaps;
-	struct tx_pcaps dumpers;
+	struct rx_pcaps pcaps={0};
+	struct tx_pcaps dumpers={0};
 
 	RTE_LOG(INFO, PMD, "Initializing pmd_pcap for %s\n", name);