[v2,13/44] net/enic: fix segment fault when parse devargs

Message ID 20230320092110.37295-14-fengchengwen@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series fix segment fault when parse args |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen March 20, 2023, 9:20 a.m. UTC
  The rte_kvargs_process() was used to parse KV pairs, it also supports
to parse 'only keys' (e.g. socket_id) type. And the callback function
parameter 'value' is NULL when parsed 'only keys'.

This patch fixes segment fault when parse input args with 'only keys'.

Fixes: 93fb21fdbe23 ("net/enic: enable overlay offload for VXLAN and GENEVE")
Fixes: e39c2756e21a ("net/enic: add devarg to specify ingress VLAN rewrite mode")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/enic/enic_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

John Daley (johndale) March 20, 2023, 9:37 p.m. UTC | #1
Reviewed-by: John Daley johndale@cisco.com<mailto:johndale@cisco.com>

From: Chengwen Feng <fengchengwen@huawei.com>
Date: Monday, March 20, 2023 at 2:28 AM
To: thomas@monjalon.net <thomas@monjalon.net>, ferruh.yigit@amd.com <ferruh.yigit@amd.com>, John Daley (johndale) <johndale@cisco.com>, Hyong Youb Kim (hyonkim) <hyonkim@cisco.com>
Cc: dev@dpdk.org <dev@dpdk.org>
Subject: [PATCH v2 13/44] net/enic: fix segment fault when parse devargs
The rte_kvargs_process() was used to parse KV pairs, it also supports
to parse 'only keys' (e.g. socket_id) type. And the callback function
parameter 'value' is NULL when parsed 'only keys'.

This patch fixes segment fault when parse input args with 'only keys'.

Fixes: 93fb21fdbe23 ("net/enic: enable overlay offload for VXLAN and GENEVE")
Fixes: e39c2756e21a ("net/enic: add devarg to specify ingress VLAN rewrite mode")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/enic/enic_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
index cdf0915591..b67016e0a3 100644
--- a/drivers/net/enic/enic_ethdev.c
+++ b/drivers/net/enic/enic_ethdev.c
@@ -1148,6 +1148,9 @@ static int enic_parse_zero_one(const char *key,
         struct enic *enic;
         bool b;

+       if (value == NULL)
+               return -EINVAL;
+
         enic = (struct enic *)opaque;
         if (strcmp(value, "0") == 0) {
                 b = false;
@@ -1173,6 +1176,9 @@ static int enic_parse_ig_vlan_rewrite(__rte_unused const char *key,
 {
         struct enic *enic;

+       if (value == NULL)
+               return -EINVAL;
+
         enic = (struct enic *)opaque;
         if (strcmp(value, "trunk") == 0) {
                 /* Trunk mode: always tag */
--
2.17.1
  

Patch

diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
index cdf0915591..b67016e0a3 100644
--- a/drivers/net/enic/enic_ethdev.c
+++ b/drivers/net/enic/enic_ethdev.c
@@ -1148,6 +1148,9 @@  static int enic_parse_zero_one(const char *key,
 	struct enic *enic;
 	bool b;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	enic = (struct enic *)opaque;
 	if (strcmp(value, "0") == 0) {
 		b = false;
@@ -1173,6 +1176,9 @@  static int enic_parse_ig_vlan_rewrite(__rte_unused const char *key,
 {
 	struct enic *enic;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	enic = (struct enic *)opaque;
 	if (strcmp(value, "trunk") == 0) {
 		/* Trunk mode: always tag */