[v2,09/44] net/cnxk: fix segment fault when parse devargs

Message ID 20230320092110.37295-10-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: 7eabd6c63773 ("net/cnxk: support inline security setup for cn9k")
Fixes: d25433c7a852 ("net/cnxk: add common devargs parsing")
Fixes: df5cf15faaa9 ("net/cnxk: support IPsec rule reservation scheme")
Fixes: 7eabd6c63773 ("net/cnxk: support inline security setup for cn9k")
Fixes: c91d30f46d4c ("net/cnxk: support configuring channel mask via devargs")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/cnxk/cnxk_ethdev_devargs.c | 39 ++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev_sec.c     | 12 ++++++++
 2 files changed, 51 insertions(+)
  

Patch

diff --git a/drivers/net/cnxk/cnxk_ethdev_devargs.c b/drivers/net/cnxk/cnxk_ethdev_devargs.c
index e1a0845ece..9dde7937f2 100644
--- a/drivers/net/cnxk/cnxk_ethdev_devargs.c
+++ b/drivers/net/cnxk/cnxk_ethdev_devargs.c
@@ -25,6 +25,9 @@  parse_outb_nb_desc(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	val = atoi(value);
 
 	*(uint16_t *)extra_args = val;
@@ -38,6 +41,9 @@  parse_outb_nb_crypto_qs(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	val = atoi(value);
 
 	if (val < 1 || val > 64)
@@ -54,6 +60,9 @@  parse_ipsec_in_spi_range(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	errno = 0;
 	val = strtoul(value, NULL, 0);
 	if (errno)
@@ -70,6 +79,9 @@  parse_ipsec_out_max_sa(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	errno = 0;
 	val = strtoul(value, NULL, 0);
 	if (errno)
@@ -86,6 +98,9 @@  parse_flow_max_priority(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint16_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	val = atoi(value);
 
 	/* Limit the max priority to 32 */
@@ -103,6 +118,9 @@  parse_flow_prealloc_size(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint16_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	val = atoi(value);
 
 	/* Limit the prealloc size to 32 */
@@ -120,6 +138,9 @@  parse_reta_size(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	val = atoi(value);
 
 	if (val <= RTE_ETH_RSS_RETA_SIZE_64)
@@ -144,6 +165,9 @@  parse_pre_l2_hdr_info(const char *key, const char *value, void *extra_args)
 	char *tok1 = NULL, *tok2 = NULL;
 	uint16_t off, off_mask, dir;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	RTE_SET_USED(key);
 	off = strtol(value, &tok1, 16);
 	tok1++;
@@ -164,6 +188,9 @@  parse_flag(const char *key, const char *value, void *extra_args)
 {
 	RTE_SET_USED(key);
 
+	if (value == NULL)
+		return -EINVAL;
+
 	*(uint16_t *)extra_args = atoi(value);
 
 	return 0;
@@ -175,6 +202,9 @@  parse_sqb_count(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	val = atoi(value);
 
 	*(uint16_t *)extra_args = val;
@@ -188,6 +218,9 @@  parse_meta_bufsize(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	errno = 0;
 	val = strtoul(value, NULL, 0);
 	if (errno)
@@ -203,6 +236,9 @@  parse_switch_header_type(const char *key, const char *value, void *extra_args)
 {
 	RTE_SET_USED(key);
 
+	if (value == NULL)
+		return -EINVAL;
+
 	if (strcmp(value, "higig2") == 0)
 		*(uint16_t *)extra_args = ROC_PRIV_FLAGS_HIGIG;
 
@@ -231,6 +267,9 @@  parse_sdp_channel_mask(const char *key, const char *value, void *extra_args)
 	uint16_t chan = 0, mask = 0;
 	char *next = 0;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	/* next will point to the separator '/' */
 	chan = strtol(value, &next, 16);
 	mask = strtol(++next, 0, 16);
diff --git a/drivers/net/cnxk/cnxk_ethdev_sec.c b/drivers/net/cnxk/cnxk_ethdev_sec.c
index aa8a378a00..6d1fc754b8 100644
--- a/drivers/net/cnxk/cnxk_ethdev_sec.c
+++ b/drivers/net/cnxk/cnxk_ethdev_sec.c
@@ -133,6 +133,9 @@  parse_max_ipsec_rules(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	val = atoi(value);
 
 	if (val < 1 || val > 4095)
@@ -248,6 +251,9 @@  parse_val_u32(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	errno = 0;
 	val = strtoul(value, NULL, 0);
 	if (errno)
@@ -264,6 +270,9 @@  parse_selftest(const char *key, const char *value, void *extra_args)
 	RTE_SET_USED(key);
 	uint32_t val;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	val = atoi(value);
 
 	*(uint8_t *)extra_args = !!(val == 1);
@@ -277,6 +286,9 @@  parse_inl_cpt_channel(const char *key, const char *value, void *extra_args)
 	uint16_t chan = 0, mask = 0;
 	char *next = 0;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	/* next will point to the separator '/' */
 	chan = strtol(value, &next, 16);
 	mask = strtol(++next, 0, 16);