From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 89009427E0; Mon, 20 Mar 2023 10:29:25 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 92D4342D4E; Mon, 20 Mar 2023 10:28:22 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 5B05A4282D for ; Mon, 20 Mar 2023 10:28:06 +0100 (CET) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pg8Wr1SV0zrVNM; Mon, 20 Mar 2023 17:27:04 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 17:28:03 +0800 From: Chengwen Feng To: , , Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao , Jerin Jacob , Satheesh Paul CC: Subject: [PATCH v2 09/44] net/cnxk: fix segment fault when parse devargs Date: Mon, 20 Mar 2023 09:20:35 +0000 Message-ID: <20230320092110.37295-10-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230320092110.37295-1-fengchengwen@huawei.com> References: <20230314124813.39521-1-fengchengwen@huawei.com> <20230320092110.37295-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- drivers/net/cnxk/cnxk_ethdev_devargs.c | 39 ++++++++++++++++++++++++++ drivers/net/cnxk/cnxk_ethdev_sec.c | 12 ++++++++ 2 files changed, 51 insertions(+) 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); -- 2.17.1